Eliminating Polygons with a Shared Area with a Larger Polygon in the Same Feature Class

3413
2
03-11-2015 02:46 PM
BrianPenserini
New Contributor

I have a feature class that contains ~4000 polygons that represent catchments as well as subcatchments within those catchments. Therefore, many of the polygons within my feature class overlap entirely with other polygons in the same feature class. Is there a way for me to delete all of the polygons within this feature class that share their areas with larger polygons (essentially deleting all the subcatchments), such that I'm left with only the largest polygons (the catchments)? I'd like to avoid manually selecting only the catchments as I hope to use whatever method I end up using on a much larger dataset of polygons. Any help would be greatly appreciated.

Thanks in advance.

0 Kudos
2 Replies
JayantaPoddar
MVP Esteemed Contributor

Hi Brian,

You could try the Geodatabase Topology (Must Not Overlap) to resolve the issue.

Thanks,

Jay



Think Location
0 Kudos
KishorGhatage
Occasional Contributor III
import arcpy


#Input featrue class path
in_fc = r"C:\Test.gdb\Catchment"


# Output file geodatbase
out_GDB = r"C:\Test.gdb"


# Output feature Class Name
out_FC = "Final_catchment"


arcpy.MakeFeatureLayer_management(in_fc,"in_memory\Catchment_Copy")
arcpy.MakeFeatureLayer_management(in_fc,"in_memory\Catchment_Copy1")


cursor = arcpy.SearchCursor("in_memory\Catchment_Copy")
    
for feature in cursor:
    
    val = feature.getValue("OBJECTID")
       
    where = "OBJECTID =" + str(val)
    
    arcpy.SelectLayerByAttribute_management("in_memory\Catchment_Copy","NEW_SELECTION",where)


    arcpy.SelectLayerByLocation_management("in_memory\Catchment_Copy1","WITHIN_CLEMENTINI","in_memory\Catchment_Copy","","NEW_SELECTION")


    result = arcpy.GetCount_management("in_memory\Catchment_Copy1")


    count = int(result.getOutput(0))
        
    if count == 1:


        arcpy.DeleteFeatures_management("in_memory\Catchment_Copy")


        print "ObjectID : "+ str(val) + " is Deleted"
        
arcpy.FeatureClassToFeatureClass_conversion("in_memory\Catchment_Copy", out_GDB,out_FC,"")


del cursor

print "Process completed successfully."

I am learning python and I find this issue very interesting. Hence, I tried to create above script and tested the behavior with a sample data at my end. This script worked as expected at my end. Please let me know how it works at your end.

I request all python experts to give your suggestions to make this script better and improve my skill.

Hope this is helpful

Thanks and regards

Kishor