I am trying to generate a script that executes a Spatial Join between specific shapefiles. However the only values that are added to the result feature are the first and last in the list of shapefiles to join. I have tried different approaches, however the result is always the same.
Spatial join for multiple shapefiles (loop) exposes the same problem, however I have not been able to identify the way it was solved.
This is the code:
# Shapefiles to join
selfc = ['tertiary_roads_CO_m_nonoise.shp',
'tertiary_roads_NOX_m_nonoise.shp',
'tertiary_roads_PM10_nonoise.shp',
'tertiary_roads_PM25_nonoise.shp',
'tertiary_roads_SO2_nonoise.shp']
# Define target feature as the first element in the selfc list
targetFeature = selfc[0]
joinFeatures = selfc[1:]
outfc = os.path.join(outdir, "testSpatialJoin")
for feature in joinFeatures:
#Run the Spatial Join tool
arcpy.SpatialJoin_analysis(targetFeature, feature, outfc, "JOIN_ONE_TO_MANY", "KEEP_ALL")
Result: Just the last Shapefile in the selfc
list is joined to the Target Feature.