From 87c68a91b15a704159e39f3c9c54c2bbe7d8e369 Mon Sep 17 00:00:00 2001 From: jclarke100 Date: Mon, 19 Jan 2015 16:23:45 +0000 Subject: [PATCH] Added parameters Added parameters --- ImportGPX.py | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/ImportGPX.py b/ImportGPX.py index edb9936..3b42767 100644 --- a/ImportGPX.py +++ b/ImportGPX.py @@ -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 @@ -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