From 83b965342c274aa6672a508c95ce08c0e82403d8 Mon Sep 17 00:00:00 2001 From: typebrook Date: Sun, 17 Nov 2019 21:51:17 +0800 Subject: update --- scripts/osm/osm | 6 ++--- scripts/osm/osm.osc.create | 42 ++++++++++++++++++++------------ scripts/osm/osm.village.nat_ref.makefile | 28 ++++++++++----------- 3 files changed, 44 insertions(+), 32 deletions(-) mode change 100755 => 100644 scripts/osm/osm.village.nat_ref.makefile (limited to 'scripts/osm') 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 @@ #! /bin/sh #OSM_SERVER=https://master.apis.dev.openstreetmap.org -OSM_SERVER=https://api.openstreetmap.org +export OSM_SERVER=https://api.openstreetmap.org -OSM_API=$OSM_SERVER/api/0.6 -OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) +export OSM_API=$OSM_SERVER/api/0.6 +export OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) FILENAME=$0 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 @@ - while read -r line - do - array=( $(echo $line) ) +#!/bin/bash - cat $1 |\ - sed -nr " - /<$array[1] id=$array[2]/,/<\/$array[1]/ { - /<$array[1] id=$array[2]/ a \ \ \ \ - /> $1.osc - done +while read -r line +do + TYPE=$(echo $line | cut -d ' ' -f1) + ID=$(echo $line | cut -d ' ' -f2) + NEW_TAGS=$(echo $line |\ + cut -d' ' -f3- | xargs -n2 echo |\ + sed -r 's/^([^ ]+) (.+)//' |\ + paste -s) - sed -ir '1 i - 1 i - $ a - $ a ' $1.osc + TAG_PATTERN=$(echo $line |\ + cut -d' ' -f3- | xargs -n2 echo |\ + cut -d' ' -f1 | paste -s -d'|') + + echo $TAG_PATTERN > /dev/tty + + cat $1 |\ + sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ { + /<$TYPE id=\"$ID\"/ a \ \ \ \ $NEW_TAGS + /> $1.osc +done + +sed -ir '1 i + 1 i + $ a + $ a ' $1.osc diff --git a/scripts/osm/osm.village.nat_ref.makefile b/scripts/osm/osm.village.nat_ref.makefile old mode 100755 new mode 100644 index f763c19..ffadcf4 --- a/scripts/osm/osm.village.nat_ref.makefile +++ b/scripts/osm/osm.village.nat_ref.makefile @@ -1,3 +1,5 @@ +SHELL := /bin/bash + data/taiwan-latest.osm.pbf: mkdir -p data curl -o $@ http://download.geofabrik.de/asia/taiwan-latest.osm.pbf @@ -23,7 +25,13 @@ village.no_nat_ref.csv: village.csv village.with_nat_ref.csv: village.csv (head -1 $<; grep nat_ref $<) |\ sed -r "s/\"\"\".*nat_ref\"\"=>\"\"([^\"]+).*\"\"\"/\1/g" |\ - sed '1s/other_tags/nat_ref/'> $@ + sed '1s/other_tags/nat_ref/;s/"//g' |\ + (sed -u 1q; sort -t',' -k5)> $@ + +village.gov.csv: data/VILLAGE_MOI_1081007.shp + ogr2ogr -f CSV /vsistdout/ $< |\ + (sed -u 1q; sort -t',' -k1) |\ + sed 's/"//g'> $@ matched.csv: data/VILLAGE_MOI_1081007.shp village.no_nat_ref.csv ogr2ogr $@ $(word 2,$^) \ @@ -33,18 +41,12 @@ matched.csv: data/VILLAGE_MOI_1081007.shp village.no_nat_ref.csv FROM 'village.no_nat_ref' osm, '$<'.VILLAGE_MOI_1081007 gov \ WHERE osm.name = gov.VILLNAME AND Intersects(gov.geometry, osm.geometry)" -village.gov.csv: data/VILLAGE_MOI_1081007.shp - ogr2ogr $@ $< +matched.by_nat_ref.list: village.with_nat_ref.csv village.gov.csv + join -t',' -1 5 -2 1 <(sed 1d $<) <(sed 1d $(word 2,$^)) > $@ -matched.by_ref.csv: village.gov.csv village.with_nat_ref.csv - ogr2ogr $@ $(word 2,$^) \ - -dialect sqlite \ - -sql "SELECT osm.osm_id, gov.* \ - FROM 'village.with_nat_ref' osm, '$<'.'village.gov' gov \ - WHERE osm.nat_ref = gov.VILLCODE" - -diff: matched.by_ref.csv - awk -F',' -v q='"' '{print (, "is_in:county", q{q, "is_in:town", q{})}" q, "name:en", q$6q }' $< +change.county_town_en.list: matched.by_nat_ref.list + awk -F',' -v q=\" '{print $$4, "is_in:county", q$$6q, "is_in:town", q$$7q, "name:en", q$$9q }' $< |\ + sed 's/^/relation /' > $@ confilct.list: matched.csv cat $< | cut -d',' -f2 | sort | uniq -d | xargs -I {} grep {} $< @@ -60,5 +62,3 @@ change.list: matched.csv cat $< |\ sed 1d |\ awk -F',' '{print "relation", $$1, "nat_ref", $$2}' > $@ - -# sed -i -r 's/([0-9]+ +)(.+)$/\1"name:en" "\2"/' diff.eng -- cgit v1.2.3-70-g09d2