diff options
author | typebrook <typebrook@gmail.com> | 2019-11-08 00:49:16 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-11-08 00:49:16 +0800 |
commit | 70b63add412aeb23b48dc63ae02a8b5d53a50877 (patch) | |
tree | a7da09dc4984826c334e0c6f239af60a938b34a7 | |
parent | 6080ad312b2bea08e0d1e180ca1afb083fbb188c (diff) |
update
-rw-r--r-- | utils/osm.utils.sh | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/utils/osm.utils.sh b/utils/osm.utils.sh index 5be47cc..a3df88e 100644 --- a/utils/osm.utils.sh +++ b/utils/osm.utils.sh | |||
@@ -4,16 +4,15 @@ osm.utils.edit() { | |||
4 | vim $FILENAME && source $FILENAME | 4 | vim $FILENAME && source $FILENAME |
5 | } | 5 | } |
6 | 6 | ||
7 | OSM_API='https://api.openstreetmap.org/api/0.6' | 7 | #SERVER=https://master.apis.dev.openstreetmap.org |
8 | SERVER=https://api.openstreetmap.org | ||
9 | OSM_API=$SERVER/api/0.6 | ||
8 | OSM_USER_PASSWD=$(cat $HOME/git/settings/tokens/osm) | 10 | OSM_USER_PASSWD=$(cat $HOME/git/settings/tokens/osm) |
9 | 11 | ||
10 | # get .osm format data | 12 | # get .osm format data |
11 | osm.get() { | 13 | osm.get() { |
12 | curl -X GET $OSM_API/$1/$2 | 14 | curl -X GET $OSM_API/$1/$2 &&\ |
13 | } | 15 | echo $2 | xsel -ib |
14 | # query osm-related file with .osm format output | ||
15 | osm.file.query() { | ||
16 | osmium tags-filter $1 $2 --output-format=osm --omit-referenced | ||
17 | } | 16 | } |
18 | # extract an element from .osm format STDIN | 17 | # extract an element from .osm format STDIN |
19 | osm.extract() { | 18 | osm.extract() { |
@@ -21,6 +20,23 @@ osm.extract() { | |||
21 | sed -nr "/^ *<$1 id=\"$2\".*/,/^ *<\/$1>/p" - | 20 | sed -nr "/^ *<$1 id=\"$2\".*/,/^ *<\/$1>/p" - |
22 | echo "</osm>" | 21 | echo "</osm>" |
23 | } | 22 | } |
23 | # get ids from .osm format STDIN | ||
24 | osm.get.ids() { | ||
25 | sed -nr 's/.*<(node|way|relation) id=\"([^"]+)\".*/\1 \2/p' | ||
26 | } | ||
27 | osm.upload() { | ||
28 | #source <(cat fetch | sed 's/^/osm.extract /g' | sed 's/$/ <new.osm/g') | ||
29 | INPUT=$(cat -) | ||
30 | echo $INPUT | osm.get.ids | sed 's/.*/osm.extract \0 <($INPUT)/g' | xargs tee | ||
31 | } | ||
32 | # query osm-related file with .osm format output | ||
33 | osm.file.query() { | ||
34 | osmium tags-filter $1 $2 --output-format=osm --omit-referenced | ||
35 | } | ||
36 | # extract an element from osm file | ||
37 | osm.file.extract() { | ||
38 | osmium getid $1 $2 --output-format=osm | ||
39 | } | ||
24 | # update .osm format STDIN with key-value | 40 | # update .osm format STDIN with key-value |
25 | osm.update() { | 41 | osm.update() { |
26 | # remove original tag&value | 42 | # remove original tag&value |
@@ -31,22 +47,8 @@ osm.update() { | |||
31 | # create a new changeset | 47 | # create a new changeset |
32 | osm.changeset.create() { | 48 | osm.changeset.create() { |
33 | 49 | ||
34 | #server=https://master.apis.dev.openstreetmap.org | 50 | echo -n "type comment: " |
35 | server=https://api.openstreetmap.org | 51 | read comment |
36 | comment="change is_in format" | ||
37 | |||
38 | for i in "$@" | ||
39 | do | ||
40 | case $i in | ||
41 | -s) | ||
42 | lon_col=0; lat_col=1 | ||
43 | shift;; | ||
44 | |||
45 | *) | ||
46 | csv=$i | ||
47 | shift;; | ||
48 | esac | ||
49 | done | ||
50 | 52 | ||
51 | info="<osm> | 53 | info="<osm> |
52 | <changeset> | 54 | <changeset> |
@@ -56,7 +58,7 @@ osm.changeset.create() { | |||
56 | " | 58 | " |
57 | 59 | ||
58 | echo $info |\ | 60 | echo $info |\ |
59 | curl -u $OSM_USER_PASSWD -i --upload-file - $server/api/0.6/changeset/create |\ | 61 | curl -u $OSM_USER_PASSWD -i --upload-file - $SERVER/api/0.6/changeset/create |\ |
60 | tee /dev/tty |\ | 62 | tee /dev/tty |\ |
61 | tail -1 |\ | 63 | tail -1 |\ |
62 | xsel -ib | 64 | xsel -ib |