diff options
author | typebrook <typebrook@gmail.com> | 2019-11-17 21:51:17 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-11-17 21:51:17 +0800 |
commit | 83b965342c274aa6672a508c95ce08c0e82403d8 (patch) | |
tree | e98ca07ffbab9d41883314c1c88d0087b41f4c87 /scripts/osm | |
parent | 5ec0a5a61fab514ba2aa2ffd7bdc9dda13f3a274 (diff) |
update
Diffstat (limited to 'scripts/osm')
-rw-r--r-- | scripts/osm/osm | 6 | ||||
-rwxr-xr-x | scripts/osm/osm.osc.create | 42 | ||||
-rw-r--r--[-rwxr-xr-x] | scripts/osm/osm.village.nat_ref.makefile | 28 |
3 files changed, 44 insertions, 32 deletions
diff --git a/scripts/osm/osm b/scripts/osm/osm index 2d32575..f2f08f1 100644 --- a/scripts/osm/osm +++ b/scripts/osm/osm | |||
@@ -1,10 +1,10 @@ | |||
1 | #! /bin/sh | 1 | #! /bin/sh |
2 | 2 | ||
3 | #OSM_SERVER=https://master.apis.dev.openstreetmap.org | 3 | #OSM_SERVER=https://master.apis.dev.openstreetmap.org |
4 | OSM_SERVER=https://api.openstreetmap.org | 4 | export OSM_SERVER=https://api.openstreetmap.org |
5 | 5 | ||
6 | OSM_API=$OSM_SERVER/api/0.6 | 6 | export OSM_API=$OSM_SERVER/api/0.6 |
7 | OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) | 7 | export OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) |
8 | 8 | ||
9 | FILENAME=$0 | 9 | FILENAME=$0 |
10 | 10 | ||
diff --git a/scripts/osm/osm.osc.create b/scripts/osm/osm.osc.create index 61a4dfb..c9bdaa8 100755 --- a/scripts/osm/osm.osc.create +++ b/scripts/osm/osm.osc.create | |||
@@ -1,17 +1,29 @@ | |||
1 | while read -r line | 1 | #!/bin/bash |
2 | do | ||
3 | array=( $(echo $line) ) | ||
4 | 2 | ||
5 | cat $1 |\ | 3 | while read -r line |
6 | sed -nr " | 4 | do |
7 | /<$array[1] id=$array[2]/,/<\/$array[1]/ { | 5 | TYPE=$(echo $line | cut -d ' ' -f1) |
8 | /<$array[1] id=$array[2]/ a \ \ \ \ <tag k=\"$array[3]\" v=$array[4]\/> | 6 | ID=$(echo $line | cut -d ' ' -f2) |
9 | /<tag k=$array[3]/ !p | 7 | NEW_TAGS=$(echo $line |\ |
10 | /<\/$array[1]/ q | 8 | cut -d' ' -f3- | xargs -n2 echo |\ |
11 | }" >> $1.osc | 9 | sed -r 's/^([^ ]+) (.+)/<tag k=\"\1\" v=\"\2\"\/>/' |\ |
12 | done | 10 | paste -s) |
13 | 11 | ||
14 | sed -ir '1 i <osmChange version="0.6" generator="bash script"> | 12 | TAG_PATTERN=$(echo $line |\ |
15 | 1 i <modify> | 13 | cut -d' ' -f3- | xargs -n2 echo |\ |
16 | $ a </modify> | 14 | cut -d' ' -f1 | paste -s -d'|') |
17 | $ a </osmChange>' $1.osc | 15 | |
16 | echo $TAG_PATTERN > /dev/tty | ||
17 | |||
18 | cat $1 |\ | ||
19 | sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ { | ||
20 | /<$TYPE id=\"$ID\"/ a \ \ \ \ $NEW_TAGS | ||
21 | /<tag k=\"($TAG_PATTERN)\"/ !p | ||
22 | /<\/$TYPE/ q | ||
23 | }" >> $1.osc | ||
24 | done | ||
25 | |||
26 | sed -ir '1 i <osmChange version="0.6" generator="bash script"> | ||
27 | 1 i <modify> | ||
28 | $ a </modify> | ||
29 | $ a </osmChange>' $1.osc | ||
diff --git a/scripts/osm/osm.village.nat_ref.makefile b/scripts/osm/osm.village.nat_ref.makefile index f763c19..ffadcf4 100755..100644 --- a/scripts/osm/osm.village.nat_ref.makefile +++ b/scripts/osm/osm.village.nat_ref.makefile | |||
@@ -1,3 +1,5 @@ | |||
1 | SHELL := /bin/bash | ||
2 | |||
1 | data/taiwan-latest.osm.pbf: | 3 | data/taiwan-latest.osm.pbf: |
2 | mkdir -p data | 4 | mkdir -p data |
3 | curl -o $@ http://download.geofabrik.de/asia/taiwan-latest.osm.pbf | 5 | curl -o $@ http://download.geofabrik.de/asia/taiwan-latest.osm.pbf |
@@ -23,7 +25,13 @@ village.no_nat_ref.csv: village.csv | |||
23 | village.with_nat_ref.csv: village.csv | 25 | village.with_nat_ref.csv: village.csv |
24 | (head -1 $<; grep nat_ref $<) |\ | 26 | (head -1 $<; grep nat_ref $<) |\ |
25 | sed -r "s/\"\"\".*nat_ref\"\"=>\"\"([^\"]+).*\"\"\"/\1/g" |\ | 27 | sed -r "s/\"\"\".*nat_ref\"\"=>\"\"([^\"]+).*\"\"\"/\1/g" |\ |
26 | sed '1s/other_tags/nat_ref/'> $@ | 28 | sed '1s/other_tags/nat_ref/;s/"//g' |\ |
29 | (sed -u 1q; sort -t',' -k5)> $@ | ||
30 | |||
31 | village.gov.csv: data/VILLAGE_MOI_1081007.shp | ||
32 | ogr2ogr -f CSV /vsistdout/ $< |\ | ||
33 | (sed -u 1q; sort -t',' -k1) |\ | ||
34 | sed 's/"//g'> $@ | ||
27 | 35 | ||
28 | matched.csv: data/VILLAGE_MOI_1081007.shp village.no_nat_ref.csv | 36 | matched.csv: data/VILLAGE_MOI_1081007.shp village.no_nat_ref.csv |
29 | ogr2ogr $@ $(word 2,$^) \ | 37 | ogr2ogr $@ $(word 2,$^) \ |
@@ -33,18 +41,12 @@ matched.csv: data/VILLAGE_MOI_1081007.shp village.no_nat_ref.csv | |||
33 | FROM 'village.no_nat_ref' osm, '$<'.VILLAGE_MOI_1081007 gov \ | 41 | FROM 'village.no_nat_ref' osm, '$<'.VILLAGE_MOI_1081007 gov \ |
34 | WHERE osm.name = gov.VILLNAME AND Intersects(gov.geometry, osm.geometry)" | 42 | WHERE osm.name = gov.VILLNAME AND Intersects(gov.geometry, osm.geometry)" |
35 | 43 | ||
36 | village.gov.csv: data/VILLAGE_MOI_1081007.shp | 44 | matched.by_nat_ref.list: village.with_nat_ref.csv village.gov.csv |
37 | ogr2ogr $@ $< | 45 | join -t',' -1 5 -2 1 <(sed 1d $<) <(sed 1d $(word 2,$^)) > $@ |
38 | 46 | ||
39 | matched.by_ref.csv: village.gov.csv village.with_nat_ref.csv | 47 | change.county_town_en.list: matched.by_nat_ref.list |
40 | ogr2ogr $@ $(word 2,$^) \ | 48 | awk -F',' -v q=\" '{print $$4, "is_in:county", q$$6q, "is_in:town", q$$7q, "name:en", q$$9q }' $< |\ |
41 | -dialect sqlite \ | 49 | sed 's/^/relation /' > $@ |
42 | -sql "SELECT osm.osm_id, gov.* \ | ||
43 | FROM 'village.with_nat_ref' osm, '$<'.'village.gov' gov \ | ||
44 | WHERE osm.nat_ref = gov.VILLCODE" | ||
45 | |||
46 | diff: matched.by_ref.csv | ||
47 | awk -F',' -v q='"' '{print (, "is_in:county", q{q, "is_in:town", q{})}" q, "name:en", q$6q }' $< | ||
48 | 50 | ||
49 | confilct.list: matched.csv | 51 | confilct.list: matched.csv |
50 | cat $< | cut -d',' -f2 | sort | uniq -d | xargs -I {} grep {} $< | 52 | cat $< | cut -d',' -f2 | sort | uniq -d | xargs -I {} grep {} $< |
@@ -60,5 +62,3 @@ change.list: matched.csv | |||
60 | cat $< |\ | 62 | cat $< |\ |
61 | sed 1d |\ | 63 | sed 1d |\ |
62 | awk -F',' '{print "relation", $$1, "nat_ref", $$2}' > $@ | 64 | awk -F',' '{print "relation", $$1, "nat_ref", $$2}' > $@ |
63 | |||
64 | # sed -i -r 's/([0-9]+ +)(.+)$/\1"name:en" "\2"/' diff.eng | ||