How to delineate/draw the edge of polygon automatically?

2061
12
02-07-2017 01:10 PM
Zihan_Lin
New Contributor III

I would like to delineate the edge of my extraction below, not by hand, just automatically. I want to eliminate the inside polygons and keep the outermost edge only (highlighted by blue, not accurately). Could anyone give me some hints on this part? Thank you in advance!

Edge extraction

Tags (1)
0 Kudos
12 Replies
Zihan_Lin
New Contributor III

Thanks a lot!!! That works! 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Generating a polygon from the outer ring of the polygon with holes also gets you want you want.  If you want to use ArcPy and cursors, the following should work:

>>> from itertools import takewhile
>>> 
>>> fc = # path to feature class containing polygons with holes
>>> with arcpy.da.UpdateCursor(fc, "SHAPE@") as cur:
...     for polygon, in cur:
...         SR = polygon.spatialReference
...         polygon = arcpy.Polygon(
...             arcpy.Array(
...                 (pt for pt in takewhile(bool,part))
...                 for part
...                 in polygon.getPart()
...             ), SR
...         )
...         cur.updateRow([polygon])
...         
>>>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍  ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

It may seem odd on Line 09 to have a generator expression that simply returns an item for each item in the iterable returned by takewhile, but this is necessary because arcpy.Array is very picky about the type of iterable it will process.

Zihan_Lin
New Contributor III

Cool! I will try! Thanks a lot!

0 Kudos