User:Gitouche/gdal2tiles

From OpenStreetMap Wiki
Jump to navigation Jump to search

2020

These notes are from 2017. What's new in 2020?

  • gdal2tiles-multiprocess.py is now python3 compatible and might not need patching anymore.

Summary

  1. Download geotagged imagery and find out the projection used.
  2. Use the virtual dataset .vrt format to describe any needed transformations :
    • Compose the full image from multiple files.
    • Correct projection.
  3. Generate TMS tiles
  4. Convert tiles from .png to .jpeg to free up space.

Requirements

  • From CentOS7 (python2.7)
yum install -y gdal python-gdal python-pillow ImageMagick
  • Get gdal2tiles-multiprocess.py from gdal2tiles-leaflet project
wget https://raw.githubusercontent.com/commenthol/gdal2tiles-leaflet/master/gdal2tiles-multiprocess.py

Workflow

Data Sources

Source imagery is 528 .jpg files each covering 1*1.4km. Total = 13GiB.
Each .jpg file has an associated .jgw containing the corresponding geodata.

-> Download them all (.jpg and .jgw) in one folder.

  • Projection : from this website, we find out projection is "EPSG:RGF93 / CC45 (EPSG:3945)"

Prepare the data

  • Combine all images into one virtual dataset bm2016.vrt
gdalbuildvrt bm2016.vrt *.jpg
  • Correct projection : output needs to be EPSG:3857. bm2016-proj.vrt
 gdalwarp -s_srs EPSG:3945 -t_srs EPSG:3857 -of VRT bm2016.vrt bm2016-proj.vrt

Generate tiles from .vrt file

Syntax is

gdal2tiles-multiprocess.py -r <resampling_algorithm> --tmscompatible -z <minzoom>-<maxzoom> -s <source_projection> <source_file> <output_folder>

I used

mkdir OUTPUT
time python gdal2tiles-multiprocess.py -r antialias -d -z 14-20 -s EPSG:3857 bm2016-proj.vrt OUTPUT/

Now let's be patient, the more CPU cores the better...

Convert all tiles to .jpg

All previously tiles are generated as .png files. We can compress to .jpg without noticeable loss in quality.

 find OUTPUT/ -name '*.png' -exec mogrify -format jpg {} \;
 find OUTPUT/ -name '*.png' -delete 

EOF