[Qgis-developer] Strange behaviour of the QgsRasterNuller
Alexander Bruy
alexander.bruy at gmail.com
Wed Dec 23 06:36:55 PST 2015
Hi all,
I noticed strange behavior of the QgsRasterNuller when saving paletted
singleband raster to GeoTiff format. If input raster has no NODATA value, then
output raster will have NODATA value set to 0, even if such values
are not defined in the QgsRasterNuller.
Not sure is this bug or maybe I'm doing something wrong. Tested with
landcover.img layer from QGIS test dataset [0]. Here is my code
from qgis.core import *
outPath = '/tmp/test.tif'
layer = iface.mapCanvas().currentLayer()
provider = layer.dataProvider()
writer = QgsRasterFileWriter(outPath)
writer.setOutputFormat('GTiff')
pipe = QgsRasterPipe()
if not pipe.set(provider.clone()):
print 'Cannot set pipe provider'
nuller = QgsRasterNuller()
for band in xrange(1, provider.bandCount() + 1):
nuller.setNoData(band, [])
if not pipe.insert(1, nuller):
print 'Cannot set pipe nuller'
projector = QgsRasterProjector()
projector.setCRS(layer.crs(), layer.crs())
if not pipe.insert(2, projector):
print 'Cannot set pipe projector'
writer.writeRaster(pipe, layer.width(), layer.height(),
layer.extent(), layer.crs())
result = QgsRasterLayer(outPath, 'converted', 'gdal')
QgsMapLayerRegistry.instance().addMapLayer(result)
Any ideas what is wrong?
[0] http://qgis.org/downloads/data/qgis_sample_data.zip
Thanks
--
Alexander Bruy
More information about the Qgis-developer
mailing list