1. 程式人生 > >使用python讀取向量資料的座標點如shp資料

使用python讀取向量資料的座標點如shp資料

在ArcGIS中複製出向量資料如shp、FeatureClass的座標節點是一件很麻煩的事情,通過arcpy等模組讀取座標點到文字中方便了許多。

#讀取要素的座標點,包括挖空地塊的座標點,輸出到excel檔案中,外圈使用1,內圈使用-1標識。
import arcpy
... import xlwt
... fc=r"F:\test.shp"
... cursor=arcpy.da.SearchCursor(fc,["[email protected]","欄位1","欄位2","[email protected]"])
... 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")

效果圖如下: