[GRASS-SVN] r60922 - grass/trunk/raster/r.spread

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 22 18:36:47 PDT 2014


Author: wenzeslaus
Date: 2014-06-22 18:36:47 -0700 (Sun, 22 Jun 2014)
New Revision: 60922

Modified:
   grass/trunk/raster/r.spread/collect_ori.c
   grass/trunk/raster/r.spread/local_proto.h
   grass/trunk/raster/r.spread/main.c
Log:
r.spread: add a flag (-i) to use start raster map values instead of init time

Modified: grass/trunk/raster/r.spread/collect_ori.c
===================================================================
--- grass/trunk/raster/r.spread/collect_ori.c	2014-06-22 23:19:51 UTC (rev 60921)
+++ grass/trunk/raster/r.spread/collect_ori.c	2014-06-23 01:36:47 UTC (rev 60922)
@@ -43,7 +43,13 @@
 int x_out;
 int y_out;
 
-void collect_ori(int start_fd)
+/**
+ * \param start_fd start raster map
+ * \param start_is_time 1 if start map values should be used instead of init_time
+ *
+ * Other variables passed as global variables.
+ */
+void collect_ori(int start_fd, int start_is_time)
 {
     extern CELL *cell;
     extern CELL *map_base, *map_x_out, *map_y_out, *map_visit;
@@ -70,7 +76,11 @@
 		    continue;
 		}
 
-		DATA(map_out, row, col) = (float)init_time;
+		if (start_is_time)
+		    /* here we ignore the issue with null value if any */
+		    DATA(map_out, row, col) = cell[col];
+		else
+		    DATA(map_out, row, col) = (float)init_time;
 		insertHa((float)init_time, zero, row, col, heap, &heap_len);
 		/*mark it to avoid redundant computing */
 		DATA(map_visit, row, col) = 1;

Modified: grass/trunk/raster/r.spread/local_proto.h
===================================================================
--- grass/trunk/raster/r.spread/local_proto.h	2014-06-22 23:19:51 UTC (rev 60921)
+++ grass/trunk/raster/r.spread/local_proto.h	2014-06-23 01:36:47 UTC (rev 60922)
@@ -1,7 +1,7 @@
 #include "cell_ptrHa.h"
 #include "costHa.h"
 /* collect_ori.c */
-void collect_ori(int);
+void collect_ori(int, int);
 
 /* deleteHa.c */
 void deleteHa(float, int, int, struct costHa *, long *);

Modified: grass/trunk/raster/r.spread/main.c
===================================================================
--- grass/trunk/raster/r.spread/main.c	2014-06-22 23:19:51 UTC (rev 60921)
+++ grass/trunk/raster/r.spread/main.c	2014-06-23 01:36:47 UTC (rev 60922)
@@ -40,7 +40,6 @@
 
 #define DATA(map, r, c)		(map)[(r) * ncols + (c)]
 
-CELL range_min, range_max;
 CELL *cell;
 CELL *x_cell;
 CELL *y_cell;
@@ -70,7 +69,6 @@
 long heap_len;
 
 struct Cell_head window;
-struct Range range;
 
 struct costHa *heap;
 
@@ -79,6 +77,11 @@
 {
     int col, row;
 
+    /* to menage start (source) raster map */
+    struct Range start_range;
+    CELL start_range_min, start_range_max;
+    int start_is_time;  /* 0 or 1 */
+
     struct
     {
 	struct Option *max, *dir, *base, *start,
@@ -88,8 +91,8 @@
     } parm;
     struct
     {
-	/* please, remove before GRASS 7 released */
-	struct Flag *display, *spotting;
+	/* please, remove display before GRASS 7 released */
+	struct Flag *display, *spotting, *start_is_time;
     } flag;
     struct GModule *module;
 
@@ -307,7 +310,7 @@
 #if 0
     flag.display->label = _("DISPLAY 'live' spread process on screen");
     flag.display->description =
-	_("Display the "live" simulation on screen. A graphics window "
+	_("Display the 'live' simulation on screen. A graphics window "
 	  "must be opened and selected before using this option.");
 #else
     flag.display->description = _("Live display - disabled and depreciated");
@@ -317,6 +320,17 @@
     flag.spotting->key = 's';
     flag.spotting->description = _("Consider spotting effect (for wildfires)");
 
+    flag.start_is_time = G_define_flag();
+    flag.start_is_time->key = 'i';
+    flag.start_is_time->label = _("Use start raster map values in"
+	" output spread time raster map");
+    flag.start_is_time->description = _("Designed to be used with output"
+	" of previous run of r.spread when computing spread iteratively."
+	" The values in start raster map are considered as time."
+	" Allowed values in raster map are from zero"
+	" to the value of init_time option."
+	" If not enabled, init_time is used in the area of start raster map");
+
     /*   Parse command line */
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -522,9 +536,20 @@
 
     start_fd = Rast_open_old(start_layer, G_find_raster2(start_layer, ""));
 
-    Rast_read_range(start_layer, G_find_file("cell", start_layer, ""), &range);
-    Rast_get_range_min_max(&range, &range_min, &range_max);
+    Rast_read_range(start_layer, G_find_file("cell", start_layer, ""),
+		    &start_range);
+    Rast_get_range_min_max(&start_range, &start_range_min, &start_range_max);
 
+    start_is_time = flag.start_is_time->answer;
+    /* values higher than init_time are unexpected and may cause segfaults */
+    if (start_is_time && start_range_max > init_time)
+	G_fatal_error(_("Maximum of start raster map is grater than init_time"
+			" (%d > %d)"), start_range_max, init_time);
+    /* values lower then zero does not make sense for time */
+    if (start_is_time && start_range_min < 0)
+	G_fatal_error(_("Minimum of start raster map is less than zero"
+			" (%d < 0)"), start_range_min, init_time);
+
     /*  Initialize the heap  */
     heap =
 	(struct costHa *)G_calloc(nrows * ncols + 1, sizeof(struct costHa));
@@ -532,7 +557,7 @@
 
     G_message(_("Reading %s..."), start_layer);
     G_debug(1, "Collecting origins...");
-    collect_ori(start_fd);
+    collect_ori(start_fd, start_is_time);
     G_debug(1, "Done");
 
 



More information about the grass-commit mailing list