diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd498c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv +.venv +__pycache__ diff --git a/src/pmtiles/main.ipynb b/src/pmtiles/main.ipynb index 8b7d85f..672a93e 100644 --- a/src/pmtiles/main.ipynb +++ b/src/pmtiles/main.ipynb @@ -224,6 +224,34 @@ "!docker run --name pmtiles-converter -d pmtiles" ] }, + { + "cell_type": "markdown", + "id": "de02d6e3", + "metadata": {}, + "source": [ + "Konverterer line endings i shell script fra Windows (CRLF) til Unix (LF) format\n", + "for å unngå problemer i Linux containeren." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "2268b9d9", + "metadata": {}, + "outputs": [], + "source": [ + "# Konverter Windows line endings (CRLF) til Unix line endings (LF)\n", + "with open('vector/gdb_to_pmtiles.sh', 'rb') as f:\n", + " content = f.read()\n", + "\n", + "# Erstatt \\r\\n med \\n\n", + "unix_content = content.replace(b'\\r\\n', b'\\n')\n", + "\n", + "# Skriv tilbake med Unix line endings\n", + "with open('vector/gdb_to_pmtiles_unix.sh', 'wb') as f:\n", + " f.write(unix_content)" + ] + }, { "cell_type": "markdown", "id": "f185cd5d", @@ -242,6 +270,18 @@ "!docker cp ./vector/data/Basisdata_42_Agder_25832_N50Kartdata_FGDB.gdb pmtiles-converter:/app/N50_vektor_agder.gdb " ] }, + { + "cell_type": "code", + "execution_count": 15, + "id": "4d04af79", + "metadata": {}, + "outputs": [], + "source": [ + "# Kopierer det konverterte scriptet (med Unix line endings) inn i containeren\n", + "!docker cp ./vector/gdb_to_pmtiles_unix.sh pmtiles-converter:/app/gdb_to_pmtiles.sh\n", + "!docker exec pmtiles-converter chmod +x /app/gdb_to_pmtiles.sh" + ] + }, { "cell_type": "markdown", "id": "df86617c", @@ -407,7 +447,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "venv", "language": "python", "name": "python3" }, @@ -421,7 +461,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.2" + "version": "3.12.10" } }, "nbformat": 4, diff --git a/src/pmtiles/vector/gdb_to_pmtiles_unix.sh b/src/pmtiles/vector/gdb_to_pmtiles_unix.sh new file mode 100644 index 0000000..f22f510 --- /dev/null +++ b/src/pmtiles/vector/gdb_to_pmtiles_unix.sh @@ -0,0 +1,34 @@ + +#!/bin/bash + +# Usage: ./gdb_to_pmtiles.sh path_to.gdb layer_name output.pmtiles + +set -e + +# --- Arguments --- +GDB_PATH="$1" +LAYER_NAME="$2" +OUTPUT_PMTILES="$3" + +# --- Temporary filenames --- +GEOJSON_FILE="temp_${LAYER_NAME}.geojson" +MBTILES_FILE="temp_${LAYER_NAME}.mbtiles" + +# --- Check requirements --- +command -v ogr2ogr >/dev/null 2>&1 || { echo >&2 "ogr2ogr is required but not installed."; exit 1; } +command -v tippecanoe >/dev/null 2>&1 || { echo >&2 "tippecanoe is required but not installed."; exit 1; } +command -v pmtiles >/dev/null 2>&1 || { echo >&2 "pmtiles CLI is required (npm install -g @maplibre/pmtiles)"; exit 1; } + +echo "🧩 Converting GDB to GeoJSON..." +ogr2ogr -f GeoJSON "$GEOJSON_FILE" "$GDB_PATH" "$LAYER_NAME" -t_srs EPSG:4326 + +echo "🗺️ Creating MBTiles with tippecanoe..." +tippecanoe -o "$MBTILES_FILE" -l "$LAYER_NAME" -zg --drop-densest-as-needed "$GEOJSON_FILE" + +echo "📦 Converting MBTiles to PMTiles..." +pmtiles convert "$MBTILES_FILE" "$OUTPUT_PMTILES" + +echo "✅ Done! PMTiles file created at: $OUTPUT_PMTILES" + +# Optional: Clean up +rm "$GEOJSON_FILE" "$MBTILES_FILE"