Skip to content

Commit

Permalink
Add support for Garmin
Browse files Browse the repository at this point in the history
  • Loading branch information
frafra committed Mar 3, 2024
1 parent e1c159c commit 4b37421
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ $(WEBAPP_DIR)/%.json: $(TOPOJSON_DIR)/%.json

webapp: $(WEBAPP_DIR)/municipalities.json $(WEBAPP_DIR)/limits_IT_regions.json $(WEBAPP_DIR)/limits_IT_provinces.json

include garmin.mk

clean:
rm -rf $(WORK_DIR)
101 changes: 101 additions & 0 deletions backend/garmin.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Makefile based on https://github.com/lucadelu/ital.img by Luca Delucchi

MKGMAP_URL ?= https://www.mkgmap.org.uk/download/mkgmap-r4917.tar.gz
MKGMAP_DIR = $(WORK_DIR)/mkgmap
MKGMAP = $(MKGMAP_DIR)/mkgmap.jar
MKGMAP_XMX = 8G
MKGMAP_PRIORITY = 10
SPLITTER_URL ?= https://www.mkgmap.org.uk/download/splitter-r653.jar
SPLITTER = $(MKGMAP_DIR)/splitter.jar
SEA_URL = https://www.thkukuk.de/osm/data/sea-latest.zip
SEA_DIR = $(MKGMAP_DIR)/sea
SEA = $(SEA_DIR)/.dirstamp
BOUNDS_URL = https://www.thkukuk.de/osm/data/bounds-latest.zip
BOUNDS_DIR = $(MKGMAP_DIR)/bounds
BOUNDS = $(BOUNDS_DIR)/.dirstamp

REPO_URL = https://github.com/lucadelu/ital.img.git
REPO_DIR = $(MKGMAP_DIR)/ital.img
REPO = $(REPO_DIR)/.git/HEAD
STYLES = styles/.directory
STYLES_DIR = $(REPO_DIR)/$(dir $(STYLES))

NATION = $(notdir $(patsubst %/,%,$COUNTRY))

.PHONY: setup_garmin garmin_regioni

$(MKGMAP):
$(dir_guard)
curl -s "$(MKGMAP_URL)" | bsdtar --strip-components 1 -xf- -C "$(MKGMAP_DIR)"

$(SPLITTER): $(MKGMAP)
curl -s "$(SPLITTER_URL)" -o "$@"

$(SEA):
$(dir_guard)
curl -s "$(SEA_URL)" | bsdtar --strip-components 1 -xf- -C "$(SEA_DIR)"
touch $@

$(BOUNDS):
$(dir_guard)
curl -s "$(BOUNDS_URL)" | bsdtar -xf- -C "$(BOUNDS_DIR)"
touch $@

$(REPO):
cd $(dir $(REPO_DIR)) && git clone -n --depth=1 --filter=tree:0 $(REPO_URL) $(notdir $(REPO_DIR))

$(STYLES): $(REPO)
cd $(REPO_DIR) && git sparse-checkout set --no-cone $(dir $(STYLES))
cd $(REPO_DIR) && git checkout

setup_garmin: $(MKGMAP) $(SPLITTER) $(SEA) $(BOUNDS) $(STYLES)
setup: setup_garmin

PBF_FILES_REGIONI = $(wildcard $(PBF_DIR)/regioni/*.osm.pbf)
garmin_regioni: $(subst /pbf/,/garmin/,$(PBF_FILES_REGIONI:.osm.pbf=.tar.gz))
all: garmin_regioni

.NOTPARALLEL:
.ONESHELL:
$(OUTPUT)/garmin/%.tar.gz: $(PBF_DIR)/%.osm.pbf
$(dir_guard)
set -eux
area_id=$(basename $@ .tar)
area_name="${area_id#*_}"
trap "rm -rf "$@".temp/" EXIT
java -Xmx"$(MKGMAP_XMX)" -jar "$(SPLITTER)" \
--max-areas=4096 --max-nodes=3000000 --wanted-admin-level=8 \
--output-dir="$@".temp/ "$<"
java -Xmx"$(MKGMAP_XMX)" -jar "$(MKGMAP)" \
--style-file="$(STYLES_DIR)/general" \
--latin1 \
--country-name=Italia \
--country-abbr="$(NATION)" \
--region-name="$(area_name)" \
--area-name="$(area_name)" \
--family-name="Mappe regionali ital.img" \
--description="$(area_name)" \
--precomp-sea="$(SEA_DIR)" \
--generate-sea \
--bounds="$(BOUNDS_DIR)" \
--max-jobs \
--route \
--drive-on=detect,right \
--process-destination \
--process-exits \
--location-autofill=is_in,nearest \
--index \
--split-name-index \
--housenumbers \
--add-pois-to-areas \
--link-pois-to-ways \
--preserve-element-order \
--verbose \
--name-tag-list=name,name:it,loc_name,reg_name,nat_name \
--draw-priority="$(MKGMAP_PRIORITY)" \
--reduce-point-density=3.2 \
--make-opposite-cycleways \
--gmapsupp \
--output-dir="$@".temp/ \
"$@".temp/*.osm.pbf
tar -czf "$@" "$@".temp/gmapsupp.img
3 changes: 2 additions & 1 deletion backend/scripts/topojson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ select json_object(
'adm', admin_level,
'.osm.pbf', 'pbf/regioni/' || filename || '.osm.pbf',
'.gpkg', 'gpkg/regioni/' || filename || '.gpkg',
'.obf', 'obf/regioni/' || filename || '.obf'
'.obf', 'obf/regioni/' || filename || '.obf',
'.tar.gz', 'garmin/regioni/' || filename || '.tar.gz'
)
))
)
Expand Down
2 changes: 2 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pkgs.mkShellNoCC {
# mapshaper and topojson
nodePackages.npm
nodejs-slim_21
# garmin styles
git
];
shellHook = ''
export LD_LIBRARY_PATH="${lib-path}"
Expand Down

0 comments on commit 4b37421

Please sign in to comment.