1

I want to run the spatial join tool to join hundreds of shapefiles from two different folders.


For example one folder contains point shapefiles with names d1.1,d1.2,d1.3 . . . .

the other folder contain shapefiles with names q1.1,q1.2,q1.3 . . . .

i want to join d1.1 to q1.1, d1.2 to q1.2 and so on, using python but getting the error:

Traceback (most recent call last):

  File "C:\spatial join.py", line 28, in <module>

    arcpy.SpatialJoin_analysis(tarf, joinf, output, "JOIN_ONE_TO_ONE", 

"KEEP_ALL", "POINTID \"POINTID\" true true false 6 Long 0 6 ,First,#,fc[:-
4],POINTID,-1,-1;AOD \"AOD\" true true false 10 Long 0 10 ,First,#,fc[:-4],GRID_CODE,-1,-1;QF \"QF\" true true false 10 Long 0 10 ,First,#,fs[:-4],GRID_CODE,-1,-1", "INTERSECT", "", "")

  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\analysis.py", line 471, in SpatialJoin
    raise e

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000732: Target Features: Dataset da2016001.0510 does not exist or is not supported

ERROR 000732: Join Features: Dataset qfa2016001.0510 does not exist or is not supported

Failed to execute (SpatialJoin).

Here is my code

import arcpy

arcpy.env.workspace = r"C:\pointsD"

fcsD = arcpy.ListFeatureClasses()

arcpy.env.workspace = r"C:\pointsQF"

fcsQF = arcpy.ListFeatureClasses()

for fc in fcsD:

    for fs in fcsQF:

        if fs[3:]== fc[2:]:

            tarf = fc[:-4]

            joinf = fs[:-4]

            output = r"C:\DWithQF" + fc[1:-4]

            # Process: Spatial Join

            arcpy.SpatialJoin_analysis(tarf, joinf, output, "JOIN_ONE_TO_ONE", 
"KEEP_ALL", "POINTID \"POINTID\" true true false 6 Long 0 6 ,First,#,fc[:-4],POINTID,-1,-1;AOD \"AOD\" true true false 10 Long 0 10 ,First,#,fc[:-4],GRID_CODE,-1,-1;QF \"QF\" true true false 10 Long 0 10 ,First,#,fs[:-4],GRID_CODE,-1,-1", "INTERSECT", "", "")

print "Done"
  • 1
    You probably need to add the Path "C:\pointsD" to tarf variable because your Workspace is still set to the QF workspace. – klewis Dec 5 '16 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.