I am using ArcGIS Desktop 10.6, basic license, Spatial Analyst, python 2.6, 2019 AD.
I have a polygon feature class with representing a lake, with multiple features overlapping (all in the same feature class). The shoreline feature covers the entire area of the lake, the 1 foot depth feature covers all of the area at 1 foot, etc, etc. Opening an editing session and starting at the deepest depth, I can use the Editor toolbar Clip function to clip each area from the others. The end result is a flat representation of the lake, no overlapping depths.
To accomplish this with arcpy, I think I need to sort my list descending from the largest depth and clip the below features. I've attached a sample feature class that this script would intake, and another ("flat") that should be output.
import arcpy
from arcpy import env
try:
# Set workspace environment
env.workspace = "C:/data/default.gdb"
# intake lake
in_dataset = arcpy.GetParameterAsText(0)
# sort the lake attribute table by the depth
sort_fields = ["depth", "DESCENDING"]
# Use Peano algorithm
sort_method = "PEANO"
# sort the fc, run Editor Clip on each attribute, starting with the largest
arcpy.Sort_management(in_dataset, sort_fields, sort_method)
with arcpy.da.SearchCursor(in_dataset, 'SHAPE@') as cursor:
for row in cursor:
#don't know how to call this part
EditorClipTool(row, "DISCARD")
print arcpy.GetMessages()
except arcpy.ExecuteError:
# Print error messages
print arcpy.GetMessages(2)
except Exception as ex:
print ex.args[0]
input: https://drive.google.com/open?id=1ShZ5OQensnskLbgIzMWroVM2GIKLukou
desired output: https://drive.google.com/open?id=1QLbLr30yY136wvAUaEXEHSrM33ZKR3cG
Answer
Use this on a sorted copy of your polygons:
import arcpy
## works on sorted table !!!
g=arcpy.Geometry()
geomList=arcpy.CopyFeatures_management("POLYGONS",g)
N=0
with arcpy.da.UpdateCursor("POLYGONS","Shape@") as cursor:
for row in cursor:
N+=1
if N==len(geomList):break
origPgon=row[0]
newPgon=origPgon.difference(geomList[N])
cursor.updateRow((newPgon,))
Original, 1st record selected
Result, 1st record selected
No comments:
Post a Comment