[GRASS-SVN] r43583 - grass/branches/releasebranch_6_4/raster/r.random

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Sep 21 09:06:44 EDT 2010


Author: neteler
Date: 2010-09-21 13:06:44 +0000 (Tue, 21 Sep 2010)
New Revision: 43583

Modified:
   grass/branches/releasebranch_6_4/raster/r.random/description.html
   grass/branches/releasebranch_6_4/raster/r.random/local_proto.h
   grass/branches/releasebranch_6_4/raster/r.random/main.c
   grass/branches/releasebranch_6_4/raster/r.random/random.c
   grass/branches/releasebranch_6_4/raster/r.random/support.c
Log:
backport: don't clutter map title with repeated info, avoiding overflow (trac #800); named boolean for cover map; -b flag added to avoid vector topology

Modified: grass/branches/releasebranch_6_4/raster/r.random/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.random/description.html	2010-09-21 13:01:31 UTC (rev 43582)
+++ grass/branches/releasebranch_6_4/raster/r.random/description.html	2010-09-21 13:06:44 UTC (rev 43583)
@@ -6,7 +6,7 @@
 determined.  The program locates these randomly generated
 vector points (sites) within the current geographic region and mask (if
 any), on non-NULL category value data areas within a
-user-specified raster map layer.  If the user sets the
+user-specified raster map layer. If the user sets the
 <b>-z</b> flag, points will be randomly generated across all
 cells (even those with NULL values).
 
@@ -37,6 +37,11 @@
 the <em>cover</em> map.
 
 <p>
+If the user sets the <b>-b</b> flag, vector points are written without
+topology to minimize the required resources. This is suitable input
+to <em>v.surf.rst</em> and other vector modules.
+
+<p>
 The user may specify the quantity of random locations to be
 generated either as a <em>positive integer</em> (e.g., 10),
 or as a <em>percentage of the raster map layer's cells</em> 
@@ -108,9 +113,12 @@
 
 <h2>SEE ALSO</h2>
 
-<em><a href="g.region.html">g.region</a></em><br>
-<em><a href="r.reclass.html">r.reclass</a></em><br>
-<em><a href="v.random.html">v.random</a></em><br>
+<em>
+<a href="g.region.html">g.region</a><br>
+<a href="r.reclass.html">r.reclass</a><br>
+<a href="v.random.html">v.random</a><br>
+<a href="v.surf.rst.html">v.surf.rst</a>
+</em>
 
 
 <h2>AUTHOR</h2>

Modified: grass/branches/releasebranch_6_4/raster/r.random/local_proto.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.random/local_proto.h	2010-09-21 13:01:31 UTC (rev 43582)
+++ grass/branches/releasebranch_6_4/raster/r.random/local_proto.h	2010-09-21 13:06:44 UTC (rev 43583)
@@ -29,6 +29,7 @@
     struct RASTER_MAP_PTR nulls, cnulls, buf, cover, min, max, cmin, cmax;
     FILE *fsites;
     int z_geometry;
+    int notopol;
 };
 
 

Modified: grass/branches/releasebranch_6_4/raster/r.random/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.random/main.c	2010-09-21 13:01:31 UTC (rev 43582)
+++ grass/branches/releasebranch_6_4/raster/r.random/main.c	2010-09-21 13:06:44 UTC (rev 43583)
@@ -42,7 +42,7 @@
     } parm;
     struct
     {
-	struct Flag *zero, *info, *z_geometry;
+	struct Flag *zero, *info, *z_geometry, *notopol_flag;
     } flag;
 
     G_gisinit(argv[0]);
@@ -89,6 +89,11 @@
     flag.z_geometry->key = 'd';
     flag.z_geometry->description = _("Generate vector points as 3D points");
 
+    flag.notopol_flag = G_define_flag();
+    flag.notopol_flag->key = 'b';
+    flag.notopol_flag->description = _("Do not build topology in points mode");
+    flag.notopol_flag->guisection = _("Points");
+
     if (G_parser(argc, argv) != 0)
 	exit(EXIT_FAILURE);
 
@@ -96,23 +101,24 @@
     myState.use_nulls = flag.zero->answer;
     myState.inraster = parm.input->answer;
     if (parm.cover->answer) {
-	myState.docover = 1;
+	myState.docover = TRUE;
 	myState.inrcover = parm.cover->answer;
     }
     else {
-	myState.docover = 0;
+	myState.docover = FALSE;
 	myState.cmapset = NULL;
 	myState.inrcover = NULL;
     }
     myState.outraster = parm.raster->answer;
     myState.outvector = parm.sites->answer;
     myState.z_geometry = flag.z_geometry->answer;
+    myState.notopol = flag.notopol_flag->answer;
 
     myState.mapset = G_find_cell(myState.inraster, "");
     if (myState.mapset == NULL)
 	G_fatal_error(_("Raster map <%s> not found"), myState.inraster);
 
-    if (myState.docover == 1) {
+    if (myState.docover == TRUE) {
 	myState.cmapset = G_find_cell(myState.inrcover, "");
 	if (myState.cmapset == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"), myState.inrcover);

Modified: grass/branches/releasebranch_6_4/raster/r.random/random.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.random/random.c	2010-09-21 13:01:31 UTC (rev 43582)
+++ grass/branches/releasebranch_6_4/raster/r.random/random.c	2010-09-21 13:06:44 UTC (rev 43583)
@@ -40,14 +40,14 @@
     if ((infd = theState->fd_old) < 0)
 	G_fatal_error(_("Unable to open raster map <%s>"),
 		      theState->inraster);
-    if (theState->docover == 1) {
+    if (theState->docover == TRUE) {
 	if ((cinfd = theState->fd_cold) < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"),
 			  theState->inrcover);
     }
 
     if (theState->outraster != NULL) {
-	if (theState->docover == 1)
+	if (theState->docover == TRUE)
 	    type = theState->cover.type;
 	else
 	    type = theState->buf.type;
@@ -77,7 +77,7 @@
 	Vect_map_add_dblink(&Out, 1, NULL, fi->table, "cat", fi->database,
 			    fi->driver);
 
-	if (theState->docover == 1)
+	if (theState->docover == TRUE)
 	    table = db_alloc_table(3);
 	else
 	    table = db_alloc_table(2);
@@ -91,7 +91,7 @@
 	db_set_column_name(column, "value");
 	db_set_column_sqltype(column, DB_SQL_TYPE_DOUBLE_PRECISION);
 
-	if (theState->docover == 1) {
+	if (theState->docover == TRUE) {
 	    column = db_get_table_column(table, 2);
 	    db_set_column_name(column, "covervalue");
 	    db_set_column_sqltype(column, DB_SQL_TYPE_DOUBLE_PRECISION);
@@ -121,13 +121,14 @@
 	theState->nCells - theState->nNulls;
     nt = theState->nRand;	/* Number of points to generate */
     cat = 1;
+
     /* Execute for loop for every row if nt>1 */
     for (row = 0; row < nrows && nt; row++) {
 	if (G_get_raster_row
 	    (infd, theState->buf.data.v, row, theState->buf.type) < 0)
 	    G_fatal_error(_("Cannot read raster row [%d] from raster map <%s>"),
 			  row, theState->inraster);
-	if (theState->docover == 1) {
+	if (theState->docover == TRUE) {
 	    if (G_get_raster_row
 		(cinfd, theState->cover.data.v, row,
 		 theState->cover.type) < 0)
@@ -138,7 +139,7 @@
 	for (col = 0; col < ncols && nt; col++) {
 	    if (!theState->use_nulls && is_null_value(theState->buf, col))
 		continue;
-	    if (theState->docover == 1) {	/* skip no data cover points */
+	    if (theState->docover == TRUE) {	/* skip no data cover points */
 		if (!theState->use_nulls &&
 		    is_null_value(theState->cover, col))
 		    continue;
@@ -148,7 +149,7 @@
 		nt--;
 		if (is_null_value(theState->buf, col))
 		    cpvalue(&theState->nulls, 0, &theState->buf, col);
-		if (theState->docover == 1) {
+		if (theState->docover == TRUE) {
 		    if (is_null_value(theState->cover, col))
 			cpvalue(&theState->cnulls, 0, &theState->cover, col);
 		}
@@ -247,12 +248,13 @@
 
     /* close files */
     G_close_cell(infd);
-    if (theState->docover == 1)
+    if (theState->docover == TRUE)
 	G_close_cell(cinfd);
     if (theState->outvector) {
 	db_commit_transaction(driver);
 	db_close_database_shutdown_driver(driver);
-	Vect_build(&Out);
+	if (theState->notopol != 1)
+	    Vect_build(&Out);
 	Vect_close(&Out);
     }
     if (theState->outraster)

Modified: grass/branches/releasebranch_6_4/raster/r.random/support.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.random/support.c	2010-09-21 13:01:31 UTC (rev 43582)
+++ grass/branches/releasebranch_6_4/raster/r.random/support.c	2010-09-21 13:06:44 UTC (rev 43583)
@@ -26,7 +26,7 @@
 	nulls = theState->nulls;
     }
     if (G_read_raster_cats(inraster, mapset, &cats) >= 0) {
-	sprintf(title, "Random points on [%s in %s]", inraster, mapset);
+	sprintf(title, "Random points sampled from a raster map");
 	G_set_cats_title(title, &cats);
 	if (theState->use_nulls)
 	    G_set_raster_cat(nulls.data.v,



More information about the grass-commit mailing list