0

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?

closed as off-topic by BERA, Vince, nmtoken, Evil Genius, Hornbydd May 9 '18 at 16:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – nmtoken, Evil Genius
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Possible duplicate of Extracting coordinates of polygon vertices in ArcMap? – BERA May 9 '18 at 5:15
  • If you want the point coordinates you could use arcpy.da.SearchCursor("Building","Shape@XY"), see also desktop.arcgis.com/en/arcmap/10.3/analyze/python/… – Dan May 9 '18 at 5:19
  • That will return XY of the centroids, not the vertices – BERA May 9 '18 at 5:19
  • You need to go one level deeper: for part in row[0]: for p in part: print p. Read more about it resources.arcgis.com/en/help/main/10.2/index.html#//… 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 9 '18 at 5:21
  • @BERA, read the question too quick...missed the polygon reference. – Dan May 9 '18 at 5:22
3

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.

  • 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 9 '18 at 6:02
  • Greate, I will try this – Hilal Al-Rajhi May 9 '18 at 6: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 1:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.