I have a shapefile with many non-overlapping polygons, touching each other (see sample screenshot below):

sample screenshot

All these polygons have a field called 'avg_ht' in the attribute table, which is a 32-bit float (average height of trees). Some of these polygons have to be merged with others based on the following criteria. Consider polygon1 and polygon2. They should be merged if:

  1. They are adjacent to each other
  2. abs(polygon1.avg_ht - polygon2.avg_ht) <= 1.0

Condition #2 above basically checks if the difference between the average heights of the candidate polygons is less than 1.0 units.

What is the best way to do this? I have license for the eliminate tool but am not sure if it is the best way.

  • If three polygons in a line have heights 10-11-12 (10 and 12 not adjacent) you want to dissolve them into one?
    – BERA
    Jun 22, 2018 at 11:21
  • Eliminate is a good tool to do that, you need to select all the attributes. Then you need to specify the expression as (abs( "polygon1.avg_ht"- "polygon2.avg_ht") >=1)
    – Moh
    Jun 22, 2018 at 11:23
  • Yes @BERA, they should all be merged into one. Jun 22, 2018 at 13:59

1 Answer 1


Workflow below finds edges between polygons to be used to construct larger polygons. They include outer edges and ones where difference in heights is greater than threshold:

arcpy.Dissolve_management("outlines", "C:/SCRATCH/edges.shp","SINGLE_PART")
arcpy.SpatialJoin_analysis("edges", "fish_net", "../SJ.shp", "JOIN_ONE_TO_MANY", "KEEP_ALL", .."SHARE_A_LINE_SEGMENT_WITH")
arcpy.Statistics_analysis("SJ", "../SCRATCH.gdb/min_max", "HEIGHT MIN;HEIGHT MAX", "TARGET_FID")
arcpy.AddJoin_management("edges", "FID", "min_max", "TARGET_FID")
# select outer edges and ones with high gradient
arcpy.SelectLayerByAttribute_management("edges", "NEW_SELECTION", "min_max.FREQUENCY = 1 OR ( min_max.MAX_HEIGHT- min_max.MIN_HEIGHT)>1")
arcpy.FeatureToPolygon_management("edges", "...gdb/RESULT")

enter image description here

  • It works very well, thanks a lot! The only change I had to make was using named arguments. For example, the second line became: arcpy.Dissolve_management("outlines", "C:/SCRATCH/edges.shp",multi_part="SINGLE_PART"). It would be great if you can add those edits too, to make the answer even better. Jun 27, 2018 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.