[GRASS-SVN] r54418 - grass/trunk/raster/r.walk
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 27 08:06:21 PST 2012
Author: mmetz
Date: 2012-12-27 08:06:21 -0800 (Thu, 27 Dec 2012)
New Revision: 54418
Modified:
grass/trunk/raster/r.walk/main.c
grass/trunk/raster/r.walk/r.walk.html
Log:
r.walk: use standard GRASS directions
Modified: grass/trunk/raster/r.walk/main.c
===================================================================
--- grass/trunk/raster/r.walk/main.c 2012-12-27 16:06:06 UTC (rev 54417)
+++ grass/trunk/raster/r.walk/main.c 2012-12-27 16:06:21 UTC (rev 54418)
@@ -130,7 +130,7 @@
double NS_fac, EW_fac, DIAG_fac, H_DIAG_fac, V_DIAG_fac;
double fcost_dtm, fcost_cost;
double min_cost, old_min_cost;
- double cur_dir;
+ FCELL cur_dir;
double zero = 0.0;
int col = 0, row = 0, nrows = 0, ncols = 0;
int maxcost, par_number;
@@ -165,7 +165,7 @@
void *ptr1, *ptr2;
RASTER_MAP_TYPE dtm_data_type, cost_data_type, cum_data_type =
- DCELL_TYPE, dir_data_type = DCELL_TYPE;
+ DCELL_TYPE, dir_data_type = FCELL_TYPE;
struct History history;
double peak = 0.0;
int dtm_dsize, cost_dsize;
@@ -556,8 +556,8 @@
if (dir == 1) {
double disk_mb, mem_mb;
- disk_mb = (double) nrows * ncols * 32. / 1048576.;
- mem_mb = (double) srows * scols * 32. / 1048576. * segments_in_memory;
+ disk_mb = (double) nrows * ncols * 28. / 1048576.;
+ mem_mb = (double) srows * scols * 28. / 1048576. * segments_in_memory;
mem_mb += nrows * ncols * 0.05 * 20. / 1048576.; /* for Dijkstra search */
G_message(_("Will need at least %.2f MB of disk space"), disk_mb);
G_message(_("Will need at least %.2f MB of memory"), mem_mb);
@@ -592,7 +592,7 @@
if (dir == 1) {
dir_out_fd = creat(dir_out_file, 0600);
if (segment_format(dir_out_fd, nrows, ncols, srows, scols,
- sizeof(double)) != 1)
+ sizeof(FCELL)) != 1)
G_fatal_error("can not create temporary file");
close(dir_out_fd);
}
@@ -987,87 +987,97 @@
* 16 8 4 7 15
* 12 11
*/
+
+ /* drainage directions in degrees CCW from East
+ * drainage directions are set for each neighbor and must be
+ * read as from neighbor to current cell
+ *
+ * X = neighbor:
+ *
+ * 112.5 67.5
+ * 157.5 135 90 45 22.5
+ * 180 X 360
+ * 202.5 225 270 315 337.5
+ * 247.5 292.5
+ *
+ * X = present cell, directions for neighbors:
+ *
+ * 292.5 247.5
+ * 337.5 315 270 225 202.5
+ * 360 X 180
+ * 22.5 45 90 135 157.5
+ * 67.5 112.5
+ */
+
for (neighbor = 1; neighbor <= total_reviewed; neighbor++) {
switch (neighbor) {
case 1:
- row = pres_cell->row;
col = pres_cell->col - 1;
- cur_dir = 180.0;
+ cur_dir = 360.0;
break;
case 2:
- row = pres_cell->row;
col = pres_cell->col + 1;
- cur_dir = 0.0;
+ cur_dir = 180.0;
break;
case 3:
row = pres_cell->row - 1;
col = pres_cell->col;
- cur_dir = 90.0;
+ cur_dir = 270.0;
break;
case 4:
row = pres_cell->row + 1;
- col = pres_cell->col;
- cur_dir = 270.0;
+ cur_dir = 90.0;
break;
case 5:
row = pres_cell->row - 1;
col = pres_cell->col - 1;
- cur_dir = 135.0;
+ cur_dir = 315.0;
break;
case 6:
- row = pres_cell->row - 1;
col = pres_cell->col + 1;
- cur_dir = 45.0;
+ cur_dir = 225.0;
break;
case 7:
- col = pres_cell->col + 1;
row = pres_cell->row + 1;
- cur_dir = 315.0;
+ cur_dir = 135.0;
break;
case 8:
col = pres_cell->col - 1;
- row = pres_cell->row + 1;
- cur_dir = 225.0;
+ cur_dir = 45.0;
break;
case 9:
row = pres_cell->row - 2;
col = pres_cell->col - 1;
- cur_dir = 112.5;
+ cur_dir = 292.5;
break;
case 10:
- row = pres_cell->row - 2;
col = pres_cell->col + 1;
- cur_dir = 67.5;
+ cur_dir = 247.5;
break;
case 11:
row = pres_cell->row + 2;
- col = pres_cell->col + 1;
- cur_dir = 292.5;
+ cur_dir = 112.5;
break;
case 12:
- row = pres_cell->row + 2;
col = pres_cell->col - 1;
- cur_dir = 247.5;
+ cur_dir = 67.5;
break;
case 13:
row = pres_cell->row - 1;
col = pres_cell->col - 2;
- cur_dir = 157.5;
+ cur_dir = 337.5;
break;
case 14:
- row = pres_cell->row - 1;
col = pres_cell->col + 2;
- cur_dir = 22.5;
+ cur_dir = 202.5;
break;
case 15:
row = pres_cell->row + 1;
- col = pres_cell->col + 2;
- cur_dir = 337.5;
+ cur_dir = 157.5;
break;
case 16:
- row = pres_cell->row + 1;
col = pres_cell->col - 2;
- cur_dir = 202.5;
+ cur_dir = 22.5;
break;
}
@@ -1460,7 +1470,8 @@
}
if (dir == 1) {
- double *p;
+ void *p;
+ size_t dir_size = Rast_cell_size(dir_data_type);
dir_fd = Rast_open_new(move_dir_layer, dir_data_type);
dir_cell = Rast_allocate_buf(dir_data_type);
@@ -1470,7 +1481,8 @@
p = dir_cell;
for (col = 0; col < ncols; col++) {
segment_get(&dir_seg, &cur_dir, row, col);
- *(p + col) = cur_dir;
+ *((FCELL *) p) = cur_dir;
+ p = G_incr_void_ptr(p, dir_size);
}
Rast_put_row(dir_fd, dir_cell, dir_data_type);
}
Modified: grass/trunk/raster/r.walk/r.walk.html
===================================================================
--- grass/trunk/raster/r.walk/r.walk.html 2012-12-27 16:06:06 UTC (rev 54417)
+++ grass/trunk/raster/r.walk/r.walk.html 2012-12-27 16:06:21 UTC (rev 54418)
@@ -4,9 +4,10 @@
cumulative cost of moving between each cell and the user-specified
starting points and 2) a second raster map layer showing the movement
direction to the next cell on the path back to the start point (see
-<a href="#move">Movement Direction</a>). It uses an input elevation raster map layer whose
-cell category values represent elevation, combined with a second input
-raster map layer whose cell values represent friction costs.
+<a href="#move">Movement Direction</a>). It uses an input elevation
+raster map layer whose cell category values represent elevation,
+combined with a second input raster map layer whose cell values
+represent friction costs.
This function is similar to <em>r.cost</em>, but in addiction to a
friction map, it considers an anisotropic travel time due to the
@@ -70,16 +71,18 @@
<p>The movement direction surface is created to record the sequence of
movements that created the cost accumulation surface. Without it
<em>r.drain</em> would not correctly create a path from an end point
-back to the start point. The direction shown in each cell points <b>away</b>
-from the cell that came before it. The directions are recorded as
-GRASS standard directions:<div class="code"><pre>
- 112.5 90 67.5 i.e. a cell with the value 135
-157.5 135 0 45 22.5 means the cell <b>before</b> it is
- 180 x 0 to the south-east.
+back to the start point. The direction of each cell points towards
+the next cell. The directions are recorded as degrees CCW from East:
+<div class="code"><pre>
+ 112.5 67.5 i.e. a cell with the value 135
+157.5 135 90 45 22.5 means the next cell is to the north-west
+ 180 x 360
202.5 225 270 315 337.5
247.5 292.5
</pre></div>
-<p>Once <em>r.walk</em> computes the cumulative cost map as a linear
+
+<p>
+Once <em>r.walk</em> computes the cumulative cost map as a linear
combination of friction cost (from friction map) and the altitude and
distance covered (from the digital elevation model), <em>r.drain</em>
can be used to find the minimum cost path. Make sure to use the <b>-d</b> flag
More information about the grass-commit
mailing list