Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
.venv
__pycache__
44 changes: 42 additions & 2 deletions src/pmtiles/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -407,7 +447,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -421,7 +461,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.2"
"version": "3.12.10"
}
},
"nbformat": 4,
Expand Down
34 changes: 34 additions & 0 deletions src/pmtiles/vector/gdb_to_pmtiles_unix.sh
Original file line number Diff line number Diff line change
@@ -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"