-
Notifications
You must be signed in to change notification settings - Fork 20
/
separate-roads-by-type.sh
executable file
·108 lines (88 loc) · 2.94 KB
/
separate-roads-by-type.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# separate a roads shapefile layer into multiple layers using ogr2ogr -sql
# takes a roads.shp file extracted using: http://extract.bbbike.org/#
# processes into multiple road shapefiles based on the OSM 'type' attributes
# *****************************************************************************
#!/bin/bash
# assign variable values for OGR parameters here:
ROADS='roads.shp' # the name of your OSM roads layer file, must have a type field name and be named roads.shp
TSRS='EPSG:2227' # the EPSG code you want your data projected to
PRJ=`echo $TSRS | sed s/\"//g | cut -f2 -d ':'` # takes the numbers of your EPSG code and appends to the output file name
# set path for output files here
DIR_OUT='/Users/chrislhenrick/Cartography/projects/eHeinze/henry-cowell-sp/data/roads/processed/'
# queries out motorways
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_motorways_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type in ('motorway', 'trunk')" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# queries out motorway links (off ramps and connectors)
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_motorway-links_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type in ('motorway_link', 'trunk_link')" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# queries out main roads (primary, secondary, tertiary)
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_main-rd_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type in ('primary','secondary','tertiary')" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# queries out primary links (usually not many of these)
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_main-rd-links_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type in ('primary_link','secondary_link','tertiary_link')" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# queries out residential and other smaller roads
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_other-rd_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type in ('residential', 'service', 'living_street', 'unclassified')" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# queries out dirt roads
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_dirt-rd_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type = 'track'" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# queries out paths, trails, cycling paths, etc.
for FILE in $ROADS
do
echo "processing $FILE file..."
FILENEW=`echo $FILE | sed "s/.shp/_trails_$PRJ.shp/"`
ogr2ogr \
-sql "select * from roads where type in ('bridleway', 'cycleway', 'footway', 'path', 'pedestrian', 'steps')" \
-t_srs $TSRS \
$FILENEW $FILE\
done
# move output files to a desired location (separate from original data)
for FILE in *_$PRJ.*
do
echo "moving $FILE file..."
mv $FILE $DIR_OUT
done
exit