Python – Fixing Terracotta B&W Map Display Issue with GeoTIFF

geotiff-tiffpython

So I installed Terracotta. They have this weird system for naming their files https://terracotta-python.readthedocs.io/en/latest/concepts.html#data-model. So I converted my file into there optimized raster(as stated in the docs) and gave it a filename similar to how they have their files (S2_denmark_20180524_B03.tif) and then had to run :

terracotta serve -r {}_{date}_{band}.tif

in the folder in which my renamed file was.

When I went http://localhost:5001/rgb/2018061/preview.png?r=VV&g=VV&b=VV (my file is called S2_2018061_VV.tif) I got a B&W version of my geoTIFF. I know the bands are meant to be like different colors or something, What band should I pick to get a RGB image instead?

I really don't understand the terracotta filename syntax in general like what exactly are this bands meant for and the type S2. The docs were not very helpful in explaining this and research TIFF bands has not been very helpful.

Terracotta docs
https://terracotta-python.readthedocs.io/en/latest/index.html

tiff
This the gdalinfo output on the file (before the cloud optimize)
enter image description here
This the gdalinfo output on the file (after the cloud optimize)
enter image description here

Best Answer

Terracotta expects your files to have one band each.

The file you started with had three (and apparently they are R, G, B and Alpha). The file you then used had only one so no true color information is left. https://terracotta-python.readthedocs.io/en/latest/cli-commands/optimize-rasters.html explicitly says "Note that all rasters may only contain a single band." so you'd either have to split your file into separate rasters again or re-download the scene at the source where it is probably available as separate files.

Your URL asks for the same file for each band so you are using the same value per pixel three times. Same value on R, G and B means grey scale.

To make it work you need to have one file per band. Name them accordingly and specify them in the request like shown on https://terracotta-python.readthedocs.io/en/latest/concepts.html#data-model

A common pattern, matching Sentinel-2 data standards, would be "B04" for red, "B03" for green and "B02" for blue. Then you can specify them in your URLs: ...?r=B04&g=B03&b=B02

PS: "VV" is used for polarisation bands, I assume you used it by mistake.

Related Question