[GRASS-SVN] r43745 - grass-addons/raster/r.clump2

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 30 05:34:03 EDT 2010


Author: mmetz
Date: 2010-09-30 09:34:03 +0000 (Thu, 30 Sep 2010)
New Revision: 43745

Added:
   grass-addons/raster/r.clump2/description.html
Removed:
   grass-addons/raster/r.clump2/r.clump2.html
Modified:
   grass-addons/raster/r.clump2/local_proto.h
   grass-addons/raster/r.clump2/main.c
   grass-addons/raster/r.clump2/ramseg.c
   grass-addons/raster/r.clump2/ramseg.h
Log:
backport r.clump2 to grass6

Copied: grass-addons/raster/r.clump2/description.html (from rev 43744, grass-addons/raster/r.clump2/r.clump2.html)
===================================================================
--- grass-addons/raster/r.clump2/description.html	                        (rev 0)
+++ grass-addons/raster/r.clump2/description.html	2010-09-30 09:34:03 UTC (rev 43745)
@@ -0,0 +1,49 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.clump2</em> finds all areas of contiguous cell category values in the
+input raster map layer <em>name.</em> It assigns a unique category value
+to each such area ("clump") in the resulting output raster map layer
+<em>name.</em> Optionally <em>r.clump2</em> uses start points and finds
+only those clumps where the start points are falling into.
+
+<h4>Differences to r.clump</h4>
+
+Category distinctions in the input raster map layer are NOT preserved.
+This means that if distinct category values are adjacent, they will be
+clumped together if possible.
+<p>
+Contrary to r.clump, NULL cells are ignored and not clumped.
+<p>
+<em>r.clump2</em> also consideres diagonal cells. <em>r.clump2</em> can
+be forced to consider only edge cells with the <em>e</em> flag, diagonal
+cells are now ignored.
+<p>
+Linear elements (lines that are a single cell wide) are without the
+<em>e</em> flag always clumped together.
+<p> 
+
+
+<h2>NOTES</h2>
+
+A random color table and other support files are
+generated for the <em>output</em> raster map layer.
+
+<h2>SEE ALSO</h2>
+
+<em><a href="r.clump.html">r.clump</a></em><br>
+<em><a href="r.average.html">r.average</a></em><br>
+<em><a href="r.buffer.html">r.buffer</a></em><br>
+<em><a href="r.grow.html">r.grow</a></em><br>
+<em><a href="r.mapcalc.html">r.mapcalc</a></em><br>
+<em><a href="r.mfilter.html">r.mfilter</a></em><br>
+<em><a href="r.neighbors.html">r.neighbors</a></em><br>
+<em><a href="r.to.vect.html">r.to.vect</a></em><br>
+<em><a href="r.reclass.html">r.reclass</a></em><br>
+<em><a href="r.statistics.html">r.statistics</a></em><br>
+<em><a href="r.support.html">r.support</a></em>
+
+<h2>AUTHOR</h2>
+
+Markus Metz
+
+<p><i>Last changed: $Date$</i>

Modified: grass-addons/raster/r.clump2/local_proto.h
===================================================================
--- grass-addons/raster/r.clump2/local_proto.h	2010-09-30 09:08:23 UTC (rev 43744)
+++ grass-addons/raster/r.clump2/local_proto.h	2010-09-30 09:34:03 UTC (rev 43745)
@@ -20,7 +20,6 @@
 #define __LOCAL_PROTO_H__
 
 #include <grass/gis.h>
-#include <grass/raster.h>
 #include "flag.h"
 #include "ramseg.h"
 

Modified: grass-addons/raster/r.clump2/main.c
===================================================================
--- grass-addons/raster/r.clump2/main.c	2010-09-30 09:08:23 UTC (rev 43744)
+++ grass-addons/raster/r.clump2/main.c	2010-09-30 09:34:03 UTC (rev 43745)
@@ -8,7 +8,7 @@
  * PURPOSE:      Recategorizes data in a raster map layer by grouping cells
  *		 that form physically discrete areas into unique categories.
  *
- * COPYRIGHT:    (C) 2009 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2010 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
@@ -58,9 +58,7 @@
     /* Define the different options */
 
     module = G_define_module();
-    G_add_keyword(_("raster"));
-    G_add_keyword(_("statistics"));
-    G_add_keyword(_("reclass"));
+    module->keywords = (_("raster, statistics, reclass"));
     module->description =
 	_("Recategorizes data in a raster map by grouping cells "
 	  "that form physically discrete areas into unique categories.");
@@ -91,11 +89,11 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    in_fd = Rast_open_old(opt_in->answer, "");
+    in_fd = G_open_cell_old(opt_in->answer, "");
     if (in_fd < 0)
 	G_fatal_error(_("Unable to open raster map <%s>"), opt_in->answer);
 
-    out_fd = Rast_open_c_new(opt_out->answer);
+    out_fd = G_open_cell_new(opt_out->answer);
     if (out_fd < 0)
 	G_fatal_error(_("Unable to create raster map <%s>"), opt_out->answer);
 
@@ -106,7 +104,7 @@
 
     /* some checks */
     G_get_set_window(&window);
-    Rast_get_cellhd(opt_in->answer, "", &cellhd);
+    G_get_cellhd(opt_in->answer, "", &cellhd);
 
     if (fabs(window.ew_res - cellhd.ew_res) > GRASS_EPSILON ||
 	fabs(window.ns_res - cellhd.ns_res) > GRASS_EPSILON) {
@@ -150,20 +148,20 @@
 	(CELL *) G_malloc(size_array(&ramseg, nrows, ncols) * sizeof(CELL));
 
     /* read input */
-    map_type = Rast_get_map_type(in_fd);
-    in_size = Rast_cell_size(map_type);
-    in_buf = Rast_allocate_buf(map_type);
+    map_type = G_get_raster_map_type(in_fd);
+    in_size = G_raster_size(map_type);
+    in_buf = G_allocate_raster_buf(map_type);
 
     inlist = flag_create(nrows, ncols);
 
     G_message(_("Loading input map ..."));
     for (r = 0; r < nrows; r++) {
-	Rast_get_row(in_fd, in_buf, r, map_type);
+	G_get_raster_row(in_fd, in_buf, r, map_type);
 	in_ptr = in_buf;
 	G_percent(r, nrows, 2);
 	for (c = 0; c < ncols; c++) {
 	    index = SEG_INDEX(ramseg, r, c);
-	    if (Rast_is_null_value(in_ptr, map_type))
+	    if (G_is_null_value(in_ptr, map_type))
 		clump_id[index] = 0;
 	    else
 		clump_id[index] = 1;
@@ -175,7 +173,7 @@
     }
     G_percent(nrows, nrows, 2);
 
-    Rast_close(in_fd);
+    G_close_cell(in_fd);
     G_free(in_buf);
 
     ncells = nrows * ncols;
@@ -324,7 +322,7 @@
     
     /* write output */
     G_message(_("Write output map ..."));
-    out_buf = Rast_allocate_buf(CELL_TYPE);
+    out_buf = G_allocate_raster_buf(CELL_TYPE);
     for (r = 0; r < nrows; r++) {
 	G_percent(r, nrows, 2);
 	for (c = 0; c < ncols; c++) {
@@ -337,16 +335,16 @@
 		    clump_id[index] = id_map[clump_id[index]];
 	    }
 	    if (clump_id[index] == 0)
-		Rast_set_c_null_value(&out_buf[c], 1);
+		G_set_c_null_value(&out_buf[c], 1);
 	    else
 		out_buf[c] = clump_id[index];
 
 	}
-	Rast_put_row(out_fd, out_buf, CELL_TYPE);
+	G_put_raster_row(out_fd, out_buf, CELL_TYPE);
     }
     G_percent(nrows, nrows, 2);
     G_free(out_buf);
-    Rast_close(out_fd);
+    G_close_cell(out_fd);
     G_free(clump_id);
     flag_destroy(inlist);
     if (id_map)
@@ -361,11 +359,11 @@
     else
 	sprintf(title, "clump of <%s@%s>", name, G_mapset());
 
-    Rast_put_cell_title(opt_out->answer, title);
-    Rast_read_range(opt_out->answer, G_mapset(), &range);
-    Rast_get_range_min_max(&range, &min, &max);
-    Rast_make_random_colors(&colr, min, max);
-    Rast_write_colors(opt_out->answer, G_mapset(), &colr);
+    G_put_cell_title(opt_out->answer, title);
+    G_read_range(opt_out->answer, G_mapset(), &range);
+    G_get_range_min_max(&range, &min, &max);
+    G_make_random_colors(&colr, min, max);
+    G_write_colors(opt_out->answer, G_mapset(), &colr);
 
     G_done_msg(_("%d clumps."), range.max);
 

Deleted: grass-addons/raster/r.clump2/r.clump2.html
===================================================================
--- grass-addons/raster/r.clump2/r.clump2.html	2010-09-30 09:08:23 UTC (rev 43744)
+++ grass-addons/raster/r.clump2/r.clump2.html	2010-09-30 09:34:03 UTC (rev 43745)
@@ -1,49 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.clump2</em> finds all areas of contiguous cell category values in the
-input raster map layer <em>name.</em> It assigns a unique category value
-to each such area ("clump") in the resulting output raster map layer
-<em>name.</em> Optionally <em>r.clump2</em> uses start points and finds
-only those clumps where the start points are falling into.
-
-<h4>Differences to r.clump</h4>
-
-Category distinctions in the input raster map layer are NOT preserved.
-This means that if distinct category values are adjacent, they will be
-clumped together if possible.
-<p>
-Contrary to r.clump, NULL cells are ignored and not clumped.
-<p>
-<em>r.clump2</em> also consideres diagonal cells. <em>r.clump2</em> can
-be forced to consider only edge cells with the <em>e</em> flag, diagonal
-cells are now ignored.
-<p>
-Linear elements (lines that are a single cell wide) are without the
-<em>e</em> flag always clumped together.
-<p> 
-
-
-<h2>NOTES</h2>
-
-A random color table and other support files are
-generated for the <em>output</em> raster map layer.
-
-<h2>SEE ALSO</h2>
-
-<em><a href="r.clump.html">r.clump</a></em><br>
-<em><a href="r.average.html">r.average</a></em><br>
-<em><a href="r.buffer.html">r.buffer</a></em><br>
-<em><a href="r.grow.html">r.grow</a></em><br>
-<em><a href="r.mapcalc.html">r.mapcalc</a></em><br>
-<em><a href="r.mfilter.html">r.mfilter</a></em><br>
-<em><a href="r.neighbors.html">r.neighbors</a></em><br>
-<em><a href="r.to.vect.html">r.to.vect</a></em><br>
-<em><a href="r.reclass.html">r.reclass</a></em><br>
-<em><a href="r.statistics.html">r.statistics</a></em><br>
-<em><a href="r.support.html">r.support</a></em>
-
-<h2>AUTHOR</h2>
-
-Markus Metz
-
-<p><i>Last changed: $Date$</i>

Modified: grass-addons/raster/r.clump2/ramseg.c
===================================================================
--- grass-addons/raster/r.clump2/ramseg.c	2010-09-30 09:08:23 UTC (rev 43744)
+++ grass-addons/raster/r.clump2/ramseg.c	2010-09-30 09:34:03 UTC (rev 43745)
@@ -1,8 +1,6 @@
 #include <stdio.h>
 #include "ramseg.h"
 
-#ifdef LARGE_MAPS
-
 long size_array(long *ramseg, int nrows, int ncols)
 {
     *ramseg = (long)ncols;
@@ -18,33 +16,3 @@
     
     return 0;
 }
-
-#else
-
-long size_array(long *ramseg, int nrows, int ncols)
-{
-    long size, segs_in_col;
-
-    segs_in_col = ((nrows - 1) >> RAMSEGBITS) + 1;
-    *ramseg = ((ncols - 1) >> RAMSEGBITS) + 1;
-    size = ((((nrows - 1) >> RAMSEGBITS) + 1) << RAMSEGBITS) *
-	((((ncols - 1) >> RAMSEGBITS) + 1) << RAMSEGBITS);
-    size -= ((segs_in_col << RAMSEGBITS) - nrows) << RAMSEGBITS;
-    size -= (*ram_seg << RAMSEGBITS) - ncols;
-    return (size);
-}
-
-/* get r, c from seg_index */
-long seg_index_rc(long ramseg, long seg_index, int *r, int *c)
-{
-    long seg_no, seg_remainder;
-
-    seg_no = seg_index >> DOUBLEBITS;
-    seg_remainder = seg_index - (seg_no << DOUBLEBITS);
-    *r = ((seg_no / ramseg) << RAMSEGBITS) + (seg_remainder >> RAMSEGBITS);
-    *c = ((seg_no - ((*r) >> RAMSEGBITS) * ramseg) << RAMSEGBITS) +
-	seg_remainder - (((*r) & SEGLENLESS) << RAMSEGBITS);
-    return seg_no;
-}
-
-#endif

Modified: grass-addons/raster/r.clump2/ramseg.h
===================================================================
--- grass-addons/raster/r.clump2/ramseg.h	2010-09-30 09:08:23 UTC (rev 43744)
+++ grass-addons/raster/r.clump2/ramseg.h	2010-09-30 09:34:03 UTC (rev 43745)
@@ -7,20 +7,8 @@
 #define DOUBLEBITS 	8	/* 2 * ramsegbits       */
 #define SEGLENLESS 	15	/* 2 ^ ramsegbits - 1   */
 
-#define LARGE_MAPS 1
-
-#ifdef LARGE_MAPS
-
 #define SEG_INDEX(s,r,c) (long) ((r) * (s) + (c))
 
-#else
-
-#define SEG_INDEX(s,r,c) (long) \
-   (((((r) >> RAMSEGBITS) * (s) + ((c) >> RAMSEGBITS)) << DOUBLEBITS) \
-    + (((r) & SEGLENLESS) << RAMSEGBITS) + ((c) & SEGLENLESS))
-    
-#endif
-
 long size_array(long *, int, int);
 long seg_index_rc(long, long, int *, int *);
 



More information about the grass-commit mailing list