aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--utils/osm.utils.sh49
1 files changed, 43 insertions, 6 deletions
diff --git a/utils/osm.utils.sh b/utils/osm.utils.sh
index 3eed4be..56f31d0 100644
--- a/utils/osm.utils.sh
+++ b/utils/osm.utils.sh
@@ -1,5 +1,28 @@
1FILENAME=$0 1FILENAME=$0
2 2
3osm.help() {
4 echo "
5COMMANDS:
6 osm.utils.edit
7 osm.get
8 osm.get.full
9 osm.get.history
10 osm.in_relations
11 osm.in_ways
12 osm.extract
13 osm.extract.ids
14 osm.upload.to
15 osm.query
16 osm.file.query
17 osm.file.extract
18 osm.update
19 osm.changeset.create
20 osm.changeset.add
21 osm.changeset.update
22 osm.changeset.close
23 osm.pbf.update
24 "
25}
3osm.utils.edit() { 26osm.utils.edit() {
4 vim $FILENAME && source $FILENAME 27 vim $FILENAME && source $FILENAME
5} 28}
@@ -15,11 +38,16 @@ osm.get() {
15 tee /tmp/osm &&\ 38 tee /tmp/osm &&\
16 echo content of $1 $2 is copied into /tmp/osm > /dev/tty 39 echo content of $1 $2 is copied into /tmp/osm > /dev/tty
17} 40}
18osm.get_full() { 41osm.get.full() {
19 curl -X GET $OSM_API/$1/$2/full |\ 42 curl -X GET $OSM_API/$1/$2/full |\
20 tee /tmp/osm &&\ 43 tee /tmp/osm &&\
21 echo content of $1 $2 and its members are copied into /tmp/osm > /dev/tty 44 echo content of $1 $2 and its members are copied into /tmp/osm > /dev/tty
22} 45}
46osm.get.history() {
47 curl -X GET $OSM_API/$1/$2/history |\
48 tee /tmp/osm &&\
49 echo history of $1 $2 are copied into /tmp/osm > /dev/tty
50}
23osm.in_relations() { 51osm.in_relations() {
24 curl -X GET $OSM_API/$1/$2/relations |\ 52 curl -X GET $OSM_API/$1/$2/relations |\
25 tee /tmp/osm &&\ 53 tee /tmp/osm &&\
@@ -28,7 +56,7 @@ osm.in_relations() {
28osm.in_ways() { 56osm.in_ways() {
29 curl -X GET $OSM_API/node/$1/ways |\ 57 curl -X GET $OSM_API/node/$1/ways |\
30 tee /tmp/osm &&\ 58 tee /tmp/osm &&\
31 echo ways contain $1 are copied into /tmp/osm > /dev/tty 59 echo ways contain node $1 are copied into /tmp/osm > /dev/tty
32} 60}
33# extract an element from .osm format STDIN 61# extract an element from .osm format STDIN
34osm.extract() { 62osm.extract() {
@@ -37,7 +65,7 @@ osm.extract() {
37 echo "</osm>" 65 echo "</osm>"
38} 66}
39# get ids from .osm format STDIN 67# get ids from .osm format STDIN
40osm.get.ids() { 68osm.extract.ids() {
41 sed -nr 's/.*<(node|way|relation) id=\"([^"]+)\".*/\1 \2/p' 69 sed -nr 's/.*<(node|way|relation) id=\"([^"]+)\".*/\1 \2/p'
42} 70}
43# upload .osm format STDIN to a given changeset 71# upload .osm format STDIN to a given changeset
@@ -54,13 +82,19 @@ osm.upload.to() {
54 source <(echo "("$command " &)") 82 source <(echo "("$command " &)")
55 done 83 done
56} 84}
85# query .osm format STDIN
86osm.query() {
87 osmium tags-filter - $@ --input-format=osm --output-format=osm --omit-referenced
88}
57# query osm-related file with .osm format output 89# query osm-related file with .osm format output
58osm.file.query() { 90osm.file.query() {
59 osmium tags-filter $1 $2 --output-format=osm --omit-referenced 91 file=$1; shift
92 osmium tags-filter $file $@ --output-format=osm --omit-referenced
60} 93}
61# extract an element from osm file 94# extract an element from osm file
62osm.file.extract() { 95osm.file.extract() {
63 osmium getid $1 $2 --output-format=osm 96 file=$1; shift
97 osmium getid $file $@ --output-format=osm
64} 98}
65# update .osm format STDIN with key-value 99# update .osm format STDIN with key-value
66osm.update() { 100osm.update() {
@@ -106,7 +140,10 @@ osm.changeset.add() {
106} 140}
107# update changeset with a new comment 141# update changeset with a new comment
108osm.changeset.update() { 142osm.changeset.update() {
109 echo "<osm><changeset><tag k=\"comment\" v=\"$2\"/></changeset></osm>" | \ 143 echo -n 'type comment: '
144 read -r comment
145
146 echo "<osm><changeset><tag k=\"comment\" v=\"$comment\"/></changeset></osm>" | \
110 curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1 147 curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1
111} 148}
112# close a changeset 149# close a changeset