ArcGIS帮助中的相关代码并不能直接运行,进行了小幅修改,现在就可以直接运行了。
python代码的大致思路是:
(1)先获得描述shp的相关信息,获得存储图形信息的字段名;
(2)然后获得游标;
(3)最后对游标进行遍历。
下面就贴上代码了:
import arcpy
#!!!please change the path!!!
shpPath = "D:/data/A156.shp"
desc = arcpy.Describe(shpPath)
shapefieldname = desc.ShapeFieldName
rows = arcpy.SearchCursor(shpPath)
# Enter for loop for each feature/row
#
for row in rows:
# Create the
geometry object
#
feat =
row.getValue(shapefieldname)
# Print the current
multipoint's ID
#
print "Feature " +
str(row.getValue(desc.OIDFieldName)) + ":"
partnum =
0
# Count the number
of points in the current multipart feature
#
partcount =
feat.partCount
# Enter while loop
for each part in the feature (if a singlepart feature
# this will occur
only once)
#
while partnum
< partcount:
# Print the part number
#
print "Part " + str(partnum) + ":"
part = feat.getPart(partnum)
pnt = part.next()
pntcount = 0
# Enter while loop for each vertex
#
while pnt:
x,y coordinates of current point
#
pnt.X, pnt.Y
pnt =
part.next()
pntcount
+= 1
# If pnt
is null, either the part is finished or there is
an
#
interior ring
#
if not
pnt:
pnt = part.next()
if pnt:
print "Interior Ring:"
partnum += 1