1

I have a shapefile of drone flight footprints that I am trying to merge an excel tracker/log file to. The shapefile and Excel file will change each time I run the script so I am trying to store the names of both in two separate variables.

First I bring in the shapefile. Then I bring in the .xslx Excel file. Next I convert the Excel file to a table (.gdb), then I attempt to join based on a common field.

However I get the following error and a failed join:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.8\ArcPy\arcpy\management.py", line 6587, in JoinField
    raise e
RuntimeError: Object: Error in executing tool

Here is my code:

#STEP 1 SETUP DIRS

root = r"C:\users\[USERNAME]\Desktop\ORTHO_FOOTPRINT_AUTOMATION" #change the filepath here
    inputs = root + r"\INPUT_CSVS" #input directory of geotag CSVs
    steps = root + r"\STEPS" #location of temporary file storage of intermediate processing steps
    rfoots = root + r"\STEPS\rasterfootprints" #subfolder in steps to store the 100's of rasterized individual photo footprints
    outputs = root + r"\OUTPUT_SHAPEFILES" #location of final

 ### STEP 23: MERGE INDIVIDUAL SHAPEFILES INTO  MULTIPART SINGLE SHAPEFILE
    arcpy.env.workspace = outputs
    arcpy.env.overwriteOutput = True
    shplist = arcpy.ListFiles("*_footprint.shp")
    arcpy.Merge_management(shplist,"ImAc_"+ CampaignNum +"_Usable_Footprints_Merged.shp")
    
    # STEP 24: JOIN TRACKER TO MERGED SHAPEFILE
    arcpy.env.workspace = outputs
    arcpy.env.overwriteOutput = True
    in_file = arcpy.ListFiles("*_Merged.shp")
    in_table = arcpy.ExcelToTable_conversion(Tracker,"Tracker.gdb")
    arcpy.JoinField_management(in_file,"FLIGHTNAME",in_table,"Flight_Pla")

And here are the files in question. https://drive.google.com/drive/folders/1ue1fWwAd90EhaBRtxPPoaUXCj4gtsBmv?usp=sharing

What am I doing wrong?

3
  • What is the full and detailed error message, which will include a line number from your script, when you run the code that you have presented?
    – PolyGeo
    Commented Jun 5, 2021 at 0:51
  • 1
    In_file is a list object not a file path.
    – Hornbydd
    Commented Jun 5, 2021 at 1:01
  • Thanks @Hornbydd. Can you assist with what changes I should apply to the code? (sorry fairly new at Python)
    – BenW
    Commented Jun 6, 2021 at 0:06

1 Answer 1

1

I fixed it by getting a list of the files I want (there will be only one file). Then I concatenate the output filepath with the first item in that list (index position zero). That way like @Hornbydd says it's not a list it's an actual file for the in_file.

arcpy.env.workspace = outputs
arcpy.env.overwriteOutput = True
in_file = arcpy.ListFiles("*_Merged.shp")
in_filepath = outputs + "\\" + (in_file)[0]
in_table = arcpy.ExcelToTable_conversion(Tracker,"Tracker.gdb")
arcpy.JoinField_management(in_filepath,"FLIGHTNAME",in_table,"Flight_Pla")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.