I am trying to spatially join a polygon shapefile to a point shapefile such that every point is matched to the characteristics of the polygon it falls inside. I have succeeded to do this spatial join within the ArcMap following the steps below and in the picture:
- Right-click on point shapefile --> Joins and Relates --> Join
- What I have selected in the picture
Now I am trying to replicate the result with ArcPy which is more convenient for me because it will allow me to replicate the results in the future. This is the code I tried:
### Define input, output etc. target_features = "data/raw/population_weights/nhgis0009_shape/CA_block_2010.shp" join_features = "data/raw/voting_precincts/shapefile/voting_precincts.shp" out_feature_class = "data/raw/population_weights/nhgis0008_shape/block_points_merged_2.shp" ### Do spatial join arcpy.SpatialJoin_analysis(target_features, join_features, out_feature_class)
However, I then end up with a polygon shapefile (the points must be somehow joined to the polygons and not vice versa). I have tried to switch target feature and join feature but the result is the same.
Is SpatialJoin_analysis the correct tool for what I am trying to do? How would the correct python code look that will replicate the steps I described above?
Edit (see comments below): Results window for the spatial join I want to perform