Skip to content

Instantly share code, notes, and snippets.

@typebrook
Last active June 11, 2022 04:56
Show Gist options
  • Select an option

  • Save typebrook/11073025dc45ce5b5155d63fed031555 to your computer and use it in GitHub Desktop.

Select an option

Save typebrook/11073025dc45ce5b5155d63fed031555 to your computer and use it in GitHub Desktop.
更新林務局通訊點資訊 #osm #tagging #rudymap #mobile
.ONESHELL:
all: changes.osc
clean:
rm *.osm *.osc
OVERPASS_API := https://overpass.nchc.org.tw/api/interpreter
TAIWAN_BBOX := 20.72799,118.1036,26.60305,122.9312
# 使用NCHC OverPass Server
# 取得臺灣內, information=mobile的通訊點清單
markers.osm:
curl -d @- -X POST $(OVERPASS_API) <<EOF >$@
[out:xml];
node[information=mobile]($(TAIWAN_BBOX));
out meta;
EOF
# 去除外層標籤, 每一筆資料縮為一行
# 將tag operator 取代為internet_access:operator
markers_oneline.osm: markers.osm
xq -x --xml-root=node '.osm.node[] | del(.["@uid"]) | del(.["@timestamp"])' $< | \
sed -Ee 's/中華([^電])/中華電信\1/; s/台哥大/台灣大哥大/; s/遠傳([^電])/遠傳電信\1/' | \
sed -e 's/<tag k="operator"/<tag k="internet_access:operator"/' | \
tr -d '\n' | \
sed -Ee 's/(<\/node>)/\1\n/g' >$@
# 將結果包裏成osmChange file (.osc file)
changes.osc: markers_oneline.osm
cat <<EOF >$@
<osmChange version="0.6" generator="bash script">
<modify>
$$(cat $<)
</modify>
</osmChange>
EOF
# 新建Changeset, 上傳osmChange file, 關閉該Changeset
changeset: changes.osc
curl -fsS https://raw.githubusercontent.com/typebrook/helper/dev/tools/osm/osm.api.changeset.commit | \
bash /dev/stdin $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment