qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.35k stars 2.98k forks source link

Preserve GRASS raster labels #15249

Open qgib opened 12 years ago

qgib commented 12 years ago

Author Name: Paolo Cavallini (@pcav) Original Redmine Issue: 5742

Redmine category:processing/grass


Of course we can Use raster values as categories, but keeping the labels would be much better. One way would be to pipe directly the two GRASS commands, without exporting in between, but this is not implemented yet.

Notes from Etienne Tourigny: labels could be added as GTIFF metadata, which GDAL supports but I don't know how/if this could be done in GRASS

If the export is using r.out.gdal there must be a way to put/get metadata in a gtiff?

from r.out.gdal:

metaopt=string[,string,...]
Metadata key(s) and value(s) to include
In the form of "META-TAG=VALUE", separate multiple entries with a comma. Not supported by all output format drivers.

Notes from Benjamin Ducke:

Theoretically, it wouldn't be very hard to read the labels from the mapset in which SEXTANTE is storing the (temporary) GRASS datasets; they are saved as plain ASCII there.

However, the host GIS for SEXTANTE must then somehow deal with this additional data in some useful way (e.g. via a virtual raster attribute table).

qgib commented 12 years ago

Author Name: Paolo Cavallini (@pcav)


From Markus Metz, GRASS mailing list:

An alternative would be to make use of the GDAL raster attribute table in both GRASS and QGIS, with the benefit that reading labels for other raster maps imported with GDAL would also be supported.

IIUC, QGIS is currently using GDALGetRasterCategoryNames() which has very limited functionality and supports only integer maps. In a GDAL raster attribute table, as with GRASS-internal categories, floating point values and data ranges are supported, e.g.

min=358.5, max=359.5, name=359 degrees ccw from east

A GDAL raster attribute table would also solve the problem of importing/exporting color rules for floating point data types.

qgib commented 10 years ago

Author Name: Giovanni Manghi (@gioman)


Paolo Cavallini wrote:

From Markus Metz, GRASS mailing list:

An alternative would be to make use of the GDAL raster attribute table in both GRASS and QGIS, with the benefit that reading labels for other raster maps imported with GDAL would also be supported.

IIUC, QGIS is currently using GDALGetRasterCategoryNames() which has very limited functionality and supports only integer maps. In a GDAL raster attribute table, as with GRASS-internal categories, floating point values and data ranges are supported, e.g.

min=358.5, max=359.5, name=359 degrees ccw from east

A GDAL raster attribute table would also solve the problem of importing/exporting color rules for floating point data types.

may be this has been implemented n qgis?

see

8bdaf42dbaec240151eacaa9a28e02f49a53fd66


qgib commented 10 years ago

Author Name: Paolo Cavallini (@pcav)


I think more work has to be done on the Processing side, to add these options to the export command.

qgib commented 9 years ago

Author Name: Giovanni Manghi (@gioman)


qgib commented 9 years ago

Author Name: Giovanni Manghi (@gioman)


qgib commented 8 years ago

Author Name: Médéric RIBREUX (Médéric RIBREUX)


Hello,

after some work on r.category implementation, I've found that in GRASS7 (and only GRASS7), you can use the '-t' parameter for r.out.gdal (command that is internally used by Processing GRASS) to export raster labels. Labels are exported in GDAL Raster Attribute Table (RAT). The RAT takes the form of an xml file named after the raster filename concatenated with '.aux.xml'.

For the moment, QGIS raster provider can't use the values that are in the RAT. The only thing that QGIS uses for rasters are GDAL categories (and only for integer rasters). But we can make Processing GRASS algorithms to export raster labels just by adding the '-t' parameter to every r.out.gdal output (for the default case).

For importing labels and keeping labels, this is a little bit more complex: it seems that only r.in.gdal (which duplicates the raster) can import labels into GRASS7 (but the import is complete from the RAT and very well integrated into GRASS database). Processing uses r.external for raster imports (because it just makes a link to the raster file, there is no data duplication). We have different choices (as far as I can see):

What do you think about this ? Feel free to add any other choice or just your opinion...

qgib commented 8 years ago

Author Name: Paolo Cavallini (@pcav)


IMHO the last option is the best one.

qgib commented 8 years ago

Author Name: Médéric RIBREUX (Médéric RIBREUX)


Ok, I have opened "a ticket into GRASS bugtracker for r.external":https://trac.osgeo.org/grass/ticket/2963...

On QGIS side, we need to add '-t' option for r.out.gdal command in Grass7Algorithm.py. I'll do it once "my global r.* Pull-Request":https://github.com/qgis/QGIS/pull/2865 will be merged.


qgib commented 7 years ago

Author Name: Giovanni Manghi (@gioman)


qgib commented 6 years ago

Author Name: Paolo Cavallini (@pcav)


Still true in Q3


Of course we can Use raster values as categories, but keeping the labels would be much better. One way would be to pipe directly the two GRASS commands, without exporting in between, but this is not implemented yet.

Notes from Etienne Tourigny: labels could be added as GTIFF metadata, which GDAL supports but I don't know how/if this could be done in GRASS

If the export is using r.out.gdal there must be a way to put/get metadata in a gtiff?

from r.out.gdal:

metaopt=string[,string,...]
Metadata key(s) and value(s) to include
In the form of "META-TAG=VALUE", separate multiple entries with a comma. Not supported by all output format drivers.

Notes from Benjamin Ducke:

Theoretically, it wouldn't be very hard to read the labels from the mapset in which SEXTANTE is storing the (temporary) GRASS datasets; they are saved as plain ASCII there.

However, the host GIS for SEXTANTE must then somehow deal with this additional data in some useful way (e.g. via a virtual raster attribute table). to * GRASS raster can have labels (very convenient, e.g. r.param.scale saves feature names along with categories)

Of course we can Use raster values as categories, but keeping the labels would be much better. One way would be to pipe directly the two GRASS commands, without exporting in between, but this is not implemented yet.

Notes from Etienne Tourigny: labels could be added as GTIFF metadata, which GDAL supports but I don't know how/if this could be done in GRASS

If the export is using r.out.gdal there must be a way to put/get metadata in a gtiff?

from r.out.gdal:

metaopt=string[,string,...]
Metadata key(s) and value(s) to include
In the form of "META-TAG=VALUE", separate multiple entries with a comma. Not supported by all output format drivers.

Notes from Benjamin Ducke:

Theoretically, it wouldn't be very hard to read the labels from the mapset in which SEXTANTE is storing the (temporary) GRASS datasets; they are saved as plain ASCII there.

However, the host GIS for SEXTANTE must then somehow deal with this additional data in some useful way (e.g. via a virtual raster attribute table).