Processing orthophotomap
This is a summary of all the steps I did to process the orthophotomap
I downloaded the orthophotomap from here
Dilsen-Stokkem is code 72041
The download contains a jp2 file of 900MB
Qgis
With qgis you view the map
Create tiles
I converted the jp2 files to tiles using the following commands
Create a tif file
Crop using Lambert72 bounds, reproject to Web Mercator
gdalwarp \
-te_srs EPSG:31370 \
-te 244492 188891 245434 190782 \
-t_srs EPSG:3857 \
-r bilinear \
-dstalpha \
-co TILED=YES -co COMPRESS=JPEG -co BIGTIFF=YES \
OMWRGB25VL_72041.jp2 track_3857.tif
Create multi level tiles
gdal2tiles.py --xyz -z 17-20 -r bilinear -w none \
hometown_3857.tif tiles_xyz
convert to jpg
#!/usr/bin/env bash
# Build XYZ tiles from a raster using GDAL, then convert PNG tiles to JPEG and remove PNGs.
# Defaults: z=17-19, tilesize=512, resampling=near, quality=80, processes=$(nproc)
# Usage:
# ./build_xyz_jpeg_tiles.sh <input.tif> <output_dir> [zoom_levels]
# Example:
# ./build_xyz_jpeg_tiles.sh hometown_3857.tif tiles_xyz_512_jpeg 17-19
set -euo pipefail
# ---- Inputs & defaults ----
INPUT="${1:-}"
OUT_DIR="${2:-}"
ZOOM="${3:-17-19}"
TILESIZE="${TILESIZE:-512}"
RESAMPLING="${RESAMPLING:-near}" # near | bilinear | cubic | lanczos ...
QUALITY="${QUALITY:-80}" # JPEG quality 1..100
PROCESSES="${PROCESSES:-$(nproc)}"
if [[ -z "$INPUT" || -z "$OUT_DIR" ]]; then
echo "Usage: $0 <input.tif> <output_dir> [zoom_levels]"
echo "Env overrides: TILESIZE=${TILESIZE} RESAMPLING=${RESAMPLING} QUALITY=${QUALITY} PROCESSES=${PROCESSES}"
exit 1
fi
# ---- Dependency checks ----
command -v gdal2tiles.py >/dev/null 2>&1 || { echo "Error: gdal2tiles.py not found in PATH."; exit 1; }
command -v mogrify >/dev/null 2>&1 || { echo "Error: mogrify (ImageMagick) not found in PATH."; exit 1; }
command -v find >/dev/null 2>&1 || { echo "Error: find not available."; exit 1; }
command -v xargs >/dev/null 2>&1 || { echo "Error: xargs not available."; exit 1; }
# ---- Build PNG XYZ tiles with GDAL ----
echo "==> Tiling with GDAL"
echo " Input: $INPUT"
echo " Output dir: $OUT_DIR"
echo " Zoom: $ZOOM"
echo " Tilesize: $TILESIZE"
echo " Resampling: $RESAMPLING"
echo " Processes: $PROCESSES"
mkdir -p "$OUT_DIR"
gdal2tiles.py --xyz -z "$ZOOM" \
--tilesize="$TILESIZE" \
--processes="$PROCESSES" \
-r "$RESAMPLING" -w none \
"$INPUT" "$OUT_DIR"
# ---- Convert PNG -> JPEG in place ----
echo "==> Converting PNG -> JPEG (quality=$QUALITY) using $PROCESSES processes"
# Only attempt conversion if there are PNGs
if find "$OUT_DIR" -type f -name '*.png' -print -quit | grep -q .; then
# Use mogrify to write .jpg next to each .png
# -print0/-0 handles spaces/newlines safely; -P parallelizes conversion.
find "$OUT_DIR" -type f -name '*.png' -print0 \
| xargs -0 -P "$PROCESSES" mogrify -format jpg -quality "$QUALITY"
echo "==> Removing original PNG tiles"
find "$OUT_DIR" -type f -name '*.png' -delete
else
echo "No PNG tiles found to convert—nothing to do."
fi
echo "==> Done."
echo "JPEG tiles are in: $OUT_DIR"