-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.sh
executable file
·129 lines (95 loc) · 3.75 KB
/
convert.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Install npm using
sudo apt-get install zip
sudo apt-get install npm nodejs-legacy
sudo npm install -g osmtogeojson
sudo npm install -g @mapbox/geojson-merge
sudo npm install -g topojson
sudo npm install -g ndjson-cli
#sudo npm install -g d3
#sudo npm install -g d3-geo-projection
sudo apt-get install jq
# Osmosis also needed, as per https://wiki.openstreetmap.org/wiki/Osmosis/Installation#Linux (not reproduced here)
# Bomb out if something goes wrong
set -e
# Unzip original data
unzip dft-england-cycling-data-2011.zip
rm -rf zip/
mv done zip
# Unzip zip files
rm -rf osm/
mkdir osm/
cd zip/
for zipfile in *.zip ; do
unzip $zipfile
osmfile="${zipfile/.zip/.osm}"
if [ "${zipfile}" == "SuperLondonBorough1-201202201611.zip" ]; then
mv LondonSuperBorough1-201202201611.osm $osmfile
fi
mv "${osmfile}" ../osm/
done
cd ../
# Create a merged .osm file using osmosis --rx file1.osm --rx file2.osm --m --wx merged.osm ; see: https://lists.openstreetmap.org/pipermail/osmosis-dev/2013-October/001619.html
#cd osm/
#ls -lAF
#mergeCommand="osmosis"
#for osmfile in *.osm ; do
# mergeCommand+=" --rx '${osmfile}'" # --sort
#done
#echo $mergeCommand
#i=0
#for osmfile in *.osm ; do
# if [ $i -gt 0 ]; then
# mergeCommand+=" --merge"
# fi
# (( i = i + 1 ))
#done
#mergeCommand+=" --wx ../dft-england-cycling-data-2011.osm"
#echo "${mergeCommand}"
#eval "${mergeCommand}"
#cd ../
# https://help.openstreetmap.org/questions/18255/softwarelibraries-to-convert-osm-data-to-geojson-without-using-api
# osmtogeojson in.osm > out.geojson
rm -rf geojson/
mkdir geojson/
cd osm/
for osmfile in *.osm ; do
echo "Converting ${osmfile}"
osmtogeojson $osmfile > "../geojson/${osmfile/.osm/.geojson}"
done
cd ../
# List file counts
ls -lAF zip/ | wc -l
ls -lAF osm/ | wc -l
ls -lAF geojson/ | wc -l
# Merge
geojson-merge geojson/*.geojson > combined.geojson
# Filter unwanted features using sed
# Not ideal, as retains commas at end of list
#less combined.geojson | sed -r '/"(timestamp|version|ccg_date)":/d' | sed -r '/ "id":/d' | sed -e 's/ccg_//' | cat > dft-england-cycling-data-2011.geojson.geojson
# Filter unwanted features using ndjson-cat; see: https://github.com/mbostock/ndjson-cli and https://medium.com/@mbostock/command-line-cartography-part-2-c3a82c5c0f3
# Reformat file to newline-delimited JSON; see: http://www.roblabs.com/ndjson/
ndjson-cat combined.geojson | ndjson-split 'd.features' > combined.ndjson
# Filter unwanted properties file
ndjson-filter 'delete d.properties.version, true' < combined.ndjson | ndjson-filter 'delete d.properties.timestamp, true' | ndjson-filter 'delete d.properties.id, true' | ndjson-filter 'delete d.properties.ccg_date, true' > filtered.ndjson
sed -i -e 's/ccg_//g' filtered.ndjson
# Convert back to GeoJSON
ndjson-reduce < filtered.ndjson | ndjson-map '{type: "FeatureCollection", features: d}' > dft-england-cycling-data-2011.geojson
#sed '1s/^/{"type": "FeatureCollection", "features": [/\n' filtered.ndjson > filtered.geojson
#echo ']}' >> filtered.geojson
#mv filtered.geojson dft-england-cycling-data-2011.geojson
# Make a gzipped version for quicker downloading
gzip -k dft-england-cycling-data-2011_formatted.geojson
# Make formatted version of the GeoJSON
jq . dft-england-cycling-data-2011.geojson | cat > dft-england-cycling-data-2011_formatted.geojson
gzip dft-england-cycling-data-2011_formatted.geojson
# Convert to Shapefile
#!# TODO
# Render to SVG using d3; see: https://medium.com/@mbostock/command-line-cartography-part-2-c3a82c5c0f3
#geo2svg -n --stroke none -p 1 -w 960 -h 960 < combined.ndjson > dft-england-cycling-data-2011.svg
# Clean up temporary files
rm combined.geojson
rm combined.ndjson
rm filtered.ndjson
# Add readme
echo "Documentation at: https://wiki.openstreetmap.org/wiki/England_Cycling_Data_project"