使用python读取矢量数据的坐标点如shp数据

在ArcGIS中复制出矢量数据如shp、FeatureClass的坐标节点是一件很麻烦的事情,通过arcpy等模块读取坐标点到文本中方便了许多。

#读取要素的坐标点,包括挖空地块的坐标点,输出到excel文件中,外圈使用1,内圈使用-1标识。
import arcpy
... import xlwt
... fc=r"F:\test.shp"
... cursor=arcpy.da.SearchCursor(fc,["OID@","字段1","字段2","SHAPE@"])
... xlsfile=xlwt.Workbook(encoding="utf-8")
... sht=xlsfile.add_sheet("sheet1","cell_overwrite_ok=True")
... rownum=0
... for feature in cursor:
...     if not feature[3]:
...         sht.write(rownum,0,feature[0])
...         sht.write(rownum,1,"空几何")
...         rownum=rownum+1
...         continue
...     else:
...         for pa in feature[3]:
...             j=0
...             bsm=1   
...             for pnt in pa:    
...                 if not pnt:
...                     bsm=-1
...                     j=0
...                     continue
...                 sht.write(rownum,0,feature[0])
...                 sht.write(rownum,1,feature[1])
...                 sht.write(rownum,2,feature[2])
...                 sht.write(rownum,3,j)
...                 sht.write(rownum,4,pnt.X)
...                 sht.write(rownum,5,pnt.Y)
...                 sht.write(rownum,6,bsm)
...                 rownum=rownum+1 
...                 j=j+1                                  
... xlsfile.save(r"F:\test.xls")

效果图如下:

猜你喜欢

转载自www.cnblogs.com/apromise/p/10005778.html