[GRASS-SVN] r65490 - in grass/trunk/raster: r.null r.support

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 16 16:22:34 PDT 2015


Author: glynn
Date: 2015-06-16 16:22:34 -0700 (Tue, 16 Jun 2015)
New Revision: 65490

Modified:
   grass/trunk/raster/r.null/main.c
   grass/trunk/raster/r.support/main.c
Log:
Set window before writing null file
Add option to re-create null file to r.null


Modified: grass/trunk/raster/r.null/main.c
===================================================================
--- grass/trunk/raster/r.null/main.c	2015-06-16 23:09:08 UTC (rev 65489)
+++ grass/trunk/raster/r.null/main.c	2015-06-16 23:22:34 UTC (rev 65490)
@@ -34,7 +34,7 @@
     int row, col, fd;
     unsigned char *null_bits;
     RASTER_MAP_TYPE map_type;
-    int change_null = 0, create, remove, only_int, only_fp, only_null;
+    int change_null = 0, create, remove, only_int, only_fp, only_null, recreate;
     int is_reclass;
 
     struct GModule *module;
@@ -51,6 +51,7 @@
 	struct Flag *i;
 	struct Flag *c;
 	struct Flag *r;
+	struct Flag *z;
     } flags;
 
     G_gisinit(argv[0]);
@@ -106,6 +107,11 @@
     flags.r->description = _("Remove NULL-value bitmap file");
     flags.r->guisection = _("Remove");
 
+    flags.z = G_define_flag();
+    flags.z->key = 'z';
+    flags.z->description =
+	_("Re-create NULL-value bitmap file (to compress or uncompress)");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -114,6 +120,7 @@
     only_null = flags.n->answer;
     create = flags.c->answer;
     remove = flags.r->answer;
+    recreate = flags.z->answer;
 
     name = parms.map->answer;
     mapset = G_find_raster2(name, "");
@@ -165,11 +172,12 @@
 
     if (create) {
 	/* write a file of no-nulls */
-	null_bits = (unsigned char *)Rast__allocate_null_bits(cellhd.cols);
+	null_bits = Rast__allocate_null_bits(cellhd.cols);
 	/* init all cells to 0's */
 	for (col = 0; col < Rast__null_bitstream_size(cellhd.cols); col++)
 	    null_bits[col] = 0;
 
+	Rast_set_window(&cellhd);
 	fd = Rast__open_null_write(name);
 
 	G_verbose_message(_("Writing new null file for raster map <%s>..."),
@@ -187,6 +195,32 @@
 	exit(EXIT_SUCCESS);
     }
 
+    if (recreate) {
+	int in_fd;
+	/* write a file of no-nulls */
+	null_bits = Rast__allocate_null_bits(cellhd.cols);
+
+	Rast_set_window(&cellhd);
+	in_fd = Rast_open_old(name, mapset);
+	fd = Rast__open_null_write(name);
+
+	G_verbose_message(_("Writing new null file for raster map <%s>..."),
+			  name);
+
+	for (row = 0; row < cellhd.rows; row++) {
+	    G_percent(row, cellhd.rows, 1);
+	    Rast_get_null_value_row(in_fd, (char*) null_bits, row);
+	    Rast__write_null_bits(fd, null_bits);
+	}
+	G_percent(row, cellhd.rows, 1);
+	Rast__close_null(fd);
+	Rast_close(in_fd);
+
+	G_done_msg(_("Raster map <%s> modified."), name);
+
+	exit(EXIT_SUCCESS);
+    }
+
     if (remove) {
 	/* write a file of no-nulls */
 	G_verbose_message(_("Removing null file for raster map <%s>..."),

Modified: grass/trunk/raster/r.support/main.c
===================================================================
--- grass/trunk/raster/r.support/main.c	2015-06-16 23:09:08 UTC (rev 65489)
+++ grass/trunk/raster/r.support/main.c	2015-06-16 23:22:34 UTC (rev 65490)
@@ -283,6 +283,7 @@
 	    null_bits[col] = 0;
 
 	/* Open null file for writing */
+	Rast_set_window(&cellhd);
 	fd = Rast__open_null_write(raster->answer);
 
 	G_message(_("Writing new null file for [%s]... "), raster->answer);



More information about the grass-commit mailing list