Hi,
2007/12/17, Maciej Sieczka <[EMAIL PROTECTED]>:
Maciek:
> We need this one [1] fixed too. I'm uneasy about a release
> that has long time known bug in it's main raster export
> module, posing a threath of data corruption. See also notes
> on WIKI [2].
See the last comment in GForge and the attached patch.
http://wald.intevation.org/tracker/index.php?func=detail&aid=405&group=21
Sounds reasonable?
Martin
--
Martin Landa <[EMAIL PROTECTED]> * http://gama.fsv.cvut.cz/~landa *
Index: raster/r.out.gdal/main.c
===================================================================
--- raster/r.out.gdal/main.c (revision 29467)
+++ raster/r.out.gdal/main.c (working copy)
@@ -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);
}
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev