aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/osm/osm.osm.by_tag
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-11-19 21:34:34 +0800
committertypebrook <typebrook@gmail.com>2019-11-19 21:34:34 +0800
commitb2470324e3927c5e505ff206aa6d6fe63f42a191 (patch)
treecb15f921f8e20e3531d30525f1260b4c15e46d5d /scripts/osm/osm.osm.by_tag
parent56c24f398714b9594085eb85be38e90d24b5b49d (diff)
update
Diffstat (limited to 'scripts/osm/osm.osm.by_tag')
-rwxr-xr-xscripts/osm/osm.osm.by_tag45
1 files changed, 45 insertions, 0 deletions
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 @@
1#!/bin/bash
2
3# create new tags from input line, for example:
4# field1 field2 field3 field4 field5 field6 field7 field8...
5# [element type] [element ID] key1_added "value1" key2_added "value2" key3_removed key4_removed...
6
7# key should not quoted, value must be quoted
8# And keys which need to be removed must be placed at the end
9while read -r line
10do
11 TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type
12 ID=$(echo $line | cut -d ' ' -f2) # field2 is ID
13
14 # transform key-value pair into tag format:
15 # <tag k="[key]" v="[value]"/>
16 # keys without values are omitted
17 NEW_TAGS=$(echo $line |\
18 cut -d' ' -f3- |\
19 sed -r 's/([^ "]+) (\"[^"]+\")/<tag k=\"\1\" v=\2\/>/g; s/>[^"]*$/>/')
20
21 # get regex pattern need to removed from original osm element:
22 # key1|key2|key3|key4
23 TAG_PATTERN=$(echo $line |\
24 cut -d' ' -f3- | xargs -n2 echo |\
25 cut -d' ' -f1 | paste -s -d'|')
26
27 echo $NEW_TAGS > /dev/tty
28
29 # print matched element with new tags to .osc file
30 cat $1 |\
31 sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ {
32 /<$TYPE id=\"$ID\"/ {
33 s/(version=\"[0-9]+\")(.*)/\1>/
34 a \ \ \ \ $NEW_TAGS
35 }
36 /<tag k=\"($TAG_PATTERN)\"/ !p
37 /<\/$TYPE/ q
38 }" >> $1.osc
39done
40
41# Add .osc structure for output
42sed -ir '1 i <osmChange version="0.6" generator="bash script">
43 1 i <modify>
44 $ a </modify>
45 $ a </osmChange>' $1.osc