Skip to content

Commit

Permalink
r.geomorphon: Put the FORMS enum right
Browse files Browse the repository at this point in the history
Dàibhidh Grannd (English Language and Linguistics, School of Critical
Studies, University of Glasgow) points out that in the plugin HTML
documentation and in the original paper landform category 5 stands for
"SP" (spur), not "CV" (convex slope), and landform category 7 stands
for "HL" (hollow), not "CN" (concave slope). Amend that in the code and
update the comments.

Use the type where it belongs and replace a number of hard-coded
constants with enumeration constants. Reduce a variable scope.
  • Loading branch information
infrastation authored and wenzeslaus committed Oct 28, 2020
1 parent 0a7046c commit e6021dc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
24 changes: 6 additions & 18 deletions raster/r.geomorphon/geom.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ unsigned int ternary_rotate(unsigned int value)
return code < rev_code ? code : rev_code;
}

int determine_form(int num_minus, int num_plus)
FORMS determine_form(int num_minus, int num_plus)
{
/* determine form according number of positives and negatives
* simple approach to determine form pattern */
Expand All @@ -54,28 +54,16 @@ int determine_form(int num_minus, int num_plus)
/* 0 1 2 3 4 5 6 7 8 */
/* 0 */ {FL, FL, FL, FS, FS, VL, VL, VL, PT},
/* 1 */ {FL, FL, FS, FS, FS, VL, VL, VL, __},
/* 2 */ {FL, SH, SL, SL, CN, CN, VL, __, __},
/* 3 */ {SH, SH, SL, SL, SL, CN, __, __, __},
/* 4 */ {SH, SH, CV, SL, SL, __, __, __, __},
/* 5 */ {RI, RI, CV, CV, __, __, __, __, __},
/* 2 */ {FL, SH, SL, SL, HL, HL, VL, __, __},
/* 3 */ {SH, SH, SL, SL, SL, HL, __, __, __},
/* 4 */ {SH, SH, SP, SL, SL, __, __, __, __},
/* 5 */ {RI, RI, SP, SP, __, __, __, __, __},
/* 6 */ {RI, RI, RI, __, __, __, __, __, __},
/* 7 */ {RI, RI, __, __, __, __, __, __, __},
/* 8 */ {PK, __, __, __, __, __, __, __, __},
};
/* (See the FORMS enum for the legend.) */

/* legend:
FL, flat
PK, peak, summit
RI, ridge
SH, shoulder
CV, convex
SL, slope
CN, concave
FS, footslope
VL, valley
PT, pit, depression
__ error, impossible
*/
return forms[num_minus][num_plus];
}

Expand Down
12 changes: 6 additions & 6 deletions raster/r.geomorphon/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ typedef enum
{
ZERO, /* zero cats do not accept zero category */
FL, /* flat */
PK, /* peak, summit */
PK, /* peak (summit) */
RI, /* ridge */
SH, /* shoulder */
CV, /* convex slope */
SP, /* spur (convex slope) */
SL, /* slope */
CN, /* concave slope */
HL, /* hollow (concave slope) */
FS, /* footslope */
VL, /* valley */
PT, /* pit, depression */
__, /* error */
PT, /* pit (depression) */
__, /* error (impossible) */
CNT /* counter */
} FORMS;

Expand Down Expand Up @@ -158,7 +158,7 @@ int write_contrast_colors(char *);
/* geom */
int calc_pattern(PATTERN * pattern, int row, int cur_row, int col);
unsigned int ternary_rotate(unsigned int value);
int determine_form(int num_plus, int num_minus);
FORMS determine_form(int num_plus, int num_minus);
int determine_binary(int *pattern, int sign);
int determine_ternary(int *pattern);
int rotate(unsigned char binary);
Expand Down
17 changes: 9 additions & 8 deletions raster/r.geomorphon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ int main(int argc, char **argv)
{PK, 56, 0, 0, "summit"},
{RI, 200, 0, 0, "ridge"},
{SH, 255, 80, 20, "shoulder"},
{CV, 250, 210, 60, "spur"},
{SP, 250, 210, 60, "spur"},
{SL, 255, 255, 60, "slope"},
{CN, 180, 230, 20, "hollow"},
{HL, 180, 230, 20, "hollow"},
{FS, 60, 250, 150, "footslope"},
{VL, 0, 0, 255, "valley"},
{PT, 0, 0, 56, "depression"},
Expand Down Expand Up @@ -371,7 +371,7 @@ int main(int argc, char **argv)
continue;
} /* end null value */
{
int cur_form, small_form;
FORMS cur_form;

search_distance = search_dist;
skip_distance = skip_dist;
Expand All @@ -386,8 +386,9 @@ int main(int argc, char **argv)
/* correction of forms */
if (extended && search_distance > 10 * max_resolution) {
/* 1) remove extensive innatural forms: ridges, peaks, shoulders and footslopes */
if ((cur_form == 4 || cur_form == 8 || cur_form == 2
|| cur_form == 3)) {
if ((cur_form == SH || cur_form == FS || cur_form == PK
|| cur_form == RI)) {
FORMS small_form;
search_distance =
(search_dist / 2. <
4 * max_resolution) ? 4 *
Expand All @@ -400,9 +401,9 @@ int main(int argc, char **argv)
small_form =
determine_form(pattern->num_negatives,
pattern->num_positives);
if (cur_form == 4 || cur_form == 8)
cur_form = (small_form == 1) ? 1 : cur_form;
if (cur_form == 2 || cur_form == 3)
if (cur_form == SH || cur_form == FS)
cur_form = (small_form == FL) ? FL : cur_form;
if (cur_form == PK || cur_form == RI)
cur_form = small_form;
}
/* 3) Depressions */
Expand Down
6 changes: 3 additions & 3 deletions raster/r.geomorphon/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ int write_form_cat_colors(char *raster, CATCOLORS * ccolors)
{
struct Colors colors;
struct Categories cats;
int i;
FORMS i;

Rast_init_colors(&colors);

for (i = 1; i < CNT; ++i)
for (i = FL; i < CNT; ++i)
Rast_add_color_rule(&ccolors[i].cat, ccolors[i].r, ccolors[i].g,
ccolors[i].b, &ccolors[i].cat, ccolors[i].r,
ccolors[i].g, ccolors[i].b, &colors, CELL_TYPE);
Rast_write_colors(raster, G_mapset(), &colors);
Rast_free_colors(&colors);
Rast_init_cats("Forms", &cats);
for (i = 1; i < CNT; ++i)
for (i = FL; i < CNT; ++i)
Rast_set_cat(&ccolors[i].cat, &ccolors[i].cat, ccolors[i].label,
&cats, CELL_TYPE);
Rast_write_cats(raster, &cats);
Expand Down

0 comments on commit e6021dc

Please sign in to comment.