From d6acc3452d42160117e67bf37107e4664034f5ba Mon Sep 17 00:00:00 2001 From: typebrook Date: Thu, 7 Nov 2019 17:59:54 +0800 Subject: update --- utils/osm.utils.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'utils/osm.utils.sh') diff --git a/utils/osm.utils.sh b/utils/osm.utils.sh index 928310d..872e755 100644 --- a/utils/osm.utils.sh +++ b/utils/osm.utils.sh @@ -1,29 +1,67 @@ FILENAME=$0 osm.utils.edit() { - vim $FILENAME + vim $FILENAME && source $FILENAME } OSM_API='https://api.openstreetmap.org/api/0.6' OSM_USER_PASSWD=$(cat $HOME/git/settings/tokens/osm) +# get .osm format data osm.get() { curl -X GET $OSM_API/$1/$2 } +# query osm-related file with .osm format output osm.file.query() { osmium tags-filter $1 $2 --output-format=osm --omit-referenced } +# extract an element from .osm format STDIN osm.extract() { echo "" sed -nr "/^ *<$1 id=\"$2\".*/,/^ *<\/$1>/p" - echo "" } +# update .osm format STDIN with key-value osm.update() { # remove original tag&value sed "/" } +# create a new changeset +osm.changeset.create() { + + #server=https://master.apis.dev.openstreetmap.org + server=https://api.openstreetmap.org + comment="change is_in format" + + for i in "$@" + do + case $i in + -s) + lon_col=0; lat_col=1 + shift;; + + *) + csv=$i + shift;; + esac + done + + info=" + + + + + " + + echo $info |\ + curl -u $OSM_USER_PASSWD -i --upload-file - $server/api/0.6/changeset/create |\ + tee /dev/tty |\ + tail -1 |\ + xsel -ib +} +# add a new element into changeset osm.changeset.add() { element=$(cat -) header=$(echo $element | grep -E "<(node|way|relation)\s") @@ -32,15 +70,18 @@ osm.changeset.add() { echo $element | \ sed -r "s/^( *<(node|way|relation).*version[^ ]+ )(.*)$/\1changeset=\"$1\">/" | \ - curl -X PUT -u $OSM_API_USER_PASSWD -i -T - $OSM_API/$ele_type/$id + curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/$ele_type/$id } +# update changeset with a new comment osm.changeset.update() { echo "" | \ - curl -X PUT -u $OSM_API_USER_PASSWD -i -T - $OSM_API/changeset/$1 + curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1 } +# close a changeset osm.changeset.close() { - curl -X PUT -u $OSM_API_USER_PASSWD -i $OSM_API/changeset/$1/close + curl -X PUT -u $OSM_USER_PASSWD -i $OSM_API/changeset/$1/close } +# update an .osm.pbf file osm.pbf.update() { PBF_FILE=$1 SERVER=http://download.geofabrik.de/asia/taiwan-updates -- cgit v1.2.3-70-g09d2