Reproject with mask preserving


Denis Rykov
 

Hi there!

I have GeoTIFF files with internal mask and I need to reproject them and not lose mask.

I've found that direct generating warped mask band is not supported by GDAL: https://github.com/OSGeo/gdal/issues/689

rasterio.warp.reproject() also doesn't preserve mask.

How I can use rasterio for achieving what I need? I'm looking for something similar described in this issue but with rasterio.


Sean Gillies
 

Hi Denis,

As you discovered in your post to gdal-dev, GDAL's warper doesn't output internal (or sidecar) mask bands. You must materialize these into an alpha band and then copy the data to produce a new internal mask band.

Here's a test that demonstrates how to create an internal mask band:


While putting together an example of calling reproject() with alpha band creation, I found a bug


When Rasterio 1.0.1 is published to PyPI, you will be able to call reproject() and materialize source's mask band into the destination alpha band specified by the dst_alpha keyword argument as shown in this test:



On Sat, Jul 21, 2018 at 4:45 PM, Denis Rykov <rykovd@...> wrote:
Hi there!

I have GeoTIFF files with internal mask and I need to reproject them and not lose mask.

I've found that direct generating warped mask band is not supported by GDAL: https://github.com/OSGeo/gdal/issues/689

rasterio.warp.reproject() also doesn't preserve mask.

How I can use rasterio for achieving what I need? I'm looking for something similar described in this issue but with rasterio.




--
Sean Gillies