diff options
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/osm | 53 |
1 files changed, 30 insertions, 23 deletions
| @@ -35,36 +35,42 @@ OSM_API=$SERVER/api/0.6 | |||
| 35 | OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) | 35 | OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) |
| 36 | 36 | ||
| 37 | # get .osm format data | 37 | # get .osm format data |
| 38 | osm.fetch() { | 38 | osm.api.fetch() { |
| 39 | curl -X GET $OSM_API/$1/$2 |\ | 39 | curl -X GET $OSM_API/$1/$2 |\ |
| 40 | tee /tmp/osm &&\ | 40 | tee /tmp/osm &&\ |
| 41 | echo content of $1 $2 is copied into /tmp/osm > /dev/tty | 41 | echo content of $1 $2 is copied into /tmp/osm > /dev/tty |
| 42 | } | 42 | } |
| 43 | osm.fetch.full() { | 43 | osm.api.fetch.full() { |
| 44 | curl -X GET $OSM_API/$1/$2/full |\ | 44 | curl -X GET $OSM_API/$1/$2/full |\ |
| 45 | tee /tmp/osm &&\ | 45 | tee /tmp/osm &&\ |
| 46 | echo content of $1 $2 and its members are copied into /tmp/osm > /dev/tty | 46 | echo content of $1 $2 and its members are copied into /tmp/osm > /dev/tty |
| 47 | } | 47 | } |
| 48 | osm.fetch.history() { | 48 | osm.api.fetch.history() { |
| 49 | curl -X GET $OSM_API/$1/$2/history |\ | 49 | curl -X GET $OSM_API/$1/$2/history |\ |
| 50 | tee /tmp/osm &&\ | 50 | tee /tmp/osm &&\ |
| 51 | echo history of $1 $2 are copied into /tmp/osm > /dev/tty | 51 | echo history of $1 $2 are copied into /tmp/osm > /dev/tty |
| 52 | } | 52 | } |
| 53 | osm.in_relations() { | 53 | osm.api.in_relations() { |
| 54 | curl -X GET $OSM_API/$1/$2/relations |\ | 54 | curl -X GET $OSM_API/$1/$2/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() { | 58 | osm.member.relation() { |
| 59 | ele_pattern="(node|way|relation)" | 59 | sed -nr "/<relation/,/<\/relation/ { |
| 60 | 60 | /<relation/ {s/.* id=\"([^\"]+)\".*/\1/;h} | |
| 61 | osm.in_relations $1 $2 |\ | 61 | /<member type=\"$1\" ref=\"$2\" role=\"$3\"/ {g;p;q} |
| 62 | sed -nr "/<$ele_pattern/,/<\/$ele_pattern/ { | 62 | } |
| 63 | /<$ele_pattern/ {s/.* id=\"([^\"]+)\".*/\1/;h} | 63 | $ {s/.*//;P} |
| 64 | /<member type=\"$1\" ref=\"$2\" role=\"$3\"/ {g;p} | 64 | " | head -1 |
| 65 | }" | ||
| 66 | } | 65 | } |
| 67 | osm.in_ways() { | 66 | osm.file.cat() { |
| 67 | osmium cat $1 --output-format=osm -t $2 | ||
| 68 | } | ||
| 69 | osm.api.member.relation() { | ||
| 70 | osm.api.in_relations $1 $2 |\ | ||
| 71 | osm.member.relation $1 $2 $3 | ||
| 72 | } | ||
| 73 | osm.api.in_ways() { | ||
| 68 | curl -X GET $OSM_API/node/$1/ways |\ | 74 | curl -X GET $OSM_API/node/$1/ways |\ |
| 69 | tee /tmp/osm &&\ | 75 | tee /tmp/osm &&\ |
| 70 | echo ways contain node $1 are copied into /tmp/osm > /dev/tty | 76 | echo ways contain node $1 are copied into /tmp/osm > /dev/tty |
| @@ -86,11 +92,12 @@ osm.list.tags() { | |||
| 86 | for tag in "$@" | 92 | for tag in "$@" |
| 87 | do | 93 | do |
| 88 | echo $content |\ | 94 | echo $content |\ |
| 89 | osm.list.tag $tag > /tmp/osm.tag.$tag | 95 | osm.list.tag $tag |\ |
| 96 | paste -d',' /tmp/osm - > /tmp/osm.new &&\ | ||
| 97 | mv /tmp/osm.new /tmp/osm | ||
| 90 | done | 98 | done |
| 91 | 99 | ||
| 92 | paste -d',' /tmp/osm /tmp/osm.tag.* | 100 | cat /tmp/osm |
| 93 | rm /tmp/osm.tag.* | ||
| 94 | } | 101 | } |
| 95 | # extract an element from .osm format STDIN | 102 | # extract an element from .osm format STDIN |
| 96 | # $1 as [node|way|relation], $2 as id | 103 | # $1 as [node|way|relation], $2 as id |
| @@ -105,12 +112,12 @@ osm.list.ids() { | |||
| 105 | } | 112 | } |
| 106 | # upload .osm format STDIN to a given changeset | 113 | # upload .osm format STDIN to a given changeset |
| 107 | # allows multiple elements in osm body | 114 | # allows multiple elements in osm body |
| 108 | osm.upload.to() { | 115 | osm.api.upload.to() { |
| 109 | 116 | ||
| 110 | tee /tmp/osm |\ | 117 | tee /tmp/osm |\ |
| 111 | osm.extract.ids |\ | 118 | osm.extract.ids |\ |
| 112 | sed 's#.*#osm.extract \0 < /tmp/osm#g' |\ | 119 | sed 's#.*#osm.extract \0 < /tmp/osm#g' |\ |
| 113 | sed "s/.*/\0 \| osm.changeset.add $1/g" |\ | 120 | sed "s/.*/\0 \| osm.api.changeset.add $1/g" |\ |
| 114 | while read -r command | 121 | while read -r command |
| 115 | do | 122 | do |
| 116 | echo $command | 123 | echo $command |
| @@ -148,7 +155,7 @@ osm.update() { | |||
| 148 | fi | 155 | fi |
| 149 | } | 156 | } |
| 150 | # create a new changeset | 157 | # create a new changeset |
| 151 | osm.changeset.create() { | 158 | osm.api.changeset.create() { |
| 152 | 159 | ||
| 153 | echo -n "type comment: " | 160 | echo -n "type comment: " |
| 154 | read comment | 161 | read comment |
| @@ -167,7 +174,7 @@ osm.changeset.create() { | |||
| 167 | xsel -ib | 174 | xsel -ib |
| 168 | } | 175 | } |
| 169 | # add a new element into changeset | 176 | # add a new element into changeset |
| 170 | osm.changeset.add() { | 177 | osm.api.changeset.add() { |
| 171 | element=$(cat) | 178 | element=$(cat) |
| 172 | header=$(echo $element | grep -E "<(node|way|relation)\s") | 179 | header=$(echo $element | grep -E "<(node|way|relation)\s") |
| 173 | ele_type=$(echo $header | sed -r 's/.*<(node|way|relation).*$/\1/') | 180 | ele_type=$(echo $header | sed -r 's/.*<(node|way|relation).*$/\1/') |
| @@ -178,7 +185,7 @@ osm.changeset.add() { | |||
| 178 | curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/$ele_type/$id | 185 | curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/$ele_type/$id |
| 179 | } | 186 | } |
| 180 | # update changeset with a new comment | 187 | # update changeset with a new comment |
| 181 | osm.changeset.update() { | 188 | osm.api.changeset.update() { |
| 182 | echo -n 'type comment: ' | 189 | echo -n 'type comment: ' |
| 183 | read -r comment | 190 | read -r comment |
| 184 | 191 | ||
| @@ -186,7 +193,7 @@ osm.changeset.update() { | |||
| 186 | curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1 | 193 | curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1 |
| 187 | } | 194 | } |
| 188 | # close a changeset | 195 | # close a changeset |
| 189 | osm.changeset.close() { | 196 | osm.api.changeset.close() { |
| 190 | curl -X PUT -u $OSM_USER_PASSWD -i $OSM_API/changeset/$1/close | 197 | curl -X PUT -u $OSM_USER_PASSWD -i $OSM_API/changeset/$1/close |
| 191 | } | 198 | } |
| 192 | # update an .osm.pbf file | 199 | # update an .osm.pbf file |