Select to view content in your preferred language

Getting vertices from object

6443
14
Jump to solution
06-10-2015 04:54 AM
ExEFan
by
Deactivated User

Hi, i am trying to write a code in python that will get me all the vertices from one polygon object. Normally that wouldn't be a problem, but this object comes from Geoview 6, and this polygon object has a hole in the center. In ArcGis 10.2, when you load polygon object, it looks normal. Sketch properties shows all vertices. But when i write a code to print vertices, or to get them in any way, it returns only the outer vertices. It doesn't show (print) 4 vertices inside. Can someone help, and write a code that will print all 19 vertices that this polygon has?

Most importantly, do not change the polygon in any way. When you modify the polygon and save changes, it works. But when i have 1000 polygons, i don't have time to modify them all.

Thank you.

0 Kudos
14 Replies
ExEFan
by
Deactivated User

Thank you very much.

0 Kudos
DuncanHornby
MVP Notable Contributor

I still think using the Feature vertices to point tool is your easiest option but I got interested in the idea of writing it as cursors and accessing geometries. I knocked some code together but it failed. I ran your sample data through the repair geometry tool and re-ran the code and it still failed. I then took a closer look at your data and discovered it does not conform to the definition of polygons with interior rings. Part zero should be the EXTERIOR ring and CLOCKWISE. In your data what looks like the exterior ring is the interior ring! Each ring has the correct orientation but is the wrong part number. Create a polygon with a hole in it in ArcMap and everything is as expected and the code runs spewing out XY for interior rings.

So it's not your code that is at fault it is the data and the software that generated it. It looks like what ever created it has built the polygon in to out rather than out to in.

Capture.PNG

DarrenWiens2
MVP Alum

I can't explain why the da.SearchCursor Search@ token ignores the second part.

You can, however, get at the vertices by flipping to numpy and back again, setting explode to points as True.

>>> sr = arcpy.Describe("Sample").spatialReference
... nparr = arcpy.da.FeatureClassToNumPyArray("Sample","*","",sr,True)
... arcpy.da.NumPyArrayToFeatureClass(nparr,r'C:/junk/out.shp','Shape',sr)

1.PNG

DuncanHornby
MVP Notable Contributor

This is a nifty way, I like that!

0 Kudos
ExEFan
by
Deactivated User

Thank you.

0 Kudos