[GRASS-SVN] r65233 - grass/branches/releasebranch_7_0/raster/r.compress
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 13 04:38:09 PDT 2015
Author: neteler
Date: 2015-05-13 04:38:09 -0700 (Wed, 13 May 2015)
New Revision: 65233
Modified:
grass/branches/releasebranch_7_0/raster/r.compress/main.c
grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html
Log:
r.compress: print flag added; examples added; mention GRASS_ZLIB_LEVEL (trunk, r65115 + r65118)
Modified: grass/branches/releasebranch_7_0/raster/r.compress/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.compress/main.c 2015-05-13 08:06:40 UTC (rev 65232)
+++ grass/branches/releasebranch_7_0/raster/r.compress/main.c 2015-05-13 11:38:09 UTC (rev 65233)
@@ -8,7 +8,7 @@
*
* PURPOSE: Compress and decompress raster map files.
*
- * COPYRIGHT: (C) 2003 by the GRASS Development Team
+ * COPYRIGHT: (C) 2003-2015 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
@@ -20,6 +20,7 @@
* compress_cell converts straight grid_cell files into compressed grid_cell
* files. Compressed files have the following format:
*
+ * RLE:
* - Array of addresses pointing to the internal start of each row
* First byte of each row is the nuber of bytes per cell for that row
* Remainder of the row is a series of byte groups that describe the data:
@@ -45,6 +46,7 @@
static off_t newsize, oldsize;
static int process(char *, int);
+static int pprint(char *, int);
static int doit(char *, int, RASTER_MAP_TYPE);
int main(int argc, char *argv[])
@@ -54,13 +56,14 @@
char *name;
struct GModule *module;
struct Option *map;
- struct Flag *uncompress;
+ struct Flag *uncompress, *pflag;
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("raster"));
G_add_keyword(_("map management"));
+ G_add_keyword(_("compression"));
module->description = _("Compresses and decompresses raster maps.");
map = G_define_option();
@@ -75,9 +78,19 @@
uncompress->key = 'u';
uncompress->description = _("Uncompress the map");
+ pflag = G_define_flag();
+ pflag->key = 'p';
+ pflag->description = _("Print compression information and data type of input map(s)");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ if(pflag->answer) {
+ for (n = 0; (name = map->answers[n]); n++)
+ pprint(name, pflag->answer);
+ exit(EXIT_SUCCESS);
+ }
+
stat = 0;
for (n = 0; (name = map->answers[n]); n++)
if (process(name, uncompress->answer))
@@ -95,26 +108,26 @@
int colr_ok;
int hist_ok;
int cats_ok;
- int quant_ok;
+ int quant_ok=0;
off_t diff;
RASTER_MAP_TYPE map_type;
char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
if (G_find_raster(name, G_mapset()) == NULL) {
- G_warning(_("[%s] not found"), name);
+ G_warning(_("Raster map <%s> not found"), name);
return 1;
}
if (Rast_is_reclass(name, G_mapset(), rname, rmapset) > 0) {
G_warning(uncompress
?
- _("[%s] is a reclass file of map <%s> in mapset <%s> - can't uncompress")
+ _("<%s> is a reclass file of map <%s> in mapset <%s> - can't uncompress")
:
- _("[%s] is a reclass file of map <%s> in mapset <%s> - can't compress"),
+ _("<%s> is a reclass file of map <%s> in mapset <%s> - can't compress"),
name, rname, rmapset);
return 1;
}
if (G_find_file2_misc("cell_misc", "gdal", name, G_mapset())) {
- G_warning(_("[%s] is a GDAL-linked map - can't (un)compress"), name);
+ G_warning(_("<%s> is a GDAL-linked map - can't (un)compress"), name);
return 1;
}
@@ -180,15 +193,15 @@
/* check if already compressed/decompressed */
if (uncompress && cellhd.compressed == 0) {
- G_warning(_("[%s] already uncompressed"), name);
+ G_warning(_("<%s> already uncompressed"), name);
return 1;
}
else if (!uncompress && cellhd.compressed > 0) {
- G_warning(_("[%s] already compressed"), name);
+ G_warning(_("<%s> already compressed"), name);
return 1;
}
- G_message(_("\n%sCOMPRESS [%s]"), uncompress ? "UN" : "", name);
+ G_message(_("\n%sCOMPRESS <%s>"), uncompress ? "UN" : "", name);
Rast_set_window(&cellhd);
@@ -231,3 +244,59 @@
Rast_close(old);
return 0;
}
+
+
+static int pprint(char *name, int printstyle)
+{
+ struct Cell_head cellhd;
+ char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
+ int done;
+ RASTER_MAP_TYPE map_type;
+
+ if (G_find_raster(name, G_mapset()) == NULL) {
+ G_warning(_("Raster map <%s> not found"), name);
+ return 1;
+ }
+ if (G_find_file2_misc("cell_misc", "gdal", name, G_mapset())) {
+ G_message(_("<%s> is a GDAL-linked map"), name);
+ return 1;
+ }
+
+ Rast_get_cellhd(name, G_mapset(), &cellhd);
+ map_type = Rast_map_type(name, G_mapset());
+
+ done = 0;
+ if (Rast_is_reclass(name, G_mapset(), rname, rmapset) > 0) {
+ G_message(_("<%s> is a reclass file of map <%s> in mapset <%s>"),
+ name, rname, rmapset);
+ done = 1;
+ }
+
+ if (G_find_file2_misc("cell_misc", "gdal", name, G_mapset())) {
+ G_message(_("<%s> is a GDAL-linked map"), name);
+ done = 1;
+ }
+
+ /* Integer (CELL) compression:
+ * cellhd.compressed == 0: uncompressed
+ * cellhd.compressed == 1: RLE compressed
+ * cellhd.compressed == 2: DEFLATE compressed
+ */
+ if (!done && cellhd.compressed == 0) {
+ G_message(_("<%s> is uncompressed (level %i: %s). Data type: <%s>"), name, cellhd.compressed,
+ "NONE",
+ (map_type == CELL_TYPE ? "CELL" :
+ (map_type == DCELL_TYPE ? "DCELL" :
+ (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ }
+ else if (!done && cellhd.compressed > 0) {
+ G_message(_("<%s> is compressed (level %i: %s). Data type: <%s>"), name, cellhd.compressed,
+ cellhd.compressed == 1 ? "RLE" : "DEFLATE",
+ (map_type == CELL_TYPE ? "CELL" :
+ (map_type == DCELL_TYPE ? "DCELL" :
+ (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ }
+
+ return 0;
+}
+
Modified: grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html 2015-05-13 08:06:40 UTC (rev 65232)
+++ grass/branches/releasebranch_7_0/raster/r.compress/r.compress.html 2015-05-13 11:38:09 UTC (rev 65233)
@@ -1,7 +1,8 @@
<h2>DESCRIPTION</h2>
<em>r.compress</em> can be used to compress and decompress
-raster map layers.
+raster map layers. Additionally, it prints information about the
+map compression and data type of the input raster map(s).
<p>
During compression, this program reformats raster maps using a run-length-encoding
@@ -51,10 +52,11 @@
<p>
Integer (CELL) raster maps are by default ZLIB compressed or may remain
uncompressed. If the environment variable <tt>GRASS_INT_ZLIB</tt>
-exists and has the value 0, newly generated compressed integer (CELL type) raster maps will
-be compressed using RLE compression instead of ZLIB. In the internal
-cellhd file, the value for "compressed" is 1 for RLE and 2 for ZLIB.
+exists and has the value 0, newly generated compressed integer (CELL type)
+raster maps will be compressed using RLE compression instead of ZLIB.
<p>
+In the internal cellhd file, the value for "compressed" is 1 for RLE and 2 for ZLIB.
+<p>
Obviously, decompression is controlled by the raster map's compression,
not the environment variable.
@@ -150,9 +152,62 @@
only be larger by the size of the address array and the
single byte preceding each row.
+<p>
+Since GRASS GIS 7.0.0, the default compression method for
+ Integer (CELL) maps is deflate and not any more the RLE compression.
+
+<h4>DEFLATE compression level</h4>
+
+If the environment variable <tt>GRASS_ZLIB_LEVEL</tt> exists and
+its value can be parsed as an integer, it determines the compression
+level used when newly generated raster maps are compressed using zlib
+compression. This applies to all raster map types (CELL, FCELL, DCELL).
+<p>
+If the variable does not exist, or the value cannot be parsed as an
+integer, zlib's default compression level will be used.
+
+
+<h2>EXAMPLES</h2>
+
+Printing of current compression state:
+<div class="code"><pre>
+r.compress compressed_no -p
+ <compressed_no> (level 0: NONE). Data type: <CELL>
+</pre></div>
+
+<p>
+Applying RLE compression to a copy of the uncompressed map:
+<div class="code"><pre>
+# compression of map using RLE compression
+g.copy raster=compressed_no,compressed_RLE
+
+export GRASS_INT_ZLIB=0 # RLE
+r.compress compressed_RLE
+r.compress compressed_RLE -p
+ <compressed_RLE> is compressed (level 1: RLE). Data type: <CELL>
+unset GRASS_INT_ZLIB
+</pre></div>
+
+<p>
+Applying DEFLATE (ZLIB) compression to a copy of the uncompressed map:
+<div class="code"><pre>
+# compression of map using DEFLATE compression
+g.copy raster=compressed_no,compressed_DEFLATE
+
+export GRASS_INT_ZLIB=1 # deflate
+r.compress compressed_DEFLATE
+r.compress compressed_DEFLATE -p
+ <compressed_DEFLATE> is compressed (level 2: DEFLATE). Data type: <CELL>
+unset GRASS_INT_ZLIB
+</pre></div>
+
+
<h2>SEE ALSO</h2>
-<em><a href="r.support.html">r.support</a></em>
+<em>
+<a href="r.info.html">r.info</a>,
+<a href="r.support.html">r.support</a>
+</em>
<h2>AUTHORS</h2>
More information about the grass-commit
mailing list