-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImportGPX.py
More file actions
43 lines (31 loc) · 1.34 KB
/
ImportGPX.py
File metadata and controls
43 lines (31 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Script to import all GPX tracks from a folder into a line feature class
in a file geodatabase. New line feature for each GPX file.
Generate linear density map of those lines to show where most tracks go.
Paths hardcoded in script so needs changed first before running it.
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()
for f in os.listdir(gpxFolder):
print "Processing file %s" % f
print "\tconvert to points in_mem"
arcpy.GPXtoFeatures_conversion(gpxFolder + "\\" + f, "in_memory\\track")
print "\tconvert in_memory points to lines"
arcpy.PointsToLine_management("in_memory\\track", "in_memory\\track_line")
print "\tadd the new in_mem line to target feature class"
arcpy.Append_management("in_memory\\track_line", target, "NO_TEST")
# Line density stuff todo - needs Spatial Analyst
# lineDensity = LineDensity(target, "", 10, 20)
if __name__ == '__main__':
main()