[gdal-dev] SetNoDataValue on in-memory datasets via python

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] SetNoDataValue on in-memory datasets via python

Jacob Adams
I think I've found a bug in the python bindings, but I want to run it by the list before I open a ticket to make sure I'm not missing anything (I'm assuming you'd rather I check it out on the list first rather than cluttering the ticket system with bugs that aren't actually bugs).

Environment: gdal 2.2.3, python 3.6, installed from conda-forge via Anaconda Navigator.

I'm creating an in-memory raster to pass to DEMProcessing() to create a hillshade like thus:

    mem_s_fh = gdal.GetDriverByName("MEM").Create('', temp_cols, temp_rows, 1, gdal.GDT_Float32)
    mem_s_fh.SetGeoTransform([0, cell_size, 0, 0, 0, cell_size])
    mem_s_fh.SetNoDataValue(s_nodata)
    s_band = mem_s_fh.GetRasterBand(1)
    s_band.WriteArray(in_array)

Which then bombs out on setting NoData with this error:

Traceback (most recent call last):
  File "i:\git\dem_smooth.py", line 299, in <module>
    smooth(smooth_dem, hs_dem, window_size, "hillshade", filter_f, t, n, v)
  File "i:\git\dem_smooth.py", line 232, in smooth
    new_data = hillshade(super_array)
  File "i:\git\dem_smooth.py", line 91, in hillshade
    mem_s_fh.SetNoDataValue(s_nodata)
  File "C:\Users\jadams\AppData\Local\conda\conda\envs\gdal\lib\site-packages\osgeo\gdal.py", line 1804, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, Dataset, name)
  File "C:\Users\jadams\AppData\Local\conda\conda\envs\gdal\lib\site-packages\osgeo\gdal.py", line 74, in _swig_getattr
    return _swig_getattr_nondynamic(self, class_type, name, 0)
  File "C:\Users\jadams\AppData\Local\conda\conda\envs\gdal\lib\site-packages\osgeo\gdal.py", line 69, in _swig_getattr_nondynamic
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'

My searching turns up this ticket in Swig, but I have no idea if it's relevant or not: https://github.com/swig/swig/issues/588.

I've tried this under python 2.7 and 3.6 with the same result. Trying it under gdal 2.1.3 gives an "Attribute Error: 'Dataset' object has no attribute value 'SetNoDataValue'" error. s_nodata is set previously, and I've verified it holds the right value (when using SetNoDataValue on my GTiff output raster it works as expected). The MEM driver documentation says memory datasets should support nodata values, and the difference in error messages between 2.2.3 and 2.1.3 seems to indicate this has been implemented. The script runs fine if I comment out the SetNoDataValues() call.

Jake Adams

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: SetNoDataValue on in-memory datasets via python

Even Rouault-2

Jake,

 

>

> mem_s_fh = gdal.GetDriverByName("MEM").Create('', temp_cols, temp_rows,

> 1, gdal.GDT_Float32) mem_s_fh.SetGeoTransform([0, cell_size, 0, 0, 0,

> cell_size])

> mem_s_fh.SetNoDataValue(s_nodata)

 

SetNoDataValue() is a rasterband level method, not dataset.

 

So should be s_band.SetNoDataValue(s_nodata)

 

> s_band = mem_s_fh.GetRasterBand(1)

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: SetNoDataValue on in-memory datasets via python

Jacob Adams
*facepalm*

Happy Monday, everyone.

Jake
>>> Even Rouault <[hidden email]> 12/18/2017 11:04 AM >>>
Jake,
 
>
> mem_s_fh = gdal.GetDriverByName("MEM").Create('', temp_cols, temp_rows,
> 1, gdal.GDT_Float32) mem_s_fh.SetGeoTransform([0, cell_size, 0, 0, 0,
> cell_size])
> mem_s_fh.SetNoDataValue(s_nodata)
 
SetNoDataValue() is a rasterband level method, not dataset.
 
So should be s_band.SetNoDataValue(s_nodata)
 
> s_band = mem_s_fh.GetRasterBand(1)
 
Even
 
--
Spatialys - Geospatial professional services
http://www.spatialys.com

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev