[GRASS-SVN] r29556 -
grass/branches/releasebranch_6_3/raster/r.out.gdal
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 4 12:15:33 EST 2008
Author: martinl
Date: 2008-01-04 12:15:32 -0500 (Fri, 04 Jan 2008)
New Revision: 29556
Modified:
grass/branches/releasebranch_6_3/raster/r.out.gdal/main.c
Log:
Fixing bug GForge/405: r.out.gdal sets NoData? wrong (merged from trunk)
Modified: grass/branches/releasebranch_6_3/raster/r.out.gdal/main.c
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.out.gdal/main.c 2008-01-04 17:07:05 UTC (rev 29555)
+++ grass/branches/releasebranch_6_3/raster/r.out.gdal/main.c 2008-01-04 17:15:32 UTC (rev 29556)
@@ -82,7 +82,7 @@
int import_band(GDALDatasetH hMEMDS, int band, char *name, char *mapset,
struct Cell_head *cellhead, RASTER_MAP_TYPE maptype,
- double nodataval)
+ double nodataval, char *nodatakey)
{
struct Colors sGrassColors;
@@ -225,12 +225,12 @@
/* Copy data form GRASS raster to memory raster */
int row, col;
+ int n_nulls = 0;
if (maptype == FCELL_TYPE) {
/* Source datatype understandible by GDAL */
GDALDataType datatype = GDT_Float32;
FCELL fnullval = (FCELL) nodataval;
- GDALSetRasterNoDataValue(hBand, nodataval);
for (row = 0; row < rows; row++) {
if (G_get_raster_row(fd, bufer, row, maptype) < 0) {
@@ -240,8 +240,13 @@
}
G_get_null_value_row(fd, nulls, row);
for (col = 0; col < cols; col++)
- if (nulls[col])
+ if (nulls[col]) {
((FCELL *) bufer)[col] = fnullval;
+ if (n_nulls == 0) {
+ GDALSetRasterNoDataValue(hBand, nodataval);
+ }
+ n_nulls++;
+ }
if (GDALRasterIO
(hBand, GF_Write, 0, row, cols, 1, bufer, cols, 1, datatype, 0,
@@ -256,7 +261,6 @@
GDALDataType datatype = GDT_Float64;
DCELL dnullval = (DCELL) nodataval;
- GDALSetRasterNoDataValue(hBand, nodataval);
for (row = 0; row < rows; row++) {
if (G_get_raster_row(fd, bufer, row, maptype) < 0) {
@@ -266,8 +270,13 @@
}
G_get_null_value_row(fd, nulls, row);
for (col = 0; col < cols; col++)
- if (nulls[col])
+ if (nulls[col]) {
((DCELL *) bufer)[col] = dnullval;
+ if (n_nulls == 0) {
+ GDALSetRasterNoDataValue(hBand, nodataval);
+ }
+ n_nulls++;
+ }
if (GDALRasterIO
(hBand, GF_Write, 0, row, cols, 1, bufer, cols, 1, datatype, 0,
@@ -282,7 +291,6 @@
GDALDataType datatype = GDT_Int32;
CELL inullval = (CELL) nodataval;
- GDALSetRasterNoDataValue(hBand, nodataval);
for (row = 0; row < rows; row++) {
if (G_get_raster_row(fd, bufer, row, maptype) < 0) {
@@ -292,8 +300,13 @@
}
G_get_null_value_row(fd, nulls, row);
for (col = 0; col < cols; col++)
- if (nulls[col])
+ if (nulls[col]) {
((CELL *) bufer)[col] = inullval;
+ if (n_nulls == 0) {
+ GDALSetRasterNoDataValue(hBand, nodataval);
+ }
+ n_nulls++;
+ }
if (GDALRasterIO
(hBand, GF_Write, 0, row, cols, 1, bufer, cols, 1, datatype, 0,
@@ -305,6 +318,20 @@
}
}
+ if (n_nulls > 0) {
+ if (maptype == CELL_TYPE)
+ G_warning(_("Input raster map constains cells with NULL-value (no-data). "
+ "For no-data values was used value %d. "
+ "You can specify nodata value by %s parameter."),
+ (int) nodataval, nodatakey);
+ else
+ G_warning(_("Input raster map constains cells with NULL-value (no-data). "
+ "For no-data values was used value %g. "
+ "You can specify nodata value by %s parameter."),
+ nodataval, nodatakey);
+ }
+
+
return 0;
}
@@ -332,7 +359,7 @@
struct GModule *module;
struct Flag *flag_l;
- struct Option *input, *format, *type, *output, *createopt, *metaopt;
+ struct Option *input, *format, *type, *output, *createopt, *metaopt, *nodataopt;
struct Cell_head cellhead;
struct Ref ref;
@@ -406,6 +433,13 @@
metaopt->multiple = YES;
metaopt->required = NO;
+ nodataopt = G_define_option();
+ nodataopt->key = "nodata";
+ nodataopt->type = TYPE_DOUBLE;
+ nodataopt->description = _("Assign a specified nodata value to output bands");
+ nodataopt->multiple = NO;
+ nodataopt->required = NO;
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -536,6 +570,11 @@
}
}
+ /* force nodata-value if needed */
+ if (nodataopt->answer) {
+ nodataval = atof(nodataopt->answer);
+ }
+
/* If file type not set by user ... */
/* Get min/max values. */
if( G_read_fp_range(input->answer, mapset, &sRange ) == -1 ) {
@@ -638,7 +677,7 @@
for (band = 0; band < ref.nfiles; band++) {
if (import_band
(hCurrDS, band + 1, ref.file[band].name, ref.file[band].mapset,
- &cellhead, maptype, nodataval) < 0)
+ &cellhead, maptype, nodataval, nodataopt->key) < 0)
G_warning(_("Unable to export raster map <%s>"),
ref.file[band].name);
}
More information about the grass-commit
mailing list