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