Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions ImportGPX.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,44 @@

Generate linear density map of those lines to show where most tracks go.

Paths hardcoded in script so needs changed first before running it.
Parameters:
1 - Path to source folder of GPX files
2 - Target feature class to which data is appended
3 - Option to truncate target feature class before data load

TODO:
Could do with some error handling, create FGDB if it doesn't exist etc
Also doesn't carry any attributes through from GPX, date/time would be good
"""

import sys, arcpy, os
## TODO Jim - PARAM
gpxFolder = r"c:\stuff\python\gpx"
target = r"c:\stuff\python\GPS.gdb\Tracks_1"

def main():

print "Truncating %s..." % target
try:
arcpy.TruncateTable_management(target)
except:
print "Target not found or can't truncate"
sys.exit()
print "Script started"

gpxFolder = sys.argv[1]
target = sys.argv[2]
doTruncate = sys.argv[3]
##gpxFolder = r"c:\stuff\python\gpx"
##target = r"c:\stuff\python\GPS.gdb\Tracks_1"
##doTruncate = False

if not os.path.isdir(gpxFolder):
print "No source folder found: " + gpxFolder
sys.exit(1)

if not arcpy.Exists(target):
print "No target found: " + target
sys.exit(1)

if doTruncate:
try:
print "Truncating %s..." % target
arcpy.TruncateTable_management(target)
except:
print "Target not found or can't truncate"
sys.exit()

for f in os.listdir(gpxFolder):
print "Processing file %s" % f
Expand All @@ -34,6 +53,8 @@ def main():
arcpy.PointsToLine_management("in_memory\\track", "in_memory\\track_line")

print "\tadd the new in_mem line to target feature class"
arcpy.AddMessage(f)
print("\t" + f)
arcpy.Append_management("in_memory\\track_line", target, "NO_TEST")

# Line density stuff todo - needs Spatial Analyst
Expand Down