aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/osm/osm.osc.create
blob: 93a6640b3daeff98b20faad25d511fdbf612bd4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

# create new tags from input line, for example: 
# [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)
    ID=$(echo $line | cut -d ' ' -f2)

    NEW_TAGS=$(echo $line |\
               cut -d' ' -f3- |\
               sed -r 's/([^ "]+) (\"[^"]+\")/<tag k=\"\1\" v=\2\/>/g; s/>[^"]*$/>/')

    TAG_PATTERN=$(echo $line |\
                  cut -d' ' -f3- | xargs -n2 echo |\
                  cut -d' ' -f1 | paste -s -d'|')

    echo $NEW_TAGS > /dev/tty

    cat $1 |\
    sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ {
                 /<$TYPE id=\"$ID\"/ {
                     s/(version=\"[0-9]+\")(.*)/\1>/
                     a \ \ \ \ $NEW_TAGS
                 }
                 /<tag k=\"($TAG_PATTERN)\"/ !p
                 /<\/$TYPE/ q
            }" >> $1.osc
done

sed -ir '1 i <osmChange version="0.6" generator="bash script">
         1 i <modify>
         $ a </modify>
         $ a </osmChange>' $1.osc