QGIS3 has a tool called 'gdal2tiles.py' which can generate map tiles, but currently, it only supports TMS, not XYZ. However, QGIS3 loads XYZ by default and requires checkbox for TMS, so it's better to convert TMS to XYZ.
The difference between TMS and XYZ is just the name of Y-coordinate, so renaming works well. tms2xyz.py is a script for that.
Suppose you have raster images with world files.
- Generate GeoTIFF files
This command converts an image to GeoTIFF. It's better to iterate files using shell script if you have many files.
gdal_translate -of GTiff -a_srs EPSG:{src-srs-number} {input-image-name} {output-tiff-name}
- Merge GeoTIFF files to one file
First, list up file names of .tiff files.
- Windows:
dir /B {tiff-dir-name}\*.tiff > list.txt
- Linux:
ls {tiff-dir-name} | grep '.tiff' > list.txt
Then, create VRT(Virtual Dataset). This is probably the fastest way to merge.
gdalbuildvrt -o merge.vrt -input_file_list list.txt
Finally, create a merged GeoTIFF file from VRT.
gdal_translate -ot Byte -co COMPRESS=LZW -co BIGTIFF=YES merge.vrt merge.tiff
- Convert GeoTIFF to tiles
This command converts the merged GeoTIFF file to TMS tiles.
gdal2tiles -r "bilinear" -s "EPSG:{src-srs-number}" -z "16-20" --processes=8 merge.tiff tms-tiles
- Convert TMS to XYZ
This command converts TMS tiles to XYZ tiles.
python tms2xyz.py tms-tiles xyz-tiles
See the following links for more options of GDAL commands.
newer version of
gdal2tiles
has an option--xyz
to generate XYZ tiles