1

Based on my understanding in coding, I thought the following code will list all points in every feature in my Building polygon feature class:

arcpy.env.workspace=r'D:\test.gdb'
rows=arcpy.da.SearchCursor("Building","Shape@")
for row in rows:
    print row
    for p in row:
        print p

But that displays the following results for each polygon:

(<Polygon object at 0x324838f0[0x32483ee0]>,)
<geoprocessing describe geometry object object at 0x32483EE0>

What is missing in my code?

Hilal Al-Rajhi
  • 210
  • 1
  • 11
  • 1
  • If you want the point coordinates you could use arcpy.da.SearchCursor("Building","Shape@XY"), see also http://desktop.arcgis.com/en/arcmap/10.3/analyze/python/reading-geometries.htm – Dan May 09 '18 at 05:19
  • That will return XY of the centroids, not the vertices – BERA May 09 '18 at 05:19
  • You need to go one level deeper: for part in row[0]: for p in part: print p. Read more about it http://resources.arcgis.com/en/help/main/10.2/index.html#//002z0000001t000000 what you're currently displaying is the polygon object, as it says, which is the geometry (SHAPE@); a polygon is made of parts (at least one RING) and the part is made of points so you need to go polygon->parts->points. Printing p should give you Point object, you might want to print "{},{}".format(p.X,p.Y) to get something sensible to read. That will only do one feature class, you'll need to put in another loop to do all. – Michael Stimson May 09 '18 at 05:21
  • @BERA, read the question too quick...missed the polygon reference. – Dan May 09 '18 at 05:22
  • Thank you Mr. Michael Stimson, that really solved my problem. Now only I understand that there are parts in geometry object. – Hilal Al-Rajhi May 09 '18 at 05:42
  • Is there a picture that has a structured representation of geometry parts? – Hilal Al-Rajhi May 09 '18 at 05:45
  • Not so much, there's the OGC spec which isn't very exciting... what we call polygon and polyline are actually containers that contain a multipart geometry (like a multipoint is made of points).. Polygons are made from rings, polylines are made from paths. Polygon rings can be exterior (outer boundary) or interior (hole); both rings and paths are made from points (vertices), it makes a bit more sense from the ArcObjects side of things but is still a little strange until you get used to it. – Michael Stimson May 09 '18 at 06:06

1 Answers1

4

Based on @MichaelStimson's comments I solved the problem this way:

arcpy.env.workspace=r'D:\hilal\test.gdb'
rows=arcpy.da.SearchCursor("Building","Shape@")
for row in rows:
    print row
    for p in row[0]:
        for r in p:
            print r

This display every polygon and it's polygon points.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Hilal Al-Rajhi
  • 210
  • 1
  • 11
  • Now the next step is to do for FC in arcpy.ListFeatureClasses('*','POLYGON'): with arcpy.da.SearchCursor(FC,'SHAPE@'): for row in rows: to do all the polygon feature classes in your workspace. – Michael Stimson May 09 '18 at 06:02
  • Greate, I will try this – Hilal Al-Rajhi May 09 '18 at 06:57
  • This is the memory address of your polygon object i.e a pointer to polygon <Polygon object at 0x324838f0[0x32483ee0]>. The data you extracted is inside the polygon object – ozzyzig May 13 '18 at 01:36