[GRASS-SVN] r69476 - grass/branches/releasebranch_7_2/raster/r.out.gdal
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 13 14:12:02 PDT 2016
Author: mmetz
Date: 2016-09-13 14:12:02 -0700 (Tue, 13 Sep 2016)
New Revision: 69476
Modified:
grass/branches/releasebranch_7_2/raster/r.out.gdal/attr.c
Log:
r.out.gdal: try to keep the raster attribute table as simple as possible (backport from trunk r69131)
Modified: grass/branches/releasebranch_7_2/raster/r.out.gdal/attr.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.out.gdal/attr.c 2016-09-13 20:49:43 UTC (rev 69475)
+++ grass/branches/releasebranch_7_2/raster/r.out.gdal/attr.c 2016-09-13 21:12:02 UTC (rev 69476)
@@ -54,38 +54,88 @@
* what to do for a cell value that has a category but no color rule ?
* what to do for a cell value that has a color rule but no category ?
*/
- if (cats.ncats > 0) { /* && rcount == 0 */
- /* create new raster attribute table */
- hrat = GDALCreateRasterAttributeTable();
-
- if (maptype == CELL_TYPE) {
- GDALRATCreateColumn(hrat, "min", GFT_Integer, GFU_Min);
- GDALRATCreateColumn(hrat, "max", GFT_Integer, GFU_Max);
- }
- else {
- GDALRATCreateColumn(hrat, "min", GFT_Real, GFU_Min);
- GDALRATCreateColumn(hrat, "max", GFT_Real, GFU_Max);
- }
- GDALRATCreateColumn(hrat, "label", GFT_String, GFU_Name);
+ if (cats.ncats > 0) {
+ int use_minmax = 0;
- GDALRATSetRowCount(hrat, cats.ncats);
-
if (maptype == CELL_TYPE) {
for (i = 0; i < cats.ncats; i++) {
label = Rast_get_ith_c_cat(&cats, i, &CellMin, &CellMax);
- GDALRATSetValueAsInt(hrat, i, 0, CellMin);
- GDALRATSetValueAsInt(hrat, i, 1, CellMax);
- GDALRATSetValueAsString(hrat, i, 2, label);
+ if (CellMin != CellMax) {
+ use_minmax = 1;
+ break;
+ }
}
}
else {
for (i = 0; i < cats.ncats; i++) {
label = Rast_get_ith_d_cat(&cats, i, &dfCellMin, &dfCellMax);
- GDALRATSetValueAsDouble(hrat, i, 0, dfCellMin);
- GDALRATSetValueAsDouble(hrat, i, 1, dfCellMax);
- GDALRATSetValueAsString(hrat, i, 2, label);
+ if (dfCellMin != dfCellMax) {
+ use_minmax = 1;
+ break;
+ }
}
}
+
+ /* create new raster attribute table */
+ hrat = GDALCreateRasterAttributeTable();
+
+ if (use_minmax) {
+ if (maptype == CELL_TYPE) {
+ GDALRATCreateColumn(hrat, "min", GFT_Integer, GFU_Min);
+ GDALRATCreateColumn(hrat, "max", GFT_Integer, GFU_Max);
+ }
+ else {
+ GDALRATCreateColumn(hrat, "min", GFT_Real, GFU_Min);
+ GDALRATCreateColumn(hrat, "max", GFT_Real, GFU_Max);
+ }
+ GDALRATCreateColumn(hrat, "label", GFT_String, GFU_Name);
+
+ GDALRATSetRowCount(hrat, cats.ncats);
+
+ if (maptype == CELL_TYPE) {
+ for (i = 0; i < cats.ncats; i++) {
+ label = Rast_get_ith_c_cat(&cats, i, &CellMin, &CellMax);
+ GDALRATSetValueAsInt(hrat, i, 0, CellMin);
+ GDALRATSetValueAsInt(hrat, i, 1, CellMax);
+ GDALRATSetValueAsString(hrat, i, 2, label);
+ }
+ }
+ else {
+ for (i = 0; i < cats.ncats; i++) {
+ label = Rast_get_ith_d_cat(&cats, i, &dfCellMin, &dfCellMax);
+ GDALRATSetValueAsDouble(hrat, i, 0, dfCellMin);
+ GDALRATSetValueAsDouble(hrat, i, 1, dfCellMax);
+ GDALRATSetValueAsString(hrat, i, 2, label);
+ }
+ }
+ }
+ else {
+ if (maptype == CELL_TYPE) {
+ GDALRATCreateColumn(hrat, "value", GFT_Integer, GFU_MinMax);
+ }
+ else {
+ GDALRATCreateColumn(hrat, "value", GFT_Real, GFU_MinMax);
+ }
+ GDALRATCreateColumn(hrat, "label", GFT_String, GFU_Name);
+
+ GDALRATSetRowCount(hrat, cats.ncats);
+
+ if (maptype == CELL_TYPE) {
+ for (i = 0; i < cats.ncats; i++) {
+ label = Rast_get_ith_c_cat(&cats, i, &CellMin, &CellMax);
+ GDALRATSetValueAsInt(hrat, i, 0, CellMin);
+ GDALRATSetValueAsString(hrat, i, 1, label);
+ }
+ }
+ else {
+ for (i = 0; i < cats.ncats; i++) {
+ label = Rast_get_ith_d_cat(&cats, i, &dfCellMin, &dfCellMax);
+ GDALRATSetValueAsDouble(hrat, i, 0, dfCellMin);
+ GDALRATSetValueAsString(hrat, i, 1, label);
+ }
+ }
+ }
+
if (GDALSetDefaultRAT(hBand, hrat) != CE_None) {
G_warning(_("Failed to set raster attribute table"));
ret = -1;
More information about the grass-commit
mailing list