-
Notifications
You must be signed in to change notification settings - Fork 20
/
gpx-to-shp.sh
executable file
·59 lines (49 loc) · 1.47 KB
/
gpx-to-shp.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# this script will clean up gpx data for rendering in illustrator with mapublisher.
# separate gpx data into one shapefile for lines, a shapefile for waypoints, and a shapefile for track points,
# and project data to a desired CRS
# ************************************************************************************************************
#!/bin/bash
# script variables assigned as follows:
OUTDR='/Users/chrislhenrick/Cartography/projects/rHenrick/mike_pct_map/data/shp_gps_waypoint_data' # ouput directory here
TSRS='EPSG:4326' # target CRS EPSG code here
PRJ=`echo $TSRS | sed s/\"//g | cut -f2 -d ':'` # variable values for sed here:
# extract tracks and rename file
for FILE in *.gpx
do
echo "converting $FILE file's tracks..."
FILENEW=`echo $FILE | sed "s/.gpx/_tracks_$PRJ.shp/"`
ogr2ogr \
-f "ESRI Shapefile" \
-t_srs $TSRS \
$FILENEW $FILE \
tracks
done
# extract waypoints and rename file
for FILE in *.gpx
do
echo "converting $FILE file's waypoints..."
FILENEW=`echo $FILE | sed "s/.gpx/_waypoints_$PRJ.shp/"`
ogr2ogr \
-f "ESRI Shapefile" \
-t_srs $TSRS \
$FILENEW $FILE \
waypoints
done
# extract track points and rename file
for FILE in *.gpx
do
echo "converting $FILE file's waypoints..."
FILENEW=`echo $FILE | sed "s/.gpx/_track-points_$PRJ.shp/"`
ogr2ogr \
-f "ESRI Shapefile" \
-t_srs $TSRS \
$FILENEW $FILE \
track_points
done
# move files into an output directory
for FILE in *$PRJ*
do
echo "moving $FILE to $OUTDR..."
mv $FILE $OUTDR
done
exit