diff options
author | typebrook <typebrook@gmail.com> | 2019-11-06 08:21:02 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-11-06 22:56:14 +0800 |
commit | 93c22ce0aa1bb1ed16123d6517c536c44368f0e8 (patch) | |
tree | 7e2133de42021e55b17e45344a0b5603505bf4ce | |
parent | 1e688c2c35929952d65d227a80746e119c347818 (diff) |
update osm features
-rw-r--r-- | alias | 47 | ||||
-rwxr-xr-x | scripts/changeset | 30 |
2 files changed, 74 insertions, 3 deletions
@@ -1,4 +1,5 @@ | |||
1 | SETTING_DIR="$HOME/git/settings" | 1 | SETTING_DIR="$HOME/git/settings" |
2 | OSM_USER_PASSWD=$(cat $HOME/git/settings/token/osm) | ||
2 | 3 | ||
3 | # settings | 4 | # settings |
4 | alias al='vim ~/.bash_aliases && source ~/.bash_aliases' | 5 | alias al='vim ~/.bash_aliases && source ~/.bash_aliases' |
@@ -161,6 +162,7 @@ alias data-osm-diff="curl https://planet.openstreetmap.org/replication/minute/st | |||
161 | alias xi='xsel -ib' | 162 | alias xi='xsel -ib' |
162 | alias xo='xsel -ob' | 163 | alias xo='xsel -ob' |
163 | alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && xsel -ob ' | 164 | alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && xsel -ob ' |
165 | alias xll='xo >> ~/vimwiki/working.md' | ||
164 | alias xc='xsel -ob | gcc -xc -' | 166 | alias xc='xsel -ob | gcc -xc -' |
165 | 167 | ||
166 | # image | 168 | # image |
@@ -193,9 +195,6 @@ mvt_decode() { | |||
193 | big52utf8() { | 195 | big52utf8() { |
194 | iconv -f BIG-5 -t UTF-8 $1 > $1.utf8 | 196 | iconv -f BIG-5 -t UTF-8 $1 > $1.utf8 |
195 | } | 197 | } |
196 | replace() { | ||
197 | rm $1 && mv $2 $1 | ||
198 | } | ||
199 | 198 | ||
200 | # tmp | 199 | # tmp |
201 | alias cdo='cd ~/git/openmaptiles' | 200 | alias cdo='cd ~/git/openmaptiles' |
@@ -210,3 +209,45 @@ alias cdand='cd ~/git/sample' | |||
210 | repo='git@github.com' | 209 | repo='git@github.com' |
211 | hub='https://github.com' | 210 | hub='https://github.com' |
212 | typebrook='git@github.com:typebrook' | 211 | typebrook='git@github.com:typebrook' |
212 | |||
213 | |||
214 | # osm | ||
215 | osm='https://api.openstreetmap.org/api/0.6/' | ||
216 | osm.get() { | ||
217 | curl -X GET $osm/$1/$2 | ||
218 | } | ||
219 | osm.query() { | ||
220 | osmium tags-filter $1 $2 --output-format=osm --omit-referenced | ||
221 | } | ||
222 | osm.update() { | ||
223 | # remove original tag&value | ||
224 | sed "/<tag k=\"$1\"/d" - | \ | ||
225 | # insert new tag&value | ||
226 | sed -r "/<(node|way|relation)/a \ \ \ \ <tag k=\"$1\" v=\"$2\"\/>" | ||
227 | } | ||
228 | osm.changeset.update() { | ||
229 | element=$(cat -) | ||
230 | header=$(echo $element | grep -E "<(node|way|relation)\s") | ||
231 | ele_type=$(echo $header | sed -r 's/.*<(node|way|relation).*$/\1/') | ||
232 | id=$(echo $header | sed -r 's/.* id=\"([^"]+)\".*$/\1/') | ||
233 | |||
234 | echo $element | \ | ||
235 | sed -r "s/^( *<(node|way|relation).*version[^ ]+ )(.*)$/\1changeset=\"$1\">/" | \ | ||
236 | curl -X PUT -u $OSM_USER_PASSWD -i -T - https://api.openstreetmap.org/api/0.6/$ele_type/$id | ||
237 | } | ||
238 | osm.changeset.close() { | ||
239 | curl -X PUT -u $OSM_USER_PASSWD -i https://api.openstreetmap.org/api/0.6/changeset/$1/close | ||
240 | } | ||
241 | osm.pbf.update() { | ||
242 | osmium fileinfo $1 | \ | ||
243 | grep osmosis_replication_sequence_number | \ | ||
244 | cut -d'=' -f2 | \ | ||
245 | sed 's/$/+1/' | bc | \ | ||
246 | sed -r 's/(.{1})(.{3})/00\1\/\2/' | \ | ||
247 | xargs -I {} curl -O http://download.geofabrik.de/asia/taiwan-updates/000/'{}'.osc.gz | ||
248 | } | ||
249 | |||
250 | # misc | ||
251 | length() { | ||
252 | ogr2ogr -sql "SELECT geom.length() FROM $1" $1.geojson | ||
253 | } | ||
diff --git a/scripts/changeset b/scripts/changeset new file mode 100755 index 0000000..d3dee3d --- /dev/null +++ b/scripts/changeset | |||
@@ -0,0 +1,30 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | OSM_USER_PASSWD=$(cat ~/git/settings/token/osm) | ||
4 | #server=https://master.apis.dev.openstreetmap.org | ||
5 | server=https://api.openstreetmap.org | ||
6 | comment="change is_in format" | ||
7 | |||
8 | for i in "$@" | ||
9 | do | ||
10 | case $i in | ||
11 | -s) | ||
12 | lon_col=0; lat_col=1 | ||
13 | shift;; | ||
14 | |||
15 | *) | ||
16 | csv=$i | ||
17 | shift;; | ||
18 | esac | ||
19 | done | ||
20 | |||
21 | info="<osm> | ||
22 | <changeset> | ||
23 | <tag k='comment' v='$comment'/> | ||
24 | </changeset> | ||
25 | </osm> | ||
26 | " | ||
27 | |||
28 | echo $info |\ | ||
29 | curl -u $OSM_USER_PASSWD -i --upload-file - $server/api/0.6/changeset/create | ||
30 | |||