Select to view content in your preferred language

Spatial Join Script

383
0
07-07-2023 10:09 AM
AnthonyRodriguez1
New Contributor

Hi All,

I'm new to the GIS world and am trying to create a script that creates several Spatial Joins for all of our district school zones.  I currently use Model Builder and this is what comes out when I copy and paste the last command from the history panel.  I'm trying to understand all the values of the Field Mappings and how I can make a stand-alone script that runs monthly and provides the necessary data for our District's school zoning.  Should I be storing all this in a dictionary to reference as I run the spatial join on each shape file?  I'm ultimately looking for best practices and how I can run this process monthly without any incorrect data.

 

arcpy.analysis.SpatialJoin(
target_features="DBO.AddressPoints20230602",
join_features="ProposedBoundaries",
out_feature_class=r"S:\Zoning2122\MyProject33\Zoning2122\MyProject33\MyProject33.gdb\DBO_SpatialJoinEL",
join_operation="JOIN_ONE_TO_ONE",
join_type="KEEP_ALL",
field_mapping='OBJECTID "OBJECTID" true true false 4 Long 0 10,First,#,DBO.AddressPoints20230602,OBJECTID,-1,-1;Flag "Flag" true true false 10 Text 0 0,First,#,DBO.AddressPoints20230602,Flag,0,10;ESiteID "ESiteID" true true false 4 Long 0 10,First,#,DBO.AddressPoints20230602,ESiteID,-1,-1;GPSFLG "GPSFLG" true true false 1 Text 0 0,First,#,DBO.AddressPoints20230602,GPSFLG,0,1;SiteType "SiteType" true true false 2 Text 0 0,First,#,DBO.AddressPoints20230602,SiteType,0,2;LR "LR" true true false 1 Text 0 0,First,#,DBO.AddressPoints20230602,LR,0,1;Post_Code "Post_Code" true true false 5 Text 0 0,First,#,DBO.AddressPoints20230602,Post_Code,0,5;ESN "ESN" true true false 4 Long 0 10,First,#,DBO.AddressPoints20230602,ESN,-1,-1;Long "Long" true true false 8 Double 8 18,First,#,DBO.AddressPoints20230602,Long,-1,-1;Lat "Lat" true true false 8 Double 8 18,First,#,DBO.AddressPoints20230602,Lat,-1,-1;ParcelNum "ParcelNum" true true false 20 Text 0 0,First,#,DBO.AddressPoints20230602,ParcelNum,0,20;PD "PD" true true false 5 Text 0 0,First,#,DBO.AddressPoints20230602,PD,0,5;PT "PT" true true false 5 Text 0 0,First,#,DBO.AddressPoints20230602,PT,0,5;St_Name "St_Name" true true false 50 Text 0 0,First,#,DBO.AddressPoints20230602,St_Name,0,50;St_PosTyp "St_PosTyp" true true false 5 Text 0 0,First,#,DBO.AddressPoints20230602,St_PosTyp,0,5;St_PosDir "St_PosDir" true true false 5 Text 0 0,First,#,DBO.AddressPoints20230602,St_PosDir,0,5;ZN "ZN" true true false 50 Text 0 0,First,#,DBO.AddressPoints20230602,ZN,0,50;Add_Number "Add_Number" true true false 15 Text 0 0,First,#,DBO.AddressPoints20230602,Add_Number,0,15;HouseInt "HouseInt" true true false 4 Long 0 10,First,#,DBO.AddressPoints20230602,HouseInt,-1,-1;PrimaryAdd "PrimaryAdd" true true false 100 Text 0 0,First,#,DBO.AddressPoints20230602,PrimaryAdd,0,100;AddrLocati "AddrLocati" true true false 2 Text 0 0,First,#,DBO.AddressPoints20230602,AddrLocati,0,2;PrimaryNam "PrimaryNam" true true false 100 Text 0 0,First,#,DBO.AddressPoints20230602,PrimaryNam,0,100;Alias1 "Alias1" true true false 60 Text 0 0,First,#,DBO.AddressPoints20230602,Alias1,0,60;Alias2 "Alias2" true true false 60 Text 0 0,First,#,DBO.AddressPoints20230602,Alias2,0,60;Alias3 "Alias3" true true false 60 Text 0 0,First,#,DBO.AddressPoints20230602,Alias3,0,60;Alias4 "Alias4" true true false 60 Text 0 0,First,#,DBO.AddressPoints20230602,Alias4,0,60;Alias5 "Alias5" true true false 60 Text 0 0,First,#,DBO.AddressPoints20230602,Alias5,0,60;Unit "Unit" true true false 40 Text 0 0,First,#,DBO.AddressPoints20230602,Unit,0,40;County "County" true true false 154 Text 0 0,First,#,DBO.AddressPoints20230602,County,0,154;MailingCit "MailingCit" true true false 254 Text 0 0,First,#,DBO.AddressPoints20230602,MailingCit,0,254;T_MailingC "T_MailingC" true true false 254 Text 0 0,First,#,DBO.AddressPoints20230602,T_MailingC,0,254;Country "Country" true true false 2 Text 0 0,First,#,DBO.AddressPoints20230602,Country,0,2;State "State" true true false 2 Text 0 0,First,#,DBO.AddressPoints20230602,State,0,2;Inc_Muni "Inc_Muni" true true false 50 Text 0 0,First,#,DBO.AddressPoints20230602,Inc_Muni,0,50;DateUpdate "DateUpdate" true true false 8 Date 0 0,First,#,DBO.AddressPoints20230602,DateUpdate,-1,-1;SchoolName "SchoolName" true true false 90 Text 0 0,First,#,ProposedBoundaries,SchoolName,0,90;SchoolNumb "SchoolNumb" true true false 4 Text 0 0,First,#,ProposedBoundaries,SchoolNumb,0,4;Shape_Leng "Shape_Leng" true true false 0 Double 0 0,First,#,ProposedBoundaries,Shape_Leng,-1,-1;Shape__Area "Shape__Area" false true true 0 Double 0 0,First,#,ProposedBoundaries,Shape__Area,-1,-1;Shape__Length "Shape__Length" false true true 0 Double 0 0,First,#,ProposedBoundaries,Shape__Length,-1,-1',
match_option="INTERSECT",
search_radius=None,
distance_field_name=""
)

Thanks to anyone who can provide some insight into my endeavor and can hopefully provide insight and learning on how to make this better.

0 Kudos
0 Replies