Gokul Ganesan | 2020-02-01 |
This article is about serving very large raster data as a custom basemap for mapping or visualisation purposes.
when the area covered by the basemap is very large and the datasize becomes huge if all the tiff image is mosaiced, then we need to mosaic the data using VRT (Virtual Dataset) by utilising gdalbuildvrt utility.
gdalbuildvrt -input_file_list my_list.txt output.vrt
Once the vrt
is created it can be used to generate raster tiles using gdal2tiles utility.
gdal2tiles --zoom 2-15 input.vrt output_folder
output has to be a folder because this utility creates a series of sub folders with a lot of images inside them based on the zoom level and tile id. Here the compression can be set to JPEG/PNG based on the need. This utility also creates a sample html code to show case how to use the created tiles with different apis. Also note that the final created tiles are in TMS
based ids and not XYZ
based ids so they both need to be interchanged based on the API requirement.
Since all the generated tiles are already in proper folder structure all it is need to serve them is a simple file server.
python3 -m http.server <target_port>
once the server is setup the images can be accesed via https://<your.host>/z/x/y.png