Re: Implementing -scale functionality of gdal_translate


Sean Gillies
 

Hi,

I apologize for being slow to reply, I've been occupied with fixing bugs in the last couple of releases.

In theory it is possible to add an option to the read method which will cast the data because GDAL already supports this well in versions 2 and up. I haven't pursued this because converting unsigned int to float is trivial, if not cheap, with numpy:

   data = dataset.read().astype('float64')

And if you pass masked=True to read, you'll get a masked array and then can apply a fill_value of numpy.nan under the invalid data mask. Is this useful for you or have you already been down this path?

GDAL's data type casting would not produce an extra copy of the data and so would be optimal for some applications.


On Tue, Feb 5, 2019 at 11:09 AM <linden.kyle@...> wrote:
Ok, so it appears the issue was that I was attempting to do a windowed read outside the bounds of the geotiff (for TMS edge tiles) and `src.read()` was only returning the data inside the bounds since I wasn't using the `boundless=True` option. However, the next problem I am running into is that I'd like to use `fill_value=numpy.nan` to fill in the edge data with NaN values. However, my data is UInt8. Is there any way to specify an option to cast the data read by the call to `read()` into float32 so that I can support this?



--
Sean Gillies

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