From f80b19014b8737e88277beff950bf783a0137d20 Mon Sep 17 00:00:00 2001 From: "Willeke A'Campo (linux vdi)" Date: Tue, 11 Jun 2024 11:19:39 +0200 Subject: [PATCH] add: script to convert gpkg to pmtiles --- scripts/generate_pmtiles.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/generate_pmtiles.sh diff --git a/scripts/generate_pmtiles.sh b/scripts/generate_pmtiles.sh new file mode 100644 index 0000000..e3df279 --- /dev/null +++ b/scripts/generate_pmtiles.sh @@ -0,0 +1,30 @@ +# generate_pmtiles +# Converts a GeoPackage file to PMTiles +# Output PMTiles file can be checked here: https://pmtiles.io/ +# Arguments: +# $1: Path to input GeoPackage file +# $2: Path to output PMTiles file +# $3: Minimum zoom level (e.g. 9) +# $4: Maximum zoom level (e.g. 15, larger than 15 is not recommended) +# $5: Run in Docker container (YES/NO, default: NO) +# $6: Path to data directory (default: $PWD) +# Usage: generate_pmtiles /path/to/input.gpkg /path/to/output.pmtiles 12 15 YES /path/to/data +generate_pmtiles () { + local input=$1 + local output=$2 + local minzoom=$3 + local maxzoom=$4 + local docker=${5:-NO} + local datadir=${6:-$PWD} + + if [ "$docker" = "YES" ] + then + # Run ogr2ogr in a Docker container + echo "Running generate_pmtiles in a Docker container" + docker run --rm -v $PWD:/data osgeo/gdal:alpine-ultrasmall-latest \ + ogr2ogr -skipfailures -f PMTiles "/data/$output" "/data/$input" -dsco MAXZOOM="$maxzoom" -dsco MINZOOM="$minzoom" + else + # Run ogr2ogr directly + ogr2ogr -skipfailures -f PMTiles "$output" "$input" -dsco MAXZOOM="$maxzoom" -dsco MINZOOM="$minzoom" + fi +} \ No newline at end of file