Hi,
I am trying to perform an eliminate on sub-acre polygons in a feature class. I need to choose 1 surrounding polygon to merge with the subacre poly based on prioritized criteria rules (if statements). I am not sure this is possible without creating feature classes for each subacre polygon and it's surrounding polygons, performing the eliminate, then appending them all back into a new feature class. Ideas?
The rules would be in order A, B, C, D, E, F, G. Rules example: A would merge with B, B with C and so on but A could be surrounded by any letter
I have code that selects and re-selects to whittle it down so that only the 2 polygons to be merged remain and it's in a loop but Eliminate wants a feature layer as the input, not 2 polygons.
Solved! Go to Solution.
Once you have the polygons, you could use the geometry itself with one of the many geometric operations:
Once you have the polygons, you could use the geometry itself with one of the many geometric operations:
That's it. Thank you much.
When I get it working I will post the code
I have code that selects and re-selects to whittle it down so that only the 2 polygons to be merged remain and it's in a loop but Eliminate wants a feature layer as the input, not 2 polygons.
Eliminate wants a feature layer with a selection active on polygons that you want to remove.
I'm wondering if you are using the right tool here.. like maybe a Feature To Line, followed by processing of left/right polygon information, followed by Dissolve.
Perhaps you could provide a more detailed description of what you are trying to do?
... and B to C, right?
Would the result of the image posted be something like this (3 polygons, indicated with the black outline)?
You will probably have to keep trace of the original polygon neighbors to define the contiguity you are looking for. Example; look the the polygon B in the lower right corner. It is connected to the small polygon A in its upper left corner. This will create a polygon composed of AB, but when you check for further contiguity there is polygon C (in the upper left corner bordering to the small polygon A, now part of AB). Since this polygon C is not connected to the polygon B but only to the original polygon A, you cannot include it in the polygon AB. This relation can only be checked in the original neighbors.
You may want to look at the Polygon neighbors tool: ArcGIS Help (10.2, 10.2.1, and 10.2.2) (if you have access to an advanced license). This will be of great help in the process.
What the finished product would look like (the polygon neighbor tool looks very promising)
Here is how I got it to work. I would still prefer to find a way to do this without creating all the feature layers and appending. Ideas?????
import arcpy arcpy.env.overwriteOutput = True fc = "C:\\Amy\\Test.gdb\\SubAcreTest_p" ntbl = "C:\\Amy\\Test.gdb\\Neighbor_tbl" sorttbl = "C:\\Amy\\Test.gdb\\tbl_sort" stattbl = "C:\\Amy\\Test.gdb\\tbl_stat" arcpy.AddMessage("Performing neighbor analysis....") arcpy.PolygonNeighbors_analysis(fc, ntbl, "OBJECTID;Acre;SHAPE_Length;SHAPE_Area;Letter", "NO_AREA_OVERLAP", "BOTH_SIDES", "", "FEET", "SQUARE_METERS") sc = arcpy.da.UpdateCursor(ntbl, ['src_Acre', 'NODE_COUNT']) arcpy.AddMessage("Removing polygons larger or equal to 1 acre and removing node polygons from neighbor table....") for s in sc: if s[0] > 1: sc.deleteRow() elif s[1] == 1: sc.deleteRow() del s, sc arcpy.AddMessage("Making sort table....") arcpy.Sort_management(ntbl, sorttbl, "src_Acre ASCENDING;nbr_Letter ASCENDING", "UR") #making sure the first letter choice is first in position for stat table to isolate arcpy.AddMessage("Making summary statistics table....") arcpy.Statistics_analysis(sorttbl, stattbl, "nbr_Letter FIRST;nbr_OBJECTID FIRST", "src_OBJECTID") #make table (used in query) for selecting the first letter and coresponding object id's to be merged arcpy.env.workspace = "C:\\Amy\\Test.gdb\\polyfiles" #feature dataset #searching for object id's in stat table to use in query of final feature class #code will grab object id's from stat table, make a feature layer of 2 polygons to be dissolved and dissolve them, delete individual polygons from final layer and append the dissolved polygon into the final feature class cursor = arcpy.da.SearchCursor(stattbl, "*") for row in cursor: OID1 = row[1] OID2 = row[4] arcpy.AddMessage("Merging layers for Object ID's: " + str(OID1) + " and " + str(OID2)) where_clause = "OBJECTID = %s OR OBJECTID = %s"%(OID1,OID2) arcpy.MakeFeatureLayer_management(fc, "tmplyr", where_clause) diss_name = "Dissolve_%s_%s"%(OID1,OID2) sort_name = "Sort_%s_%s"%(OID1,OID2) arcpy.Sort_management("tmplyr", sort_name, "Letter ASCENDING", "UR") arcpy.Dissolve_management(sort_name, diss_name, "", "Acre MAX;Letter LAST", "MULTI_PART", "DISSOLVE_LINES") uc = arcpy.da.UpdateCursor(fc, "OBJECTID") for u in uc: if u[0] == OID1: uc.deleteRow() elif u[0] == OID2: uc.deleteRow() arcpy.Append_management(diss_name, fc, "NO_TEST", "Acre \"Acre\" true true false 8 Double 0 0 ,First,#,Dissolve_1_5,MAX_Acre,-1,-1;Letter \"Letter\" true true false 10 Text 0 0 ,First,#,Dissolve_1_5,LAST_Letter,-1,-1;SHAPE_Length \"SHAPE_Length\" false true true 8 Double 0 0 ,First,#,Dissolve_1_5,SHAPE_Length,-1,-1;SHAPE_Area \"SHAPE_Area\" false true true 8 Double 0 0,First,#,Dissolve_1_5,SHAPE_Area,-1,-1", "") del u, uc del row, cursor