[GRASS-SVN] r71665 - grass/trunk/raster/r.out.gdal
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Nov 11 03:47:46 PST 2017
Author: mmetz
Date: 2017-11-11 03:47:46 -0800 (Sat, 11 Nov 2017)
New Revision: 71665
Modified:
grass/trunk/raster/r.out.gdal/export_band.c
grass/trunk/raster/r.out.gdal/local_proto.h
grass/trunk/raster/r.out.gdal/main.c
Log:
r.out.gdal: export inf values
Modified: grass/trunk/raster/r.out.gdal/export_band.c
===================================================================
--- grass/trunk/raster/r.out.gdal/export_band.c 2017-11-11 11:27:38 UTC (rev 71664)
+++ grass/trunk/raster/r.out.gdal/export_band.c 2017-11-11 11:47:46 UTC (rev 71665)
@@ -18,8 +18,9 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-#include "cpl_string.h"
-#include "gdal.h"
+#include <gdal.h>
+#include <cpl_string.h>
+#include <cpl_port.h>
#include "local_proto.h"
int exact_range_check(double, double, GDALDataType, const char *);
@@ -75,17 +76,23 @@
Rast_get_row(fd, bufer, row, maptype);
for (col = 0; col < cols; col++) {
- if (Rast_is_f_null_value(&((FCELL *) bufer)[col])) {
+ FCELL fval = ((FCELL *) bufer)[col];
+
+ if (Rast_is_f_null_value(&fval)) {
+ ((FCELL *) bufer)[col] = fnullval;
n_nulls++;
}
else {
- if (((FCELL *) bufer)[col] == fnullval) {
+ if (fval == fnullval) {
nodatavalmatch = 1;
}
- if (dfCellMin > ((FCELL *) bufer)[col])
- dfCellMin = ((FCELL *) bufer)[col];
- if (dfCellMax < ((FCELL *) bufer)[col])
- dfCellMax = ((FCELL *) bufer)[col];
+ if (!CPLIsInf(fval)) {
+ /* ignore inf */
+ if (dfCellMin > fval)
+ dfCellMin = fval;
+ if (dfCellMax < fval)
+ dfCellMax = fval;
+ }
}
}
G_percent(row + 1, rows, 2);
@@ -101,18 +108,23 @@
Rast_get_row(fd, bufer, row, maptype);
for (col = 0; col < cols; col++) {
- if (Rast_is_d_null_value(&((DCELL *) bufer)[col])) {
+ DCELL dval = ((DCELL *) bufer)[col];
+
+ if (Rast_is_d_null_value(&dval)) {
((DCELL *) bufer)[col] = dnullval;
n_nulls++;
}
else {
- if (((DCELL *) bufer)[col] == dnullval) {
+ if (dval == dnullval) {
nodatavalmatch = 1;
}
- if (dfCellMin > ((DCELL *) bufer)[col])
- dfCellMin = ((DCELL *) bufer)[col];
- if (dfCellMax < ((DCELL *) bufer)[col])
- dfCellMax = ((DCELL *) bufer)[col];
+ if (!CPLIsInf(dval)) {
+ /* ignore inf */
+ if (dfCellMin > dval)
+ dfCellMin = dval;
+ if (dfCellMax < dval)
+ dfCellMax = dval;
+ }
}
}
G_percent(row + 1, rows, 2);
@@ -229,6 +241,9 @@
return -1;
}
+ if (!no_metadata)
+ GDALSetDescription(hBand, name);
+
/* Get min/max values. */
if (Rast_read_fp_range(name, mapset, &sRange) == -1) {
bHaveMinMax = FALSE;
Modified: grass/trunk/raster/r.out.gdal/local_proto.h
===================================================================
--- grass/trunk/raster/r.out.gdal/local_proto.h 2017-11-11 11:27:38 UTC (rev 71664)
+++ grass/trunk/raster/r.out.gdal/local_proto.h 2017-11-11 11:47:46 UTC (rev 71665)
@@ -1,7 +1,7 @@
#ifndef __LOCAL_PROTO_H__
#define __LOCAL_PROTO_H__
-#include "gdal.h"
+#include <gdal.h>
/* range limits */
/*
Modified: grass/trunk/raster/r.out.gdal/main.c
===================================================================
--- grass/trunk/raster/r.out.gdal/main.c 2017-11-11 11:27:38 UTC (rev 71664)
+++ grass/trunk/raster/r.out.gdal/main.c 2017-11-11 11:47:46 UTC (rev 71665)
@@ -30,7 +30,9 @@
#include <grass/glocale.h>
#include <grass/dbmi.h>
-#include "cpl_string.h"
+#include <cpl_string.h>
+#include <cpl_port.h>
+
#include "local_proto.h"
int range_check(double, double, GDALDataType);
@@ -732,7 +734,8 @@
case GDT_Float32:
case GDT_CFloat32:
- if (max < TYPE_FLOAT32_MIN || min > TYPE_FLOAT32_MAX) {
+ if ((!CPLIsInf(max) && max < TYPE_FLOAT32_MIN) ||
+ (!CPLIsInf(min) && min > TYPE_FLOAT32_MAX)) {
G_warning(_("Selected GDAL datatype does not cover data range."));
G_warning(_("GDAL datatype: %s, range: %g - %g"),
GDALGetDataTypeName(datatype), TYPE_FLOAT32_MIN,
@@ -829,7 +832,7 @@
case GDT_Float32:
case GDT_CFloat32:
- if (nodataval != (double)(float) nodataval) {
+ if (!CPLIsNan(nodataval) && nodataval != (double)(float) nodataval) {
G_warning(_("Mismatch between metadata nodata value and actual nodata value in exported raster: "
"specified nodata value %g gets converted to %g by selected GDAL datatype."),
nodataval, (float) nodataval);
More information about the grass-commit
mailing list