0

I am trying to replicate the join tool that is available in ArcMap by right-clicking on a layer, in an ArcPy script. Specifically, all I want is an attribute field of how many points are inside each polygon. Works perfectly inside ArcMap, but I must have it inside an ArcPy script.

My polygon file has 90 polygons, and my points file has 1,070 points. When I do the join inside ArcMap (screenshot below), my output is a polygon SHP with 90 polygons, and only a "Count_" field is added. (This is perfect.)

When I do it inside ArcPy, my output is a polygon file with 1,070 polygons, a bunch of extra fields, and no sum-count field. I've tried a few different things in the ArcPy script (i.e., "JOIN_ONE_TO_MANY", "CONTAINS", etc.), but no luck. What am I missing?

NOTE: I don't have the Arc license that allows for "summarize_within"

enter image description here

arcpy.SpatialJoin_analysis(Polygons.shp, Points.shp, outFeatureClass, join_operation = "JOIN_ONE_TO_ONE", join_type = "KEEP_COMMON", field_mapping = "", match_option = "INTERSECT", search_radius = "", distance_field_name = "")
1

Ah, got it. Working script below (produces Join_Count field), and I can just drop the extra fields. I found the solution here: https://support.esri.com/en/technical-article/000008599

arcpy.SpatialJoin_analysis(Polygons.shp, Points.shp, outFeatureClass,
        join_operation = "JOIN_ONE_TO_ONE", join_type = "KEEP_ALL",
        field_mapping = "", match_option = "COMPLETELY_CONTAINS",
        search_radius = "", distance_field_name = "")

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.