Re: Help Saving .Tif File after Mask


Luke
 
Edited

rasterio.mask.mask returns a two element tuple - element 0 is the array, element 1 is the transform.  Try something like (untested):

# Mask Raster
masked_raster, transform = rasterio.mask.mask(file, poly, crop=True, filled=True, invert=False)
 
with rasterio.open('/data/my_output.tif', 'w', 
               driver='GTiff',
               height=masked_raster.shape[1], 
               width=masked_raster.shape[2], 
               count=1, 
               dtype=rasterio.ubyte, 
               crs=file.crs, 
               transform=transform
              ) as outfile:
            outfile.write(masked_raster, indexes=1) 
 

Join main@rasterio.groups.io to automatically receive all group messages.