0

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

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
rrrrrrrr
  • 13
  • 4
  • Use difference method for geometry, e.g. https://gis.stackexchange.com/questions/293433/arcgis-method-to-partially-erase-or-clip-thousands-of-related-polygons/293447#293447 – FelixIP Jun 02 '19 at 03:07
  • @FelixIP unfortunately this is happening inside one feature class – rrrrrrrr Jun 03 '19 at 16:41
  • It doesn't matter at all. – FelixIP Jun 03 '19 at 20:23
  • @FelixIP Can you explain further? I am unclear on how to implement this. Can I call the next row in a cursor somehow and then use shp.difference? – rrrrrrrr Jun 03 '19 at 21:16

1 Answers1

0

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

enter image description here

Result, 1st record selected

enter image description here

FelixIP
  • 22,922
  • 3
  • 29
  • 61