socketref,再见!高德

https://github.com/adoggie

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  246 Posts :: 4 Stories :: 312 Comments :: 0 Trackbacks

常用链接

留言簿(54)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

公司的shp数据都是以秒为单位存储,要做监控和道路匹配,直接与gps接收坐标无法实现,必须转换shp单位为度单位

  1 #--coding:utf-8---
  2 #  brief:  内业shp数据,转换秒到度为单位
  3 # author: scott
  4 # date: 2012.1.30    
  5 # org:  --navi.com
  6 # 
  7 # version: v0.1.0 2012.2.1
  8 #  1.create doc and test ok, types (included point|line|polygon|multipolygon) be supported
  9 # 
 10 
 11 import os,os.path,sys,time,copy,shutil
 12 from osgeo import ogr
 13 
 14 
 15 def do_layerPoint(layer):
 16     ftr = layer.ResetReading()
 17     ftr = layer.GetNextFeature()    
 18     print 'point num:',layer.GetFeatureCount()
 19     print 'extent:',layer.GetExtent()
 20     cc = 1
 21     while ftr:
 22         #print cc
 23         cc+=1
 24         pt = ftr.GetGeometryRef().GetPoint(0)
 25         g = ftr.GetGeometryRef()
 26         #print g#,g.ExportKML()
 27         if pt[0] >1000 or pt[1> 1000:
 28             g.SetPoint(0,pt[0]/3600.,pt[1]/3600.)
 29             #print g
 30             
 31             '''
 32             ng = ogr.Geometry(ogr.wkbPoint)
 33             print pt
 34             ng.SetPoint(0,pt[0]+40,pt[1])
 35             ftr.SetGeometry(ng)        
 36             '''
 37             layer.SetFeature(ftr)
 38         ftr = layer.GetNextFeature()    
 39 
 40 def do_layerLine(layer):
 41     ftr = layer.ResetReading()
 42     ftr = layer.GetNextFeature()
 43     
 44     while ftr:    
 45         g = ftr.GetGeometryRef()
 46         cnt = g.GetPointCount()
 47         cc = 0
 48         while cc < cnt:
 49             #print g.GetPoint(cc)
 50             cc+=1
 51         
 52         for n in range(cnt):
 53             pt = g.GetPoint(n)
 54             if pt[0]>1000 or pt[1> 1000:
 55                 g.SetPoint(n,pt[0]/3600.,pt[1]/3600.0)
 56         layer.SetFeature(ftr)
 57         
 58         ftr = layer.GetNextFeature()
 59 
 60 def do_layerPolygon(layer):
 61     ftr = layer.ResetReading()
 62     ftr = layer.GetNextFeature()
 63     
 64     while ftr:    
 65         g = ftr.GetGeometryRef()    
 66         cnt = g.GetGeometryCount()
 67         for n in range(cnt):
 68             gg = g.GetGeometryRef(n)
 69             for m in range(gg.GetPointCount() ):
 70                 pt = gg.GetPoint(m)
 71                 #print pt
 72                 if pt[0]>1000 or pt[1> 1000:
 73                     gg.SetPoint(m,pt[0]/3600.,pt[1]/3600.0)
 74         layer.SetFeature(ftr)
 75         ftr = layer.GetNextFeature()        
 76         
 77 def do_shpfile(file):
 78     #print file
 79     print 'ready file:',file
 80     driver = ogr.GetDriverByName('ESRI Shapefile')
 81     #shp = driver.Open('e:/shp_data/points.shp',1)  # 0 - read , 1 - write 
 82     shp = driver.Open(file,1)  # 0 - read , 1 - write 
 83     
 84     layer = shp.GetLayer()
 85     
 86     if layer.GetFeatureCount() == 0:
 87         return 
 88     
 89     gtyp = layer.GetLayerDefn().GetGeomType()
 90     
 91     if file.lower().find('province'== -1:
 92         pass #return 
 93         
 94     if gtyp == ogr.wkbPoint:
 95         do_layerPoint(layer)
 96     elif gtyp == ogr.wkbLineString:
 97         do_layerLine(layer)
 98     elif gtyp == ogr.wkbPolygon:
 99         do_layerPolygon(layer)
100     else:
101         print 'unknown type:',gtyp,'  ',file
102     
103     layer.SyncToDisk()    
104     shp.Destroy()
105     
106     
107 def convert(shpdir):
108     files = os.listdir(shpdir)
109     for file in files:
110         if  file.lower().find('.shp'==-1:
111             continue
112         
113         #if file == 'points.shp':
114         do_shpfile(shpdir+"/"+file)
115 
116 if __name__=='__main__':
117     #convert( 'e:/shp_data' )
118     if sys.argv[1:]:
119         convert(sys.argv[1])
120     else:
121         convert( 'D:/temp3/mess/MESH/H51F009012')
122    
posted on 2012-02-02 02:14 放屁阿狗 阅读(853) 评论(0)  编辑 收藏 引用 所属分类: MapGisperl/python/php/lua/tclWebGL

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理