Skip to content

Instantly share code, notes, and snippets.

@black-tea
Last active April 8, 2022 03:57
Show Gist options
  • Save black-tea/aab69b56fb2281125dd8 to your computer and use it in GitHub Desktop.
Save black-tea/aab69b56fb2281125dd8 to your computer and use it in GitHub Desktop.
Basic Spatial Join in ArcPy. In this case, a one-to-many that will create new rows for every match.
#### This script will take the Riits Sensor Shp, and copy the assetIDs of all intersecting points to the attribute table of the Riits layer
import arcpy
from arcpy import env
env.workspace = "Z:/GIS/DataLibrary/Transportation/BOE_Centerline_Intersections150930/collisiontoInt_test.gdb"
env.overwriteOutput = True #so we can rerun this script and overwrite our output feature class
#input
Riits_sensor_shp = "Z:/GIS/DataLibrary/Riits/TrafficVolumes/data dump/EXPORT - 2015/RiitsSensorsproj.shp"
int_fc = "MergedIntersections"
arcpy.FeatureClassToFeatureClass_conversion(speed_shp, env.workspace, "Riits")
#output
output_speed_fc = "IntRiitsJoin"
arcpy.SpatialJoin_analysis("Riits", int_fc, output_speed_fc, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_COMMON", match_option="CLOSEST",search_radius="75 Feet")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment