I have an ecw file and I want create tile via gdal2tiles.py. The file is as follow:

enter image description here

Note: Green color is style of a polygon layer that is under the ecw layer.

I want to transparent nodata sections in tile generating, How can I do it?

  • 1
    Achieving transparency is possible by multiple approaches. One is alpha-channel, second is no-data value (or null value). GIS software should be able to recognize both and make pixels with these values transparent. So, does your ECW / gdal2tiles.py process have properly defined null value - [-a nodata] ?
    – Miro
    Sep 23 '20 at 6:11
  • Do you mean: gdal2tiles.py -a 255,255,255 -z 18 file.ecw? Sep 23 '20 at 6:18
  • Yes, seems right to me based on your screen. The only downside is that it will make all white transparent. If that is problem for you, you will have to deal with alpha band.
    – Miro
    Sep 23 '20 at 6:23
  • @Miro I test it and result is same Sep 23 '20 at 7:19
  • Do you have QGIS or some other GIS software withinterface which you could use to samle that white are randomly? In QGIS you can do it with info tool. Try multiple places, if the values of white area changes, means there is/was some lossy compression in place. In such case the only way is to create alpha band. If the values are constant, it really should work using the sampled value.
    – Miro
    Sep 23 '20 at 9:58

I had a look into gdal2tiles.py code, and there is commented out part in update_no_data_values function with TODO: gbataille - check the need for this replacement. Seems to work without replace BandMapping tag for NODATA bands....

Well it seems it is not working that well. For now the fastest workaround I could find:

In QGIS top menu use Raster / Miscellaneous / Build Virtual Raster

Select your ECW as input layer, un-check Place each input file into a separate band, and in Advanced parameters add your desired nodata value (space separated) - depending on how many bands you have e.g. 255 255 255 255 (you can find number of bands in layer properties - information tab).

enter image description here

That is all, after that you can run gdal2tiles.py on your created vrt file, using your line from comment: gdal2tiles.py -z 18 file.vrt

You do not have to specify nodata value as it is capable to take it from vrt and make it transparent.

  • There is no input for set nodata value Sep 24 '20 at 5:49
  • @Morteza as written you have to look into Advanced parameters which might be collapsed, so you have to open it to see nodata value input field
    – Miro
    Sep 24 '20 at 6:27
  • Yes I expanded it. See this Sep 24 '20 at 6:45
  • @MortezaMalvandi must be an older version of QGIS which did not supported it yet. I have 3.14. You can achieve the same by copying the gdalbuildvrt command and run it with -srcnodata "255 255 255 255" - unfortunately with change of QGIS to version 3 the command is not editable in place - so this gis.stackexchange.com/questions/273192/…
    – Miro
    Sep 24 '20 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.