Skip to content

Commit e298bca

Browse files
authored
d.rast.arrow: Support Terraflow (ArcGIS) directions (OSGeo#2987)
* d.rast.arrow: Support Terraflow (ArcGIS) directions * Fix typos * clang-format
1 parent e887353 commit e298bca

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

display/d.rast.arrow/d.rast.arrow.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ <h2>DESCRIPTION</h2>
4444
north for AGNPS and 1 to 8 counterclockwise from north east for Drainage. See
4545
<em><a href="r.watershed.html">r.watershed</a></em> for more details about the
4646
Drainage aspect.
47+
Terraflow (same as ArcGIS) type aspect map will use a power-of-two encoding
48+
clockwise from 1 for east to 128 for north east.
49+
See <em><a href="r.terraflow.html">r.terraflow</a></em> for more details about
50+
the Terraflow encoding.
4751
<p>GRASS aspect maps are measured using Cartesian conventions, i.e. in degrees
4852
counterclockwise from east. e.g.:
4953

@@ -88,7 +92,8 @@ <h2>SEE ALSO</h2>
8892
<a href="d.rast.num.html">d.rast.num</a>,
8993
<a href="g.region.html">g.region</a>,
9094
<a href="r.slope.aspect.html">r.slope.aspect</a>,
91-
<a href="r.watershed.html">r.watershed</a>
95+
<a href="r.watershed.html">r.watershed</a>,
96+
<a href="r.terraflow.html">r.terraflow</a>
9297
</em>
9398

9499
<h2>AUTHORS</h2>

display/d.rast.arrow/main.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* MODULE: d.rast.arrow
44
* AUTHOR(S): Chris Rewerts, Agricultural Engineering, Purdue University
55
* PURPOSE: Draw arrows on slope/aspect maps.
6-
* COPYRIGHT: (C) 2000, 2010 by the GRASS Development Team
6+
* COPYRIGHT: (C) 2000, 2010, 2023 by the GRASS Development Team
77
*
88
* This program is free software under the GNU General Public
99
* License (>=v2). Read the file COPYING that comes with GRASS
@@ -13,9 +13,9 @@
1313

1414
/* some minor cleanup done by Andreas Lange, [email protected]
1515
* Update to handle NULLs and floating point aspect maps: Hamish Bowman, Aug
16-
* 2004 Update for 360 degree arrows and magnitude scaling: Hamish Bowman, Oct
17-
* 2005 Align grids with raster cells: Huidae Cho, Apr 2009 Drainage aspect
18-
* type: Huidae Cho, Sep 2015
16+
* 2004; Update for 360 degree arrows and magnitude scaling: Hamish Bowman, Oct
17+
* 2005; Align grids with raster cells: Huidae Cho, Apr 2009; Drainage aspect
18+
* type: Huidae Cho, Sep 2015; Terraflow type: Huidae Cho, May 2023
1919
*/
2020

2121
/*
@@ -107,7 +107,7 @@ int main(int argc, char **argv)
107107
opt2->type = TYPE_STRING;
108108
opt2->required = NO;
109109
opt2->answer = "grass";
110-
opt2->options = "grass,compass,drainage,agnps,answers";
110+
opt2->options = "grass,compass,drainage,agnps,answers,terraflow";
111111
opt2->description = _("Type of existing raster aspect map");
112112

113113
opt3 = G_define_standard_option(G_OPT_C);
@@ -198,6 +198,8 @@ int main(int argc, char **argv)
198198
map_type = 4;
199199
else if (strcmp("drainage", opt2->answer) == 0)
200200
map_type = 5;
201+
else if (strcmp("terraflow", opt2->answer) == 0)
202+
map_type = 6;
201203

202204
scale = atof(opt8->answer);
203205
if (scale <= 0.0)
@@ -377,7 +379,8 @@ int main(int argc, char **argv)
377379

378380
/* treat AGNPS and ANSWERS data like old zero-as-null CELL */
379381
/* TODO: update models */
380-
if (map_type == 2 || map_type == 3 || map_type == 5) {
382+
if (map_type == 2 || map_type == 3 || map_type == 5 ||
383+
map_type == 6) {
381384
if (Rast_is_null_value(ptr, raster_type))
382385
aspect_c = 0;
383386
else if (map_type == 5 && aspect_f < 0)
@@ -557,6 +560,53 @@ int main(int argc, char **argv)
557560
}
558561
}
559562

563+
/* case switch for r.terraflow direction type aspect map */
564+
else if (map_type == 6) {
565+
D_use_color(arrow_color);
566+
switch (aspect_c) {
567+
case 0:
568+
/* only draw if x_color is not none (transparent) */
569+
if (x_color > 0) {
570+
D_use_color(x_color);
571+
draw_x();
572+
D_use_color(arrow_color);
573+
}
574+
break;
575+
case 1:
576+
arrow_e();
577+
break;
578+
case 2:
579+
arrow_se();
580+
break;
581+
case 4:
582+
arrow_s();
583+
break;
584+
case 8:
585+
arrow_sw();
586+
break;
587+
case 16:
588+
arrow_w();
589+
break;
590+
case 32:
591+
arrow_nw();
592+
break;
593+
case 64:
594+
arrow_n();
595+
break;
596+
case 128:
597+
arrow_ne();
598+
break;
599+
default:
600+
/* only draw if unknown_color is not none */
601+
if (unknown_color > 0) {
602+
D_use_color(unknown_color);
603+
unknown_();
604+
D_use_color(arrow_color);
605+
}
606+
break;
607+
}
608+
}
609+
560610
ptr = G_incr_void_ptr(ptr, Rast_cell_size(raster_type));
561611
if (opt7->answer)
562612
mag_ptr =

0 commit comments

Comments
 (0)