diff options
| author | typebrook <typebrook@gmail.com> | 2019-11-17 09:18:07 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2019-11-17 09:18:07 +0800 |
| commit | 1d3508f66fddf3f8c6416e59ab9fbde405dbcf25 (patch) | |
| tree | 4f703dfa01596c133a4898c88fe837b8971e47e1 /scripts/osm/osm.village.nat_ref.makefile | |
| parent | e0673805fc648d47eadf5c76b822ccef5780d241 (diff) | |
update
Diffstat (limited to 'scripts/osm/osm.village.nat_ref.makefile')
| -rw-r--r-- | scripts/osm/osm.village.nat_ref.makefile | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/osm/osm.village.nat_ref.makefile b/scripts/osm/osm.village.nat_ref.makefile new file mode 100644 index 0000000..3937144 --- /dev/null +++ b/scripts/osm/osm.village.nat_ref.makefile | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | data/taiwan-latest.osm.pbf: | ||
| 2 | mkdir -p data | ||
| 3 | curl -o $@ http://download.geofabrik.de/asia/taiwan-latest.osm.pbf | ||
| 4 | |||
| 5 | data/village.zip: | ||
| 6 | mkdir -p data | ||
| 7 | curl -o $@ -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE | ||
| 8 | |||
| 9 | data/VILLAGE_MOI_1081007.shp: data/village.zip | ||
| 10 | @if [ ! -e $@ ]; then unzip $< -d data && rm data/*xml data/*xlsx; fi | ||
| 11 | |||
| 12 | village.csv: data/taiwan-latest.osm.pbf | ||
| 13 | ogr2ogr $@ $< \ | ||
| 14 | -lco GEOMETRY=AS_XY \ | ||
| 15 | -dialect sqlite \ | ||
| 16 | -sql "SELECT osm_id, name, other_tags, ST_PointOnSurface(geometry) \ | ||
| 17 | FROM multipolygons \ | ||
| 18 | WHERE admin_level = '9'" | ||
| 19 | |||
| 20 | village.no_nat_ref.csv: village.csv | ||
| 21 | grep -v nat_ref $< > $@ | ||
| 22 | |||
| 23 | village.with_nat_ref.csv: village.csv | ||
| 24 | (head -1 $<; grep nat_ref $<) |\ | ||
| 25 | sed -r "s/\"\"\".*nat_ref\"\"=>\"\"([^\"]+).*\"\"\"/\1/g" |\ | ||
| 26 | sed '1s/other_tags/nat_ref/'> $@ | ||
| 27 | |||
| 28 | matched.csv: data/VILLAGE_MOI_1081007.shp village.no_nat_ref.csv | ||
| 29 | ogr2ogr $@ $(word 2,$^) \ | ||
| 30 | -oo X_POSSIBLE_NAMES=X -oo Y_POSSIBLE_NAMES=Y \ | ||
| 31 | -dialect sqlite \ | ||
| 32 | -sql "SELECT osm.osm_id, gov.* \ | ||
| 33 | FROM 'village.no_nat_ref' osm, '$<'.VILLAGE_MOI_1081007 gov \ | ||
| 34 | WHERE osm.name = gov.VILLNAME AND Intersects(gov.geometry, osm.geometry)" | ||
| 35 | |||
| 36 | matched.by_ref.csv: data/VILLAGE_MOI_1081007.shp village.with_nat_ref.csv | ||
| 37 | ogr2ogr $@ $(word 2,$^) \ | ||
| 38 | -oo X_POSSIBLE_NAMES=X -oo Y_POSSIBLE_NAMES=Y \ | ||
| 39 | -dialect sqlite \ | ||
| 40 | -sql "SELECT osm.osm_id, gov.* \ | ||
| 41 | FROM 'village.with_nat_ref' osm, '$<'.VILLAGE_MOI_1081007 gov \ | ||
| 42 | WHERE osm.nat_ref = gov.VILLCODE" | ||
| 43 | |||
| 44 | confilct.list: matched.csv | ||
| 45 | cat $< | cut -d',' -f2 | sort | uniq -d | xargs -I {} grep {} $< | ||
| 46 | |||
| 47 | origin.osm: matched.csv data/taiwan-latest.osm.pbf | ||
| 48 | cat $< |\ | ||
| 49 | sed 1d |\ | ||
| 50 | cut -d'"' -f2 |\ | ||
| 51 | sed -nr 's/.*/r\0/p' |\ | ||
| 52 | osmium getid $(word 2,$^) --id-file - --output-format=osm > $@ | ||
| 53 | |||
| 54 | change.list: matched.csv | ||
| 55 | cat $< |\ | ||
| 56 | sed 1d |\ | ||
| 57 | awk -F',' '{print "relation", $$1, "nat_ref", $$2}' > $@ | ||
| 58 | |||
| 59 | # sed -i -r 's/([0-9]+ +)(.+)$/\1"name:en" "\2"/' diff.eng | ||