symbol for categorized raster looks like a mask
Find test file attached. The default renderer is a PalettedRenderer because of the QML sidecar. In the Data Views panel category legend looks good. Not sure why it is concidered a mask (?)
Comments (8)
-
reporter -
reporter Note that drag&drop from Data Sources panel into a map view is working fine.
-
Mhhh. @Andreas Rabe the classification.tif cannot be downloaded from Bitbucket
-
- changed status to resolved
resolves
#674- DataSourceRaster().createUnregistereMapLayer() loads default style - DataSourceTreeView().openInMap( ... DEFAULT) tries to get default style from map layer first, GDAL second.→ <<cset e0eb121d141d>>
-
reporter @Benjamin Jakimow looks good now, thanks!
Regarding GDAL Categories: I think you do not have to handle GDAL categories at all. If GDAL categories are available, QGIS will default to a paletted raster renderer. Do you see any case where checking the GDAL categories explicitely is required? At leased I’m fully relying only on QGIS inside my algorithms. Maybe I’m missing something(?)
-
Nope, without a GDAL color table and categories only, a QgsRasterLayer will get a QgsSingleBandGrayRenderer. Try this:
import numpy as np from osgeo import gdal_array, gdal from qgis.core import QgsRasterLayer, QgsPalettedRasterRenderer array = np.asarray([[1,2,3,2], [0,1,1,2]]).astype(np.uint8) path = '/vsimem/myimage.tif' ds: gdal.Dataset = gdal_array.SaveArray(array, path) band: gdal.Band = ds.GetRasterBand(1) band.SetCategoryNames(['none', 'A', 'B', 'C', 'D']) # set True to add colors and get a QgsPalettedRasterRenderer instead if False: ct = gdal.ColorTable() ct.SetColorEntry(0, (0, 0, 0)) ct.SetColorEntry(1, (0, 255, 0)) ct.SetColorEntry(3, (255, 0, 0)) band.SetColorTable(ct) ds.FlushCache() lyr = QgsRasterLayer(path) assert lyr.isValid() renderer = lyr.renderer() print(renderer)
-
reporter You have to prepare a QML file of course
See classification.qml attached.
-
relates to
#166 - Log in to comment
Also, opening the raster via “Open in new map… / Default Colors” is not using the default style from the QML: