Sfoglia il codice sorgente

r.geomorphon: fix landform category names (#1421)

* r.geomorphon: fix PK and PT category names

"Peak" and "pit" are the terms consistently used in the code and prose.
"Summit" and "depression" seem to be the terms used before the current
mnemonic codes had settled.

* r.geomorphon: deduplicate landform category code

Move two functions from main.c to memory.c and reduce them to use the
now consistent and more detailed ccolors[] instead of their own lookup
tables.
Denis Ovsienko 3 anni fa
parent
commit
0b7f1750f5

+ 2 - 0
raster/r.geomorphon/local_proto.h

@@ -98,6 +98,8 @@ int shift_buffers(int row);
 int free_map(FCELL ** map, int n);
 int write_form_cat_colors(char *raster);
 int write_contrast_colors(char *);
+const char *form_short_name(const FORMS);
+const char *form_long_name(const FORMS);
 
 /* pattern */
 int calc_pattern(PATTERN * pattern, int row, int cur_row, int col, const int);

+ 0 - 42
raster/r.geomorphon/main.c

@@ -39,48 +39,6 @@ typedef struct
     CELL *forms_buffer;
 } MULTI;
 
-static const char *form_short_name(const FORMS f)
-{
-    const char *form_short_names[] = {
-        /* skip 0 */
-        [FL] = "FL",
-        [PK] = "PK",
-        [RI] = "RI",
-        [SH] = "SH",
-        [SP] = "SP",
-        [SL] = "SL",
-        [HL] = "HL",
-        [FS] = "FS",
-        [VL] = "VL",
-        [PT] = "PT",
-        [__] = "ERROR",
-    };
-    return (f >= FL && f <= PT) ? form_short_names[f] : form_short_names[__];
-}
-
-static const char *form_long_name(const FORMS f)
-{
-    /*
-     * The list below is the same as in the documentation and the original paper.
-     * The values in ccolors[] are different for PK and PT.
-     */
-    const char *form_long_names[] = {
-        /* skip 0 */
-        [FL] = "flat",
-        [PK] = "peak",
-        [RI] = "ridge",
-        [SH] = "shoulder",
-        [SP] = "spur",
-        [SL] = "slope",
-        [HL] = "hollow",
-        [FS] = "footslope",
-        [VL] = "valley",
-        [PT] = "pit",
-        [__] = "ERROR",
-    };
-    return (f >= FL && f <= PT) ? form_long_names[f] : form_long_names[__];
-}
-
 int main(int argc, char **argv)
 {
     struct

+ 34 - 24
raster/r.geomorphon/memory.c

@@ -2,11 +2,11 @@
 
 typedef struct
 {
-    int cat;
+    const char *sname;
     int r;
     int g;
     int b;
-    char *label;
+    const char *lname;
 } CATCOLORS;
 
 typedef struct
@@ -18,6 +18,22 @@ typedef struct
     char *label;
 } FCOLORS;
 
+/* Landform category codes, numbers, names and colors. */
+static const CATCOLORS ccolors[CNT] = {
+    /* skip 0 */
+    [FL] = {"FL", 220, 220, 220, "flat"},
+    [PK] = {"PK", 56, 0, 0, "peak"},
+    [RI] = {"RI", 200, 0, 0, "ridge"},
+    [SH] = {"SH", 255, 80, 20, "shoulder"},
+    [SP] = {"SP", 250, 210, 60, "spur"},
+    [SL] = {"SL", 255, 255, 60, "slope"},
+    [HL] = {"HL", 180, 230, 20, "hollow"},
+    [FS] = {"FS", 60, 250, 150, "footslope"},
+    [VL] = {"VL", 0, 0, 255, "valley"},
+    [PT] = {"PT", 0, 0, 56, "pit"},
+    [__] = {"ERROR", 255, 0, 255, "ERROR"}
+};
+
 static int get_cell(int, float *, void *, RASTER_MAP_TYPE);
 
 int open_map(MAPS * rast)
@@ -128,33 +144,17 @@ int write_form_cat_colors(char *raster)
     struct Categories cats;
     FORMS i;
 
-    const CATCOLORS ccolors[CNT] = {    /* colors and cats for forms */
-        {ZERO, 0, 0, 0, "forms"},
-        {FL, 220, 220, 220, "flat"},
-        {PK, 56, 0, 0, "summit"},
-        {RI, 200, 0, 0, "ridge"},
-        {SH, 255, 80, 20, "shoulder"},
-        {SP, 250, 210, 60, "spur"},
-        {SL, 255, 255, 60, "slope"},
-        {HL, 180, 230, 20, "hollow"},
-        {FS, 60, 250, 150, "footslope"},
-        {VL, 0, 0, 255, "valley"},
-        {PT, 0, 0, 56, "depression"},
-        {__, 255, 0, 255, "ERROR"}
-    };
-
     Rast_init_colors(&colors);
 
-    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);
+    for (i = FL; i <= PT; ++i)
+        Rast_add_color_rule(&i, ccolors[i].r, ccolors[i].g, ccolors[i].b,
+                            &i, 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 = FL; i < CNT; ++i)
-        Rast_set_cat(&ccolors[i].cat, &ccolors[i].cat, ccolors[i].label,
-                     &cats, CELL_TYPE);
+    for (i = FL; i <= PT; ++i)
+        Rast_set_cat(&i, &i, ccolors[i].lname, &cats, CELL_TYPE);
     Rast_write_cats(raster, &cats);
     Rast_free_cats(&cats);
     return 0;
@@ -197,3 +197,13 @@ int write_contrast_colors(char *raster)
      */
     return 0;
 }
+
+const char *form_short_name(const FORMS f)
+{
+    return (f >= FL && f <= PT) ? ccolors[f].sname : ccolors[__].sname;
+}
+
+const char *form_long_name(const FORMS f)
+{
+    return (f >= FL && f <= PT) ? ccolors[f].lname : ccolors[__].lname;
+}

+ 9 - 9
raster/r.geomorphon/r.geomorphon.html

@@ -149,7 +149,7 @@ r.geomorphon elevation=eu_dem_25m forms=eu_dem_25m_geomorph
 # verify terrestrial landforms found in DEM
 r.category eu_dem_25m_geomorph
  1  flat
- 2  summit
+ 2  peak
  3  ridge
  4  shoulder
  5  spur
@@ -157,7 +157,7 @@ r.category eu_dem_25m_geomorph
  7  hollow
  8  footslope
  9  valley
- 10 depression
+ 10 pit
 </pre></div>
 
 <center>
@@ -165,20 +165,20 @@ r.category eu_dem_25m_geomorph
 </center>
 
 
-<h3>Extraction of summits</h3>
+<h3>Extraction of peaks</h3>
 
 Using the resulting terrestrial landforms map, single landforms can
-be extracted, e.g. the summits, and converted into a vector point map:
+be extracted, e.g. the peaks, and converted into a vector point map:
 
 <div class="code"><pre>
-r.mapcalc expression="eu_dem_25m_summits = if(eu_dem_25m_geomorph == 2, 1, null())"
-r.thin input=eu_dem_25m_summits output=eu_dem_25m_summits_thinned
-r.to.vect input=eu_dem_25m_summits_thinned output=eu_dem_25m_summits type=point
-v.info input=eu_dem_25m_summits
+r.mapcalc expression="eu_dem_25m_peaks = if(eu_dem_25m_geomorph == 2, 1, null())"
+r.thin input=eu_dem_25m_peaks output=eu_dem_25m_peaks_thinned
+r.to.vect input=eu_dem_25m_peaks_thinned output=eu_dem_25m_peaks type=point
+v.info input=eu_dem_25m_peaks
 </pre></div>
 
 <center>
-<img src="r_geomorphon_summits.png" border="0" alt="Extraction of summits from EU DEM 25m (with search=11)"><br>
+<img src="r_geomorphon_peaks.png" border="0" alt="Extraction of peaks from EU DEM 25m (with search=11)"><br>
 </center>
 
 <h2>SEE ALSO</h2>

raster/r.geomorphon/r_geomorphon_summits.png → raster/r.geomorphon/r_geomorphon_peaks.png


+ 2 - 2
raster/r.geomorphon/testsuite/test_r_geom.py

@@ -23,7 +23,7 @@ synth_out = """1	flat
 """
 
 ele_out = """1	flat
-2	summit
+2	peak
 3	ridge
 4	shoulder
 5	spur
@@ -31,7 +31,7 @@ ele_out = """1	flat
 7	hollow
 8	footslope
 9	valley
-10	depression
+10	pit
 """