diff options
| author | typebrook <typebrook@gmail.com> | 2019-11-11 11:58:16 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2019-11-11 11:58:16 +0800 |
| commit | 69e3a3ff1d2126fc82fb963942f9238b601bfa4a (patch) | |
| tree | af893162849de25faa62df8a60246b94ae0a9002 /utils | |
| parent | f63595db651f891d8fead6a7dfcd664cbb08f2dd (diff) | |
update
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/osm | 30 |
1 files changed, 22 insertions, 8 deletions
| @@ -5,7 +5,7 @@ FILENAME=$0 | |||
| 5 | osm.help() { | 5 | osm.help() { |
| 6 | echo " | 6 | echo " |
| 7 | COMMANDS: | 7 | COMMANDS: |
| 8 | osm.utils.edit | 8 | util.osm.edit |
| 9 | osm.get | 9 | osm.get |
| 10 | osm.get.full | 10 | osm.get.full |
| 11 | osm.get.history | 11 | osm.get.history |
| @@ -55,28 +55,38 @@ osm.in_relations() { | |||
| 55 | tee /tmp/osm &&\ | 55 | tee /tmp/osm &&\ |
| 56 | echo relations contain $1 $2 are copied into /tmp/osm > /dev/tty | 56 | echo relations contain $1 $2 are copied into /tmp/osm > /dev/tty |
| 57 | } | 57 | } |
| 58 | osm.in_relations_as() { | ||
| 59 | ele_pattern="(node|way|relation)" | ||
| 60 | |||
| 61 | osm.in_relations $1 $2 |\ | ||
| 62 | sed -nr "/<$ele_pattern/,/<\/$ele_pattern/ { | ||
| 63 | /<$ele_pattern/ {s/.* id=\"([^\"]+)\".*/\1/;h} | ||
| 64 | /<member type=\"$1\" ref=\"$2\" role=\"$3\"/ {g;p} | ||
| 65 | }" | ||
| 66 | } | ||
| 58 | osm.in_ways() { | 67 | osm.in_ways() { |
| 59 | curl -X GET $OSM_API/node/$1/ways |\ | 68 | curl -X GET $OSM_API/node/$1/ways |\ |
| 60 | tee /tmp/osm &&\ | 69 | tee /tmp/osm &&\ |
| 61 | echo ways contain node $1 are copied into /tmp/osm > /dev/tty | 70 | echo ways contain node $1 are copied into /tmp/osm > /dev/tty |
| 62 | } | 71 | } |
| 63 | osm.extract.tag() { | 72 | osm.list.tag() { |
| 64 | sed -nr "/<(node|way|relation)/,/<\/(node|way|relation)/ { | 73 | ele_pattern="(node|way|relation)" |
| 74 | sed -nr "/<$ele_pattern/,/<\/$ele_pattern/ { | ||
| 65 | /<tag k=\"$1\"/ { | 75 | /<tag k=\"$1\"/ { |
| 66 | s/.*v=\"([^\"]+)\".*/\1/ | 76 | s/.*v=\"([^\"]+)\".*/\1/ |
| 67 | h | 77 | h |
| 68 | } | 78 | } |
| 69 | /<\/(node|way|relation)/ {x;p;s/.*//;x} | 79 | /<\/$ele_pattern/ {x;p;s/.*//;x} |
| 70 | }" | 80 | }" |
| 71 | } | 81 | } |
| 72 | osm.extract.tags() { | 82 | osm.list.tags() { |
| 73 | content=$(cat) | 83 | content=$(cat) |
| 74 | echo $content | osm.extract.ids | tr ' ' ',' > /tmp/osm | 84 | echo $content | osm.list.ids | tr ' ' ',' > /tmp/osm |
| 75 | 85 | ||
| 76 | for tag in "$@" | 86 | for tag in "$@" |
| 77 | do | 87 | do |
| 78 | echo $content |\ | 88 | echo $content |\ |
| 79 | osm.extract.tag $tag > /tmp/osm.tag.$tag | 89 | osm.list.tag $tag > /tmp/osm.tag.$tag |
| 80 | done | 90 | done |
| 81 | 91 | ||
| 82 | paste -d',' /tmp/osm /tmp/osm.tag.* | 92 | paste -d',' /tmp/osm /tmp/osm.tag.* |
| @@ -90,7 +100,7 @@ osm.extract.id() { | |||
| 90 | echo "</osm>" | 100 | echo "</osm>" |
| 91 | } | 101 | } |
| 92 | # get ids from .osm format STDIN | 102 | # get ids from .osm format STDIN |
| 93 | osm.extract.ids() { | 103 | osm.list.ids() { |
| 94 | sed -nr 's/.*<(node|way|relation) id=\"([^"]+)\".*/\1 \2/p' | 104 | sed -nr 's/.*<(node|way|relation) id=\"([^"]+)\".*/\1 \2/p' |
| 95 | } | 105 | } |
| 96 | # upload .osm format STDIN to a given changeset | 106 | # upload .osm format STDIN to a given changeset |
| @@ -121,6 +131,10 @@ osm.file.extract() { | |||
| 121 | file=$1; shift | 131 | file=$1; shift |
| 122 | osmium getid $file $@ --output-format=osm | 132 | osmium getid $file $@ --output-format=osm |
| 123 | } | 133 | } |
| 134 | osm.file.extract.full() { | ||
| 135 | file=$1; shift | ||
| 136 | osmium getid $file $@ --output-format=osm --add-referenced | ||
| 137 | } | ||
| 124 | # update .osm format STDIN with key-value | 138 | # update .osm format STDIN with key-value |
| 125 | osm.update() { | 139 | osm.update() { |
| 126 | # remove original tag&value | 140 | # remove original tag&value |