aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/osm
diff options
context:
space:
mode:
Diffstat (limited to 'bin/osm')
-rwxr-xr-xbin/osm/josm_install.sh8
-rw-r--r--bin/osm/note1
-rw-r--r--bin/osm/osm18
-rwxr-xr-xbin/osm/osm.api.changeset.add10
-rwxr-xr-xbin/osm/osm.api.changeset.close3
-rwxr-xr-xbin/osm/osm.api.changeset.commit80
-rwxr-xr-xbin/osm/osm.api.changeset.create25
-rwxr-xr-xbin/osm/osm.api.changeset.update9
-rwxr-xr-xbin/osm/osm.api.changeset.upload6
-rwxr-xr-xbin/osm/osm.api.fetch6
-rwxr-xr-xbin/osm/osm.api.fetch.full5
-rwxr-xr-xbin/osm/osm.api.fetch.history6
-rwxr-xr-xbin/osm/osm.api.member.relation4
-rwxr-xr-xbin/osm/osm.api.referenced.relation6
-rwxr-xr-xbin/osm/osm.api.referenced.way5
-rwxr-xr-xbin/osm/osm.api.upload.to12
-rwxr-xr-xbin/osm/osm.file.get4
-rwxr-xr-xbin/osm/osm.file.get.full4
-rwxr-xr-xbin/osm/osm.file.query4
-rwxr-xr-xbin/osm/osm.goto3
-rwxr-xr-xbin/osm/osm.help33
-rwxr-xr-xbin/osm/osm.list.ids3
-rwxr-xr-xbin/osm/osm.list.tag10
-rwxr-xr-xbin/osm/osm.list.tags15
-rwxr-xr-xbin/osm/osm.member.relation8
-rwxr-xr-xbin/osm/osm.osc.by_member31
-rwxr-xr-xbin/osm/osm.osc.by_tag45
-rwxr-xr-xbin/osm/osm.osm.remove9
-rwxr-xr-xbin/osm/osm.pbf.update41
-rwxr-xr-xbin/osm/osm.query3
-rwxr-xr-xbin/osm/sequence_number.sh22
31 files changed, 439 insertions, 0 deletions
diff --git a/bin/osm/josm_install.sh b/bin/osm/josm_install.sh
new file mode 100755
index 0000000..520875a
--- /dev/null
+++ b/bin/osm/josm_install.sh
@@ -0,0 +1,8 @@
1#!/bin/bash
2
3# scripts from https://josm.openstreetmap.de/wiki/Download#Webstart
4echo deb https://josm.openstreetmap.de/apt $(lsb_release -sc) universe | sudo tee /etc/apt/sources.list.d/josm.list > /dev/null &&\
5wget -q https://josm.openstreetmap.de/josm-apt.key -O- | sudo apt-key add - &&\
6sudo apt-get update &&\
7sudo apt-get remove josm josm-plugins &&\
8sudo apt-get install josm
diff --git a/bin/osm/note b/bin/osm/note
new file mode 100644
index 0000000..aa51031
--- /dev/null
+++ b/bin/osm/note
@@ -0,0 +1 @@
diff -y <(ls|sort) <(osm.help | cut -d' ' -f3 | sort | uniq)
diff --git a/bin/osm/osm b/bin/osm/osm
new file mode 100644
index 0000000..344f906
--- /dev/null
+++ b/bin/osm/osm
@@ -0,0 +1,18 @@
1#! /bin/sh
2
3export OSM_TEST_SERVER=https://master.apis.dev.openstreetmap.org
4export OSM_SERVER=https://api.openstreetmap.org
5export OSM_TES_SERVER=https://api.openstreetmap.org
6
7export OSM_API=$OSM_SERVER/api/0.6
8export OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm 2>/dev/null)
9
10FILENAME=$0
11
12utils.osm() {
13 vim $FILENAME && source $FILENAME
14}
15
16osm.api() {
17 curl -X GET $OSM_API/$1/$2
18}
diff --git a/bin/osm/osm.api.changeset.add b/bin/osm/osm.api.changeset.add
new file mode 100755
index 0000000..3e4878e
--- /dev/null
+++ b/bin/osm/osm.api.changeset.add
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3element=$(cat)
4header=$(echo $element | grep -E "<(node|way|relation)\s")
5ele_type=$(echo $header | sed -r 's/.*<(node|way|relation).*$/\1/')
6id=$(echo $header | sed -r 's/.* id=\"([^"]+)\".*$/\1/')
7
8echo $element | \
9sed -r "s/^( *<(node|way|relation).*version[^ ]+ )(.*)$/\1changeset=\"$1\">/" | \
10curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/$ele_type/$id
diff --git a/bin/osm/osm.api.changeset.close b/bin/osm/osm.api.changeset.close
new file mode 100755
index 0000000..3b016c3
--- /dev/null
+++ b/bin/osm/osm.api.changeset.close
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3curl -X PUT -u $OSM_USER_PASSWD -i $OSM_API/changeset/$1/close
diff --git a/bin/osm/osm.api.changeset.commit b/bin/osm/osm.api.changeset.commit
new file mode 100755
index 0000000..6b67833
--- /dev/null
+++ b/bin/osm/osm.api.changeset.commit
@@ -0,0 +1,80 @@
1#!/bin/bash
2
3set -e
4shopt -s lastpipe
5
6OSM_SERVER=https://api.openstreetmap.org
7OSM_TEST_SERVER=https://master.apis.dev.openstreetmap.org
8if [[ $@ =~ '--serious' ]]; then
9 SERVER=$OSM_SERVER
10else
11 SERVER=$OSM_TEST_SERVER
12fi
13
14OSM_API=${SERVER}/api/0.6
15FILE=${@//--serious/}
16
17# Prompt for comment and User:Password
18if [[ ! -t 0 ]]; then
19 comment=$(cat)
20else
21 read -e -p 'Type comment: ' -r comment </dev/tty
22fi
23if [ -z ${OSM_USER_PASSWD} ]; then
24 read -e -p 'Type USER:PASSWD: ' -r OSM_USER_PASSWD </dev/tty
25fi
26
27create_changeset() {
28 SOURCE_TAG="${SOURCE:+$(printf "<tag k='source' v='%s'/>" $SOURCE)}"
29
30 curl ${OSM_API}/changeset/create \
31 --user ${OSM_USER_PASSWD} \
32 --upload-file - \
33 --silent \
34 <<EOF | tail -1
35<osm>
36 <changeset>
37 ${SOURCE_TAG}
38 <tag k='comment' v='${comment}'/>
39 <tag k='created_by' v='bash script'/>
40 <tag k='bot' v='yes'/>
41 </changeset>
42</osm>
43EOF
44}
45
46# Return http code after uploading a file
47uploade_file_to_changeset() {
48 curl -X POST $OSM_API/changeset/${changeset_id}/upload \
49 --user ${OSM_USER_PASSWD} -i \
50 --upload-file - \
51 --silent -o /dev/null -w "%{http_code}"
52}
53
54close_changeset() {
55 curl -X PUT ${OSM_API}/changeset/${changeset_id}/close \
56 --user ${OSM_USER_PASSWD} -i \
57 --silent -o /dev/null -w "%{http_code}"
58}
59
60# Create changeset with given information
61changeset_id=$(create_changeset)
62
63# Print created changeset id
64echo "Changeset created, check ${SERVER}/changeset/${changeset_id}" >/dev/tty
65echo ${changeset_id}
66
67# Upload OSC file to Changeset
68sed -Ee "/<(node|way|relation)/ s/>/ changeset=\"${changeset_id}\">/" $FILE |\
69uploade_file_to_changeset | if [[ $(cat) == '200' ]]; then
70 echo Upload file $FILE to changeset ${changeset_id} >/dev/tty
71else
72 exit 1
73fi
74
75# Close Changeset
76close_changeset | if [[ $(cat) == '200' ]]; then
77 echo Changeset ${changeset_id} closed >/dev/tty
78else
79 exit 1
80fi
diff --git a/bin/osm/osm.api.changeset.create b/bin/osm/osm.api.changeset.create
new file mode 100755
index 0000000..ab9fe85
--- /dev/null
+++ b/bin/osm/osm.api.changeset.create
@@ -0,0 +1,25 @@
1#!/bin/sh
2
3set -e
4
5read -e -p 'Type comment: ' -r comment </dev/tty
6if [ -z $OSM_USER_PASSWD ]; then
7 read -e -p 'Type USER:PASSWD: ' -r OSM_USER_PASSWD </dev/tty
8fi
9
10info="<osm>
11 <changeset>
12 <tag k='comment' v='$comment'/>
13 <tag k='created_by' v='bash script'/>
14 <tag k='bot' v='yes'/>
15 </changeset>
16 </osm>
17 "
18
19changeset_id=$(echo $info |\
20 curl -u $OSM_USER_PASSWD --upload-file - $OSM_API/changeset/create |\
21 tail -1)
22
23echo >/dev/tty
24echo "changeset created, check $OSM_SERVER/changeset/$changeset_id" >/dev/tty
25echo $changeset_id | tee /tmp/changeset && echo copied to /tmp/changeset
diff --git a/bin/osm/osm.api.changeset.update b/bin/osm/osm.api.changeset.update
new file mode 100755
index 0000000..7267449
--- /dev/null
+++ b/bin/osm/osm.api.changeset.update
@@ -0,0 +1,9 @@
1#!/bin/sh
2
3ID=${1:-$(cat /tmp/changeset 2>/dev/null)}
4[ -z $ID ] && echo Please specify Changeset ID && exit 1
5
6read -e -p 'Type comment: ' -r comment </dev/tty
7
8echo "<osm><changeset><tag k=\"comment\" v=\"$comment\"/></changeset></osm>" | \
9curl -X PUT -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1
diff --git a/bin/osm/osm.api.changeset.upload b/bin/osm/osm.api.changeset.upload
new file mode 100755
index 0000000..96bdff4
--- /dev/null
+++ b/bin/osm/osm.api.changeset.upload
@@ -0,0 +1,6 @@
1#!/bin/sh
2
3cat $2 |\
4sed -r "/<(node|way|relation)/ s/>/ changeset=\"$1\">/" |\
5tee /dev/tty |\
6curl -X POST -u $OSM_USER_PASSWD -i -T - $OSM_API/changeset/$1/upload
diff --git a/bin/osm/osm.api.fetch b/bin/osm/osm.api.fetch
new file mode 100755
index 0000000..8460c5f
--- /dev/null
+++ b/bin/osm/osm.api.fetch
@@ -0,0 +1,6 @@
1#! /bin/sh
2
3# get .osm format data
4curl -X GET $OSM_API/$1/$2 |\
5tee /tmp/osm &&\
6echo content of $1 $2 is copied into /tmp/osm > /dev/tty
diff --git a/bin/osm/osm.api.fetch.full b/bin/osm/osm.api.fetch.full
new file mode 100755
index 0000000..5ee78b8
--- /dev/null
+++ b/bin/osm/osm.api.fetch.full
@@ -0,0 +1,5 @@
1#! /bin/sh
2
3curl -X GET $OSM_API/$1/$2/full |\
4tee /tmp/osm &&\
5echo "\n" content of $1 $2 and its members are copied into /tmp/osm > /dev/tty
diff --git a/bin/osm/osm.api.fetch.history b/bin/osm/osm.api.fetch.history
new file mode 100755
index 0000000..bc837bd
--- /dev/null
+++ b/bin/osm/osm.api.fetch.history
@@ -0,0 +1,6 @@
1#! /bin/sh
2
3curl -X GET $OSM_API/$1/$2/history |\
4tee /tmp/osm &&\
5echo &&\
6echo "\n" history of $1 $2 are copied into /tmp/osm > /dev/tty
diff --git a/bin/osm/osm.api.member.relation b/bin/osm/osm.api.member.relation
new file mode 100755
index 0000000..5addef7
--- /dev/null
+++ b/bin/osm/osm.api.member.relation
@@ -0,0 +1,4 @@
1#! /bin/sh
2
3osm.api.referenced.relation $1 $2 |\
4osm.member.relation $1 $2 $3
diff --git a/bin/osm/osm.api.referenced.relation b/bin/osm/osm.api.referenced.relation
new file mode 100755
index 0000000..2ce0631
--- /dev/null
+++ b/bin/osm/osm.api.referenced.relation
@@ -0,0 +1,6 @@
1#! /bin/sh
2
3curl -X GET $OSM_API/$1/$2/relations |\
4tee /tmp/osm &&\
5echo &&\
6echo "\n" relations contain $1 $2 are copied into /tmp/osm > /dev/tty
diff --git a/bin/osm/osm.api.referenced.way b/bin/osm/osm.api.referenced.way
new file mode 100755
index 0000000..1d84238
--- /dev/null
+++ b/bin/osm/osm.api.referenced.way
@@ -0,0 +1,5 @@
1#!/bin/bash
2
3curl -X GET $OSM_API/node/$1/ways |\
4tee /tmp/osm &&\
5echo ways contain node $1 are copied into /tmp/osm > /dev/tty
diff --git a/bin/osm/osm.api.upload.to b/bin/osm/osm.api.upload.to
new file mode 100755
index 0000000..3979220
--- /dev/null
+++ b/bin/osm/osm.api.upload.to
@@ -0,0 +1,12 @@
1#! /bin/sh
2
3# allows multiple elements in osm body
4tee /tmp/osm |\
5osm.list.ids |\
6sed 's#.*#osm.extract \0 < /tmp/osm#g' |\
7sed "s/.*/\0 \| osm.api.changeset.add $1/g" |\
8while read -r command
9do
10 echo $command
11 source<(echo "($command &)")
12done
diff --git a/bin/osm/osm.file.get b/bin/osm/osm.file.get
new file mode 100755
index 0000000..e2b67b4
--- /dev/null
+++ b/bin/osm/osm.file.get
@@ -0,0 +1,4 @@
1#! /bin/sh
2
3file=$1; shift
4osmium getid $file $@ --output-format=osm
diff --git a/bin/osm/osm.file.get.full b/bin/osm/osm.file.get.full
new file mode 100755
index 0000000..50ee2f1
--- /dev/null
+++ b/bin/osm/osm.file.get.full
@@ -0,0 +1,4 @@
1#! /bin/sh
2
3file=$1; shift
4osmium getid $file $@ --output-format=osm --add-referenced
diff --git a/bin/osm/osm.file.query b/bin/osm/osm.file.query
new file mode 100755
index 0000000..4a01b5b
--- /dev/null
+++ b/bin/osm/osm.file.query
@@ -0,0 +1,4 @@
1#! /bin/sh
2
3file=$1; shift
4osmium tags-filter $file $@ --output-format=osm --omit-referenced
diff --git a/bin/osm/osm.goto b/bin/osm/osm.goto
new file mode 100755
index 0000000..25bceaa
--- /dev/null
+++ b/bin/osm/osm.goto
@@ -0,0 +1,3 @@
1#!/bin/sh
2
3xdg-open https://www.openstreetmap.org/$1/$2
diff --git a/bin/osm/osm.help b/bin/osm/osm.help
new file mode 100755
index 0000000..f4c20d2
--- /dev/null
+++ b/bin/osm/osm.help
@@ -0,0 +1,33 @@
1#! /bin/sh
2
3cat <<EOF
4COMMANDS:
5 osm.help
6 util.osm.edit
7 osm.api.changeset.create create a new changeset and return its ID
8 osm.api.changeset.update <changeset ID> update changeset with new comment
9 osm.api.changeset.upload <changeset ID> <osc file> upload osc file to the given changeset
10 osm.api.changeset.add <changeset ID> STDIN=osm element, add it into changeset
11 osm.api.changeset.close <changeset ID> close the given changeset
12 osm.api.fetch <element type> <element ID>
13 osm.api.fetch.full like .fetch, but return with all referenced elements
14 osm.api.fetch.history <element type> <element ID>
15 osm.api.member.relation <element type> <element ID> <member type> get first relations reference it as member type
16 osm.api.referenced.relation <element type> <element ID> get all relations reference this element
17 osm.api.referenced.way <element type> <element ID> get all ways reference this element
18 osm.api.upload.to
19
20 osm.file.cat
21 osm.file.get
22 osm.file.get.full
23 osm.file.query
24 osm.list.ids
25 osm.list.tag
26 osm.list.tags
27
28 osm.get.id
29 osm.query
30 osm.member.relation
31 osm.pbf.update
32 osm.osm.update
33EOF
diff --git a/bin/osm/osm.list.ids b/bin/osm/osm.list.ids
new file mode 100755
index 0000000..8e5d870
--- /dev/null
+++ b/bin/osm/osm.list.ids
@@ -0,0 +1,3 @@
1#! /bin/sh
2
3sed -nr 's/.*<(node|way|relation) id=\"([^"]+)\".*/\1 \2/p'
diff --git a/bin/osm/osm.list.tag b/bin/osm/osm.list.tag
new file mode 100755
index 0000000..76649a0
--- /dev/null
+++ b/bin/osm/osm.list.tag
@@ -0,0 +1,10 @@
1#!/bin/bash
2
3ele_pattern="(node|way|relation)"
4sed -nr "/<$ele_pattern/,/<\/$ele_pattern/ {
5 /<tag k=\"$1\"/ {
6 s/.*v=\"([^\"]+)\".*/\1/
7 h
8 }
9 /<\/$ele_pattern/ {x;p;s/.*//;x}
10}"
diff --git a/bin/osm/osm.list.tags b/bin/osm/osm.list.tags
new file mode 100755
index 0000000..767d32a
--- /dev/null
+++ b/bin/osm/osm.list.tags
@@ -0,0 +1,15 @@
1#!/bin/bash
2
3content=$(cat)
4echo $content | osm.list.ids | tr ' ' ',' > /tmp/osm
5
6for tag in $@
7do
8 echo $content |\
9 osm.list.tag $tag |\
10 paste -d',' /tmp/osm - > /tmp/osm.new &&\
11 mv /tmp/osm.new /tmp/osm
12done
13
14cat /tmp/osm
15echo "\ntag list is also copied into /tmp/osm" > /dev/tty
diff --git a/bin/osm/osm.member.relation b/bin/osm/osm.member.relation
new file mode 100755
index 0000000..f8d4598
--- /dev/null
+++ b/bin/osm/osm.member.relation
@@ -0,0 +1,8 @@
1#! /bin/sh
2
3sed -nr "/<relation/,/<\/relation/ {
4 /<relation/ {s/.* id=\"([^\"]+)\".*/\1/;h}
5 /<member type=\"$1\" ref=\"$2\" role=\"$3\"/ {g;p;q}
6}
7$ {s/.*//;P}
8" | head -1
diff --git a/bin/osm/osm.osc.by_member b/bin/osm/osm.osc.by_member
new file mode 100755
index 0000000..5f9d9be
--- /dev/null
+++ b/bin/osm/osm.osc.by_member
@@ -0,0 +1,31 @@
1#!/bin/bash
2
3while read -r line
4do
5
6 TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type
7 ID=$(echo $line | cut -d ' ' -f2) # field2 is ID
8
9 NEW_MEMBERS=$(echo $line |\
10 cut -d' ' -f3- |\
11 sed -r 's/([0-9]+)/<member type=\"relation\" ref=\"\1\" role=\"subarea\"\/>/g')
12
13 echo $NEW_MEMBERS
14
15 # print matched element with new tags to .osc file
16 cat $1 |\
17 sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ {
18 /<$TYPE id=\"$ID\"/ {
19 s/(version=\"[0-9]+\")(.*)/\1>/
20 a \ \ \ \ $NEW_MEMBERS
21 }
22 p
23 /<\/$TYPE/ q
24 }" >> $1.osc
25done
26
27# Add .osc structure for output
28sed -ir '1 i <osmChange version="0.6" generator="bash script">
29 1 i <modify>
30 $ a </modify>
31 $ a </osmChange>' $1.osc
diff --git a/bin/osm/osm.osc.by_tag b/bin/osm/osm.osc.by_tag
new file mode 100755
index 0000000..cc92c1d
--- /dev/null
+++ b/bin/osm/osm.osc.by_tag
@@ -0,0 +1,45 @@
1#!/bin/bash
2
3# create new tags from input line, for example:
4# field1 field2 field3 field4 field5 field6 field7 field8...
5# [element type] [element ID] key1_added "value1" key2_added "value2" key3_removed key4_removed...
6
7# key should not quoted, value must be quoted
8# And keys which need to be removed must be placed at the end
9while read -r line
10do
11 TYPE=$(echo $line | cut -d ' ' -f1) # field1 is type
12 ID=$(echo $line | cut -d ' ' -f2) # field2 is ID
13
14 # transform key-value pair into tag format:
15 # <tag k="[key]" v="[value]"/>
16 # keys without values are omitted
17 NEW_TAGS=$(echo $line |\
18 cut -d' ' -f3- |\
19 sed -r 's/([^ "]+) (\"[^"]+\")/<tag k=\"\1\" v=\2\/>/g; s/>[^"]*$/>/')
20
21 # get regex pattern need to removed from original osm element:
22 # key1|key2|key3|key4
23 TAG_PATTERN=$(echo $line |\
24 cut -d' ' -f3- | xargs -n2 echo |\
25 cut -d' ' -f1 | paste -s -d'|')
26
27 echo $NEW_TAGS > /dev/tty
28
29 # print matched element with new tags to .osc file
30 cat $1 |\
31 sed -nr "/<$TYPE id=\"$ID\"/,/<\/$TYPE/ {
32 /<$TYPE id=\"$ID\"/ {
33 s/(version=\"[0-9]+\")(.*)/\1>/
34 a \ \ \ \ $NEW_TAGS
35 }
36 /<tag k=\"($TAG_PATTERN)\"/ !p
37 /<\/$TYPE/ q
38 }" >> $1.osc
39done
40
41# Add .osc structure for output
42sed -ir '1 i <osmChange version="0.6" generator="bash script">
43 1 i <modify>
44 $ a </modify>
45 $ a </osmChange>' $1.osc
diff --git a/bin/osm/osm.osm.remove b/bin/osm/osm.osm.remove
new file mode 100755
index 0000000..83d6ea8
--- /dev/null
+++ b/bin/osm/osm.osm.remove
@@ -0,0 +1,9 @@
1#!/bin/bash
2
3while read -r line
4do
5 # put element type and element ID into array
6 array=( $(echo $line) )
7 cat $1 |\
8 sed -i "/<$array[1] id=\"$array[2]\"/,/<\/$array[1]>/ d"
9done
diff --git a/bin/osm/osm.pbf.update b/bin/osm/osm.pbf.update
new file mode 100755
index 0000000..6c6f445
--- /dev/null
+++ b/bin/osm/osm.pbf.update
@@ -0,0 +1,41 @@
1#!/bin/bash
2
3set -e
4
5GEOFABRIK_SERVER=http://download.geofabrik.de/asia/taiwan-updates
6PBF_FILE=$1
7
8# get latest sequence number
9echo Fetching the latest sequence number
10LATEST_SEQ=$(curl --silent http://download.geofabrik.de/asia/taiwan-updates/state.txt |\
11 tail -1 | cut -d'=' -f2)
12echo Latest sequence number is $LATEST_SEQ
13
14# get current sequence number
15SEQ=$(osmium fileinfo $PBF_FILE |\
16 grep osmosis_replication_sequence_number |\
17 cut -d'=' -f2)
18echo File sequence number is $SEQ
19
20# while server has osc file with given sequence number,
21# get it and do file update
22while
23 (( SEQ++ ))
24 [ $SEQ -le $LATEST_SEQ ]
25do
26 mkdir -p changes
27 SEQ_PATH=$(echo $SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/')
28 CHANGE_URL=$GEOFABRIK_SERVER/000/$SEQ_PATH.osc.gz
29 echo $CHANGE_URL
30 curl -o changes/$SEQ.osc.gz $CHANGE_URL && \
31 osmium apply-changes $PBF_FILE changes/$SEQ.osc.gz \
32 --output-header=osmosis_replication_sequence_number=$SEQ \
33 --overwrite \
34 --output $SEQ.osm.pbf
35
36 mv $PBF_FILE $((SEQ-1)).osm.pbf
37 mv $SEQ.osm.pbf $PBF_FILE
38done
39
40echo
41echo File sequence number is $((SEQ-1)), already the latest one on Geofrbrik
diff --git a/bin/osm/osm.query b/bin/osm/osm.query
new file mode 100755
index 0000000..8d0b9f7
--- /dev/null
+++ b/bin/osm/osm.query
@@ -0,0 +1,3 @@
1#!/bin/bash
2
3osmium tags-filter - $@ --input-format=osm --output-format=osm --omit-referenced
diff --git a/bin/osm/sequence_number.sh b/bin/osm/sequence_number.sh
new file mode 100755
index 0000000..eb365d0
--- /dev/null
+++ b/bin/osm/sequence_number.sh
@@ -0,0 +1,22 @@
1#!/bin/bash
2
3# $1 as --hour or --minute, $2 as timestamp
4# return the latest sequence number
5
6case $1 in
7 # hour difference with Tue Jun 4 03:00:00 UTC 2019
8 # sequence number=58940
9 --hour)
10 echo $[($2 - 1559617200)/3600 + 58940]
11 ;;
12
13 # minute difference with latest planet state file
14 --minute)
15 benchmark=benchmark
16 curl https://planet.openstreetmap.org/replication/minute/state > $benchmark
17 timeString=$(tail -1 $benchmark | tr -d 'timestamp=\\')
18 timestamp=$(date -d "$timeString" +%s)
19 seq=$(sed -n 2p $benchmark | tr -d "sequenceNumber=")
20 rm $benchmark
21 echo $[$seq - ($timestamp - $2)/60 - 1 ]
22esac