使用CalculateField_management工具,可以在计算形状长度时指定度量单位:
#Calculate polyline lengths in miles
polylines = "C:\sampleShape.shp"
arcpy.CalculateField_management(polylines, "shapeLen", "!Shape.length@MILES!", "PYTHON_9.3")
我想使用每个功能的'SHAPE @ LENGTH'在光标内执行相同的操作,并以我选择的单位返回长度:
#hypothetical example 1
with arcpy.da.UpdateCursor(polylines, field_names=["SHAPE@LENGTH.FEET", "shapeLen"]) as upCurs:
for row in upCurs:
row[1] = row[0]
upCurs.updateRow(row)
还是可以使用(效率较低的)@SHAPE几何对象?
#hypothetical example 2
with arcpy.da.UpdateCursor(polylines, field_names=["@SHAPE", "shapeLen"]) as upCurs:
for row in upCurs:
row[1] = row[0].length@FEET
upCurs.updateRow(row)
有什么办法可以做到这一点?