How do I do a Spatial Join in ArcGIS Python

2964
4
01-09-2019 04:52 PM
KennMurphy
New Contributor

I've been looking around and can't seem to find a good example for this, most likely because I'm not looking in the right places. I have a FeatureSet with Longitude and Latitude coordinates (and other data not related to location) that I'd like to compare to a FeatureLayer of polygons (districts in our service territory) to see which features from the FeatureSet fall within which polygon in the FeatureLayer. Then I'd ultimately like to be able to add the district number or name to the FeatureSet data.

This is all being done with ArcGIS Online, but I'm not against creating local temporary files to store things in if necessary.

Just need a bit of direction.

Thanks,

Kenn

0 Kudos
4 Replies
JayantaPoddar
MVP Esteemed Contributor

Hi Kenn,

Found this in ArcGIS API for Python Documentation. arcgis.features.analysis.join_features (Python method, in arcgis.features.analysis module) — arcgis ... 

Hope it helps...



Think Location
simoxu
by MVP Regular Contributor
MVP Regular Contributor

The easiest way to do it will be using Join Features analysis in ArcGIS Online given all your data are already in AGOL. If it's a one-off task, I would use the GUI to to it;  if it's a repetitive process for many data sets, Python API is the way to go as Jayanta pointed out.

0 Kudos
KennMurphy
New Contributor

I was messing around with the arcgis.features.analysis.join_features function that Jayanta mentioned, but whenever I used it, it would not figure out which polygons the point data was in. It did join all the fields, but that's not what I was looking for. I may have been going down the wrong path.

This will end up being a once-a-day automated process, so I would prefer to do it in Python.

What I ended up doing was use the arcgis.geometry.Geometry.contains function to determine if the point was in the polygon. My data set will always be small, so it's not a performance issue to loop through my 7 polygons and 4 or 5 points to figure this out.

I appreciate the suggestions!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

How specifically did you structure the call with arcgis.features.analysis.join_features?

0 Kudos