From b2470324e3927c5e505ff206aa6d6fe63f42a191 Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 19 Nov 2019 21:34:34 +0800 Subject: update --- scripts/osm/osm.osc.by_member | 31 ++++++++++++++++++++++ scripts/osm/osm.osc.create | 45 -------------------------------- scripts/osm/osm.osm.by_tag | 45 ++++++++++++++++++++++++++++++++ scripts/osm/osm.village.nat_ref.makefile | 7 +++++ 4 files changed, 83 insertions(+), 45 deletions(-) create mode 100755 scripts/osm/osm.osc.by_member delete mode 100755 scripts/osm/osm.osc.create create mode 100755 scripts/osm/osm.osm.by_tag (limited to 'scripts/osm') diff --git a/scripts/osm/osm.osc.by_member b/scripts/osm/osm.osc.by_member new file mode 100755 index 0000000..5f9d9be --- /dev/null +++ b/scripts/osm/osm.osc.by_member @@ -0,0 +1,31 @@ +#!/bin/bash + +while read -r line +do + + TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type + ID=$(echo $line | cut -d ' ' -f2) # field2 is ID + + NEW_MEMBERS=$(echo $line |\ + cut -d' ' -f3- |\ + sed -r 's/([0-9]+)//g') + + echo $NEW_MEMBERS + + # print matched element with new tags to .osc file + cat $1 |\ + sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ { + /<$TYPE id=\"$ID\"/ { + s/(version=\"[0-9]+\")(.*)/\1>/ + a \ \ \ \ $NEW_MEMBERS + } + p + /<\/$TYPE/ q + }" >> $1.osc +done + +# Add .osc structure for output +sed -ir '1 i + 1 i + $ a + $ a ' $1.osc diff --git a/scripts/osm/osm.osc.create b/scripts/osm/osm.osc.create deleted file mode 100755 index cc92c1d..0000000 --- a/scripts/osm/osm.osc.create +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# create new tags from input line, for example: -# field1 field2 field3 field4 field5 field6 field7 field8... -# [element type] [element ID] key1_added "value1" key2_added "value2" key3_removed key4_removed... - -# key should not quoted, value must be quoted -# And keys which need to be removed must be placed at the end -while read -r line -do - TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type - ID=$(echo $line | cut -d ' ' -f2) # field2 is ID - - # transform key-value pair into tag format: - # - # keys without values are omitted - NEW_TAGS=$(echo $line |\ - cut -d' ' -f3- |\ - sed -r 's/([^ "]+) (\"[^"]+\")//g; s/>[^"]*$/>/') - - # get regex pattern need to removed from original osm element: - # key1|key2|key3|key4 - TAG_PATTERN=$(echo $line |\ - cut -d' ' -f3- | xargs -n2 echo |\ - cut -d' ' -f1 | paste -s -d'|') - - echo $NEW_TAGS > /dev/tty - - # print matched element with new tags to .osc file - cat $1 |\ - sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ { - /<$TYPE id=\"$ID\"/ { - s/(version=\"[0-9]+\")(.*)/\1>/ - a \ \ \ \ $NEW_TAGS - } - /> $1.osc -done - -# Add .osc structure for output -sed -ir '1 i - 1 i - $ a - $ a ' $1.osc diff --git a/scripts/osm/osm.osm.by_tag b/scripts/osm/osm.osm.by_tag new file mode 100755 index 0000000..cc92c1d --- /dev/null +++ b/scripts/osm/osm.osm.by_tag @@ -0,0 +1,45 @@ +#!/bin/bash + +# create new tags from input line, for example: +# field1 field2 field3 field4 field5 field6 field7 field8... +# [element type] [element ID] key1_added "value1" key2_added "value2" key3_removed key4_removed... + +# key should not quoted, value must be quoted +# And keys which need to be removed must be placed at the end +while read -r line +do + TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type + ID=$(echo $line | cut -d ' ' -f2) # field2 is ID + + # transform key-value pair into tag format: + # + # keys without values are omitted + NEW_TAGS=$(echo $line |\ + cut -d' ' -f3- |\ + sed -r 's/([^ "]+) (\"[^"]+\")//g; s/>[^"]*$/>/') + + # get regex pattern need to removed from original osm element: + # key1|key2|key3|key4 + TAG_PATTERN=$(echo $line |\ + cut -d' ' -f3- | xargs -n2 echo |\ + cut -d' ' -f1 | paste -s -d'|') + + echo $NEW_TAGS > /dev/tty + + # print matched element with new tags to .osc file + cat $1 |\ + sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ { + /<$TYPE id=\"$ID\"/ { + s/(version=\"[0-9]+\")(.*)/\1>/ + a \ \ \ \ $NEW_TAGS + } + /> $1.osc +done + +# Add .osc structure for output +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 index cfaf92a..a051ee4 100644 --- a/scripts/osm/osm.village.nat_ref.makefile +++ b/scripts/osm/osm.village.nat_ref.makefile @@ -19,6 +19,13 @@ village.csv: data/taiwan-latest.osm.pbf FROM multipolygons \ WHERE admin_level = '9'" +town.csv: data/taiwan-latest.osm.pbf + ogr2ogr $@ $< \ + -dialect sqlite \ + -sql "SELECT osm_id, name, other_tags \ + FROM multipolygons \ + WHERE admin_level = '5' OR admin_level = '7' OR admin_level = '8'" + village.no_nat_ref.csv: village.csv grep -v nat_ref $< > $@ -- cgit v1.2.3-70-g09d2