Skip to content

Instantly share code, notes, and snippets.

@typebrook
Last active July 31, 2022 00:23
Show Gist options
  • Save typebrook/a42ef5d034a60829f8542cd53d59a149 to your computer and use it in GitHub Desktop.
Save typebrook/a42ef5d034a60829f8542cd53d59a149 to your computer and use it in GitHub Desktop.
[rudymap-wiki] Parse rudymap mapsforge style file and create a Markdown #mapsforge #rudymap
all: detail-layers detail-cats
MOI_OSM.xml:
curl -o $@ https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/MOI_OSM.xml
rudymap.json: MOI_OSM.xml
xq . <$< >$@
layers: rudymap.json
@jq -r '.rendertheme.stylemenu.layer | map(select(has("overlay"))) + map(select(has("overlay") | not)) | .[] | .["@id"]' $< | tee $@
cats: rudymap.json
@jq -r '.rendertheme.rule[] | .. | objects | .["@cat"]? | strings' $< | sort -u | tee $@
test: rudymap.json
@jq -cr '.rendertheme.stylemenu.layer[] | {"name": .name[] | select(.["@lang"] == "zh") | .["@value"], "enabled": .["@enabled"]?, "visible": .["@visible"]?}' <$<
layer-%: rudymap.json
@echo
@echo '## $*'
@jq -cr '.rendertheme.stylemenu.layer[] | select(.id == "$*") | .name[] | select(.["@lang"] == "zh") | .["@value"]' $< | sed 's/v__version__//g' | sed 's/^/- 圖層名稱: /g'
@jq -cr '.rendertheme.stylemenu.layer[] | path(.overlay? | .. | select(objects | .["@id"]? == "$*")) as $$p | " - [" + .["@id"] + "](#" + .["@id"] + ")"' $< | sed '1i - 引用於'
@jq -cr '.rendertheme.stylemenu.layer[] | select(.["@id"] == "$*") | select(.["@visible"]? == "false") | "- 不可見"' $<
@jq -cr '.rendertheme.stylemenu.layer[] | select(.["@id"] == "$*" and has("overlay")) | .overlay[] | .["@id"]' $< | sort | sed 's/.*/ - [&](#&)/g' | sed '1i - 子圖層(sublayers)'
@jq -cr '.rendertheme.stylemenu.layer[] | select(.["@id"] == "$*") | .cat? | if type == "object" then . else .[] end | .["@id"]' $< | sort | sed 's/.*/ - [&](#&)/g' | sed '1i - 包含類別'
rule-%: rudymap.json
@echo
@echo '## $*'
@jq -cr '.rendertheme.stylemenu.layer[] | path(.. | select(objects | .["@id"]? == "$*")) as $$p | " - [" + .["@id"] + "](#" + .["@id"] + ")"' $< | sed '1i - 引用於'
@jq -cr '(path(.. | select(objects | .["@cat"] == "$*")) | [while(length != 0; .[0:-1])] | reverse) as $$p | [getpath($$p[]) | select(objects | has("@k"))] | map([.["@cat"]?, .["@k"], .["@v"]] | del(.[] | nulls)) + [.[-1].rule? | select(. != null) | arrays | map([.["@cat"]?, .["@k"], .["@v"]] | del(.[] | nulls))] | map(tostring) | @tsv' $< | sed 's/~/none/g'| sed 's/\t/ -> /g' | sed 's/.*/`&`/g' | sed 's/^/- /g'
detail-layers: layers
@echo '# 圖層'
@cat $< | xargs -i $(MAKE) -s layer-{} | tee $@
detail-cats: cats
@echo '# 規則'
@cat $< | xargs -i $(MAKE) -s rule-{} | tee $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment