3

I have this apparently complex problem for solving in ArcGIS:

enter image description here

Practically, I need to get the number of all yellow polygons that fall within both the green polygons and the red polygons. I need this for each red polygon.

In other words, I need an attribute column attached to every red polygon that holds the count of yellow polygons contained within the green ones.

I can only think of Spatial Join, but I find it very cumbersome to pass the count of yellow blocks from green polygons to red ones.

Are you aware of any other straighforward tools?

  • I would try to do this using Union (two at a time if you are not using an Advanced level license) followed by Summary Statistics as my basis. Union will write all the overlapping relationships for your input polygon feature classes into a single feature class ready for summarizing. There may need to be a step or two added at the end depending on your precise requirements like totally/partially overlapping, etc. – PolyGeo Oct 1 '14 at 21:54
1

Straightforward no, but a not too hard block of Python code might help you out. First, make sure you have added a new field in the Red Polygon attribute table and call it something like "field_count". The code is this:

    uc = arcpy.UpdateCursor(redPolys)
    yellowLyr = arcpy.MakeFeatureLayer_management(yellowPolys)

    for row in uc:
        geometry = row.shape
        arcpy.SelectLayerByLocation_management(yellowLyr, 'WITHIN', geometry, '', 'NEW_SELECTION')
        arcpy.SelectLayerByLocation_management(yellowLyr, 'WITHIN', greenPolys, '', 'SUBSET_SELECTION')
        count = int(arcpy.GetCount_management(yellowLyr).getOutput(0))
        row.setValue('count_field', count)
        uc.updateRow(row)

This will go through the red polygons taking them one by one. It selects the yellow polygons within, and from this selection it selects only the polygons within the green polygons. Then the number of selected yellow polygons is counted, and this number is written to a counting field in the red polygons feature class.

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.