Search code examples
pythonarcgisarcpygpx

Using arcpy.gpxtofeature to convert gpx files en mass


I am trying to convert 10,700 GPX files to features to use in ArcGIS. I am trying to use ArcGIS's arcpy package and the new gpxtofeature tool. The input is a folder full of GPX files and the output points to a geodatabase to hold each new file (I have changed the paths for this question). Once I manage to successfully complete this conversion, I plan on merging all of the features into one huge feature. However, I am having issues with the conversion tool in the code. The latest error is "000354 : The name contains invalid characters" the last error said that I had invalid parameters for the tool. I have added arcpy.AddMessage() to see if the code is even reading the files and able to concatenate the names of the new features, which it successfully returns the first file (path\name\19465409.gpx and GDB\path\name\19465409.shp). So I am a little confused as to why I am receiving these errors and why the gpxtofeature tool will not work. Do you have any ideas? Here is my code:

import arcpy
from os.path import isfile, join
from arcpy import env
arcpy.env.overwriteOutput = True
gpxFolder = r'\\this\is\the\input\folder'
outputGdb = r'\\this\is\the\output\GDB\GPX2FeaturesOutput.gdb'
env.workspace =gpxFolder

def convertGPX2feature(gpxFolder, outputGdb): 

    for file in arcpy.ListFiles("*.gpx"):

        # Convert files from .gpx to feature layer
        inGPX = gpxFolder + "\\" + file
        arcpy.AddMessage(inGPX)
        featureName = file.partition(".gpx")[0]
        outfile = outputGdb + "\\" + featureName + ".shp"
        arcpy.AddMessage(outfile)
        arcpy.GPXtoFeatures_conversion(inGPX,outfile)

if __name__ == "__main__":
    convertGPX2feature(gpxFolder, outputGdb) 

Solution

  • Try using a filename for the shapefile that does not start with a number