[GRASS-SVN] r69128 - grass/trunk/raster/r.out.gdal
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 11 12:06:32 PDT 2016
Author: mmetz
Date: 2016-08-11 12:06:32 -0700 (Thu, 11 Aug 2016)
New Revision: 69128
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: enhance compatibility WRT metadata
Modified: grass/trunk/raster/r.out.gdal/export_band.c
===================================================================
--- grass/trunk/raster/r.out.gdal/export_band.c 2016-08-11 07:04:30 UTC (rev 69127)
+++ grass/trunk/raster/r.out.gdal/export_band.c 2016-08-11 19:06:32 UTC (rev 69128)
@@ -202,7 +202,8 @@
int export_band(GDALDatasetH hMEMDS, int band,
const char *name, const char *mapset,
struct Cell_head *cellhead, RASTER_MAP_TYPE maptype,
- double nodataval, int suppress_main_colortable)
+ double nodataval, int suppress_main_colortable,
+ int no_metadata, int writenodata)
{
struct Colors sGrassColors;
GDALColorTableH hCT;
@@ -237,9 +238,6 @@
Rast_get_fp_range_min_max(&sRange, &dfCellMin, &dfCellMax);
}
- sprintf(value, "GRASS GIS %s", GRASS_VERSION_NUMBER);
- GDALSetMetadataItem(hBand, "Generated_with", value, NULL);
-
/* use default color rules if no color rules are given */
if (Rast_read_colors(name, mapset, &sGrassColors) >= 0) {
int maxcolor, i;
@@ -312,28 +310,30 @@
GDALSetRasterColorTable(hBand, hCT);
}
- if (rcount > 0) {
- /* Create metadata entries for color table rules */
- sprintf(value, "%d", rcount);
- GDALSetMetadataItem(hBand, "COLOR_TABLE_RULES_COUNT", value,
- NULL);
- }
+ if (!no_metadata) {
+ if (rcount > 0) {
+ /* Create metadata entries for color table rules */
+ sprintf(value, "%d", rcount);
+ GDALSetMetadataItem(hBand, "COLOR_TABLE_RULES_COUNT", value,
+ NULL);
+ }
- /* Add the rules in reverse order */
- /* This can cause a GDAL warning with many rules, something like
- * Warning 1: Lost metadata writing to GeoTIFF ... too large to fit in tag. */
- for (i = rcount - 1; i >= 0; i--) {
- DCELL val1, val2;
- unsigned char r1, g1, b1, r2, g2, b2;
+ /* Add the rules in reverse order */
+ /* This can cause a GDAL warning with many rules, something like
+ * Warning 1: Lost metadata writing to GeoTIFF ... too large to fit in tag. */
+ for (i = rcount - 1; i >= 0; i--) {
+ DCELL val1, val2;
+ unsigned char r1, g1, b1, r2, g2, b2;
- Rast_get_fp_color_rule(&val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2,
- &sGrassColors, i);
+ Rast_get_fp_color_rule(&val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2,
+ &sGrassColors, i);
- sprintf(key, "COLOR_TABLE_RULE_RGB_%d", rcount - i - 1);
- sprintf(value, "%e %e %d %d %d %d %d %d", val1, val2, r1, g1, b1,
- r2, g2, b2);
- GDALSetMetadataItem(hBand, key, value, NULL);
+ sprintf(key, "COLOR_TABLE_RULE_RGB_%d", rcount - i - 1);
+ sprintf(value, "%e %e %d %d %d %d %d %d", val1, val2, r1, g1, b1,
+ r2, g2, b2);
+ GDALSetMetadataItem(hBand, key, value, NULL);
+ }
}
}
@@ -442,6 +442,8 @@
G_percent(row + 1, rows, 2);
}
}
+ if (writenodata && n_nulls == 0)
+ GDALSetRasterNoDataValue(hBand, nodataval);
Rast_close(fd);
Modified: grass/trunk/raster/r.out.gdal/local_proto.h
===================================================================
--- grass/trunk/raster/r.out.gdal/local_proto.h 2016-08-11 07:04:30 UTC (rev 69127)
+++ grass/trunk/raster/r.out.gdal/local_proto.h 2016-08-11 19:06:32 UTC (rev 69128)
@@ -56,7 +56,7 @@
/* export_band.c */
int export_band(GDALDatasetH, int, const char *,
const char *, struct Cell_head *, RASTER_MAP_TYPE,
- double, int);
+ double, int, int, int);
int exact_checks(GDALDataType, const char *, const char *,
struct Cell_head *, RASTER_MAP_TYPE, double,
const char *, int);
Modified: grass/trunk/raster/r.out.gdal/main.c
===================================================================
--- grass/trunk/raster/r.out.gdal/main.c 2016-08-11 07:04:30 UTC (rev 69127)
+++ grass/trunk/raster/r.out.gdal/main.c 2016-08-11 19:06:32 UTC (rev 69128)
@@ -114,7 +114,7 @@
{
struct GModule *module;
- struct Flag *flag_l, *flag_c, *flag_f, *flag_t;
+ struct Flag *flag_l, *flag_c, *flag_m, *flag_f, *flag_t;
struct Option *input, *format, *type, *output, *createopt, *metaopt,
*nodataopt;
@@ -148,6 +148,12 @@
flag_c->description = _("Only applicable to Byte or UInt16 data types");
flag_c->guisection = _("Creation");
+ flag_m = G_define_flag();
+ flag_m->key = 'm';
+ flag_m->label = _("Do not write non-standard metadata");
+ flag_m->description = _("Enhances compatibility with other GIS software");
+ flag_m->guisection = _("Creation");
+
flag_t = G_define_flag();
flag_t->key = 't';
flag_t->label = _("Write raster attribute table");
@@ -220,8 +226,12 @@
nodataopt = G_define_option();
nodataopt->key = "nodata";
nodataopt->type = TYPE_DOUBLE;
+ nodataopt->label =
+ _("Assign a specified nodata value to output bands");
nodataopt->description =
- _("Assign a specified nodata value to output bands");
+ _("If given, the nodata value is always written to metadata "
+ "even if there are no NULL cells in the input band "
+ "(enhances output compatibility).");
nodataopt->multiple = NO;
nodataopt->required = NO;
nodataopt->guisection = _("Creation");
@@ -581,7 +591,29 @@
/* Add metadata */
AttachMetadata(hCurrDS, metaopt->answers);
+ if (strcmp(format->answer, "GTiff") == 0) {
+ char *pszKey;
+ char *pszValue;
+ pszKey = "TIFFTAG_SOFTWARE";
+ G_asprintf(&pszValue, "GRASS GIS %s with GDAL %d.%d.%d",
+ GRASS_VERSION_NUMBER,
+ GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, GDAL_VERSION_REV);
+ GDALSetMetadataItem(hCurrDS, pszKey, pszValue, NULL);
+ G_free(pszValue);
+ }
+ else if (!flag_m->answer) {
+ char *pszKey;
+ char *pszValue;
+
+ pszKey = "SOFTWARE";
+ G_asprintf(&pszValue, "GRASS GIS %s with GDAL %d.%d.%d",
+ GRASS_VERSION_NUMBER,
+ GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, GDAL_VERSION_REV);
+ GDALSetMetadataItem(hCurrDS, pszKey, pszValue, NULL);
+ G_free(pszValue);
+ }
+
/* Export to GDAL raster */
G_message(_("Exporting raster data to %s format..."), format->answer);
for (band = 0; band < ref.nfiles; band++) {
@@ -595,7 +627,7 @@
retval = export_band
(hCurrDS, band + 1, ref.file[band].name,
ref.file[band].mapset, &cellhead, maptype, nodataval,
- flag_c->answer);
+ flag_c->answer, flag_m->answer, (nodataopt->answer != NULL));
/* read/write error */
if (retval == -1) {
@@ -604,8 +636,7 @@
}
else if (flag_t->answer) {
retval = export_attr(hCurrDS, band + 1, ref.file[band].name,
- ref.file[band].mapset, maptype);
-
+ ref.file[band].mapset, maptype);
}
}
More information about the grass-commit
mailing list