Hello,
I want to know if there's a way to perform a spatial join in ArcGIS Pro (or using Python) between Polygon A and B (B being the target) where the Polygon A that shares the largest overlap in area with the target is the one that gets joined. I saw that there is a tool for ArcMap, but if I'm using ArcGIS Pro, how do I accomplish this? My issue is if I'm joining polygons with different shapes and centre points, many other join type criteria just don't do a correct match.
Intersect sometimes selects an adjacent polygon whose boundary intersects the target rather than the one that overlaps the target the most. Have Their Center In won't work if the join polygon has a completely different centre point than the target. I am having trouble making correct join matches in this situation.
Please help!
Did you try the tool in Pro?
I imported the toolbox:
The tool opens...
Oh nice, I didn't actually know the tool even worked in Pro since it was developed for ArcMap. I tested it and it doesn't appear to complete because of syntax errors. See message below.
I guess the script needs some kind of adjusting for Pro?
Oh, that would be good if that's the only change that needs to be made (that'll be a Python 2 to Python 3 thing).
Try adding the parentheses and saving:
I'm not entirely sure if you would need to close Pro and re-open, but give that a go.
Dianne Gray Kory Kramer The Spatial Join - Largest Overlap download has been updated to remove that ridiculous print at the end.
Hi Drew, I have another problem with this tool. I just tried running it using both Keep All Features checked and unchecked:
Traceback (most recent call last):
File "E:\Library\GIS DATA\SCRIPTS\SpatialJoinLargestOverlap\Scripts\SpatialJoinLargestOverlap.py", line 85, in <module>
SpatialJoinLargestOverlap(target_features, join_features, out_fc, keep_all, spatial_rel)
File "E:\Library\GIS DATA\SCRIPTS\SpatialJoinLargestOverlap\Scripts\SpatialJoinLargestOverlap.py", line 41, in SpatialJoinLargestOverlap
for row in scur:
RuntimeError: An invalid SQL statement was used.
Failed to execute (SpatialJoinLargestOverlap).
What could be causing this problem? I thought it could be the dataset (I was using one that had over 200,000 records, but I created a subset of that that's only 2100 items, and it still fails to run).
Maybe I have the same case
Traceback (most recent call last):
File "D:\GIS Studio\Spatial-Join_Largest-Overlap\SpatialJoinLargestOverlap\Scripts\SpatialJoinLargestOverlap.py", line 85, in <module>
SpatialJoinLargestOverlap(target_features, join_features, out_fc, keep_all, spatial_rel)
File "D:\GIS Studio\Spatial-Join_Largest-Overlap\SpatialJoinLargestOverlap\Scripts\SpatialJoinLargestOverlap.py", line 73, in SpatialJoinLargestOverlap
arcpy.management.JoinField(out_fc, "JOIN_FID", join_features, arcpy.Describe(join_features).OIDFieldName, joinfields)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 8015, in JoinField
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 8012, in JoinField
retval = convertArcObjectToPythonObject(gp.JoinField_management(*gp_fixargs((in_data, in_field, join_table, join_field, fields), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000308: Invalid field type
Failed to execute (JoinField).
I used 106.000 records
Hi AlfiyanMustaqim,
I had found a solution to essentially perform a Select by Location using Largest Overlap. Please see
https://community.esri.com/t5/python-questions/select-by-location-largest-overlap/m-p/1054383#M61026
I hope this helps you accomplish what you set out to do.