本文主要是介绍【ArcPy】游标访问几何数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
访问质心坐标相关数据
结果展示
代码
import arcpy
shppath =r"C:\Users\admin\Desktop\excelfile\a2.shp"
with arcpy.da.SearchCursor(shppath, ["SHAPE@","SHAPE@XY","SHAPE@TRUECENTROID","SHAPE@X","SHAPE@Y","SHAPE@Z","SHAPE@M",]) as cursor:for row in cursor:print("几何对象:",row[0],"质心 x,y 坐标:", row[1],"质心 x,y 坐标:" ,row[2],"双精度 x 坐标:",row[3],"双精度 y 坐标:",row[4],"双精度 z 坐标:",row[5],"双精度 m 值:",row[6])
访问几何的 Esri JSON 字符串
结果展示
由图可以看出json字段包括要素的坐标数据和坐标系数据
代码
import arcpy
shppath =r"C:\Users\admin\Desktop\excelfile\a2.shp"
with arcpy.da.SearchCursor(shppath, ["SHAPE@JSON"]) as cursor:for row in cursor:print("几何的 Esri JSON 字符串:",row[0])
访问几何的WKB(二进制)
结果展示
代码
import arcpy
shppath =r"C:\Users\admin\Desktop\excelfile\a2.shp"
with arcpy.da.SearchCursor(shppath, ["SHAPE@WKB"]) as cursor:for row in cursor:print("几何的WKB:",row[0])
访问几何的WKT(文本)
结果展示
代码
import arcpy
shppath =r"C:\Users\admin\Desktop\excelfile\a2.shp"
with arcpy.da.SearchCursor(shppath, ["SHAPE@WKT"]) as cursor:for row in cursor:print("几何的WKT:",row[0])
访问几何的面积和长度
结果展示
代码
import arcpy
shppath =r"C:\Users\admin\Desktop\excelfile\a2.shp"
with arcpy.da.SearchCursor(shppath, ["SHAPE@AREA","SHAPE@LENGTH"]) as cursor:for row in cursor:print("面积:",row[0],"长度:",row[1])
这篇关于【ArcPy】游标访问几何数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!