diff options
| author | typebrook <typebrook@gmail.com> | 2019-11-08 18:07:43 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2019-11-08 18:07:43 +0800 |
| commit | e78266803bc1fa8d6e98e33bc82e8f4eb255160a (patch) | |
| tree | c2cbd502b09cbe5bf5b57317a154ab071e3e90db /utils | |
| parent | 260250f716741cea815d8a3cf99fd9b59dd50f64 (diff) | |
update
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/osm.utils.sh | 49 |
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 @@ | |||
| 1 | FILENAME=$0 | 1 | FILENAME=$0 |
| 2 | 2 | ||
| 3 | osm.help() { | ||
| 4 | echo " | ||
| 5 | COMMANDS: | ||
| 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 | } | ||
| 3 | osm.utils.edit() { | 26 | osm.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 | } |
| 18 | osm.get_full() { | 41 | osm.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 | } |
| 46 | osm.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 | } | ||
| 23 | osm.in_relations() { | 51 | osm.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() { | |||
| 28 | osm.in_ways() { | 56 | osm.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 |
| 34 | osm.extract() { | 62 | osm.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 |
| 40 | osm.get.ids() { | 68 | osm.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 | ||
| 86 | osm.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 |
| 58 | osm.file.query() { | 90 | osm.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 |
| 62 | osm.file.extract() { | 95 | osm.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 |
| 66 | osm.update() { | 100 | osm.update() { |
| @@ -106,7 +140,10 @@ osm.changeset.add() { | |||
| 106 | } | 140 | } |
| 107 | # update changeset with a new comment | 141 | # update changeset with a new comment |
| 108 | osm.changeset.update() { | 142 | osm.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 |