Browse Source

r.geomorphon: Refined resolution warning condition, code cleanups (#1093)

Refine a warning condition for resolution:

In one configuration r.geomorphon would always warn about the resolution
mismatch even after g.region had aligned the region. Apparently, the
four values in the comparison were equal up to 16 decimal places. The
difference seems to come from different calculations producing different
cumulative rounding errors. Add a small (less than 1mm in LatLong
projection) margin to squelch the warning when the difference is
negligible.

Make global_ternary_codes[] static:

The only code that uses the array is in geom.c, so make the array static
and export an initialization function to call from main(). Use a macro
instead of hard-coded constants and get the array size right.

Lose an unused function argument: extends() never used pattern_size, so get rid of it.

Fix W3C HTML validator issues for doc: required attribute "ALT" not specified,
document type does not allow element "H2" here, end tag for "DL" omitted.
Denis Ovsienko 4 years ago
parent
commit
3d418ef79d

+ 12 - 1
raster/r.geomorphon/geom.c

@@ -5,6 +5,17 @@ static double coss[NUM_DIRS] = { 0.7071067812, 1, 0.7071067812, 0, -0.7071067812
 
 /* DIRS in DEGREES from NORTH: 45,0,315,270,225,180,135,90 */
 
+#define TERNARY_MAX 6561 /* 3**8 */
+static unsigned int global_ternary_codes[TERNARY_MAX];
+
+void generate_ternary_codes()
+{
+    unsigned i;
+
+    for (i = 0; i < TERNARY_MAX; ++i)
+	global_ternary_codes[i] = ternary_rotate(i);
+}
+
 unsigned int ternary_rotate(unsigned int value)
 {
     /* this function returns rotated and mirrored
@@ -190,7 +201,7 @@ int radial2cartesian(PATTERN * pattern)
     return 0;
 }
 
-float extends(PATTERN * pattern, int pattern_size)
+float extends(PATTERN * pattern)
 {
     int i, j;
     float area = 0;

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

@@ -82,7 +82,6 @@ GLOBAL double search_distance, flat_distance;
 GLOBAL double flat_threshold, flat_threshold_height;
 GLOBAL struct Cell_head window;
 GLOBAL int cell_step;
-GLOBAL unsigned int global_ternary_codes[6562];
 
 /* memory */
 int open_map(MAPS * rast);
@@ -95,6 +94,7 @@ int write_contrast_colors(char *);
 int calc_pattern(PATTERN * pattern, int row, int cur_row, int col);
 
 /* geom */
+void generate_ternary_codes();
 unsigned int ternary_rotate(unsigned int value);
 FORMS determine_form(int num_plus, int num_minus);
 int determine_binary(int *pattern, int sign);
@@ -106,6 +106,6 @@ float range(float *elevation);
 float variance(float *elevation, int n);
 int shape(PATTERN * pattern, int pattern_size, float *azimuth,
 	  float *elongation, float *width);
-float extends(PATTERN * pattern, int pattern_size);
+float extends(PATTERN * pattern);
 int radial2cartesian(PATTERN *);
 #endif

+ 2 - 4
raster/r.geomorphon/main.c

@@ -301,9 +301,7 @@ int main(int argc, char **argv)
 	}
     }
 
-    /* generate global ternary codes */
-    for (i = 0; i < 6561; ++i)
-	global_ternary_codes[i] = ternary_rotate(i);
+    generate_ternary_codes();
 
     /* open DEM */
     strcpy(elevation.elevname, opt_input->answer);
@@ -458,7 +456,7 @@ int main(int argc, char **argv)
 		}
 		if (opt_output[o_extend]->answer)
 		    ((FCELL *) rasters[o_extend].buffer)[col] =
-			extends(pattern, pattern_size) / area_of_octagon;
+			extends(pattern) / area_of_octagon;
 
 	    }			/* end for col */
 

+ 2 - 1
raster/r.geomorphon/memory.c

@@ -37,7 +37,8 @@ int open_map(MAPS * rast)
     Rast_get_cellhd(rast->elevname, mapset, &cellhd);
     rast->raster_type = Rast_map_type(rast->elevname, mapset);
 
-    if (window.ew_res < cellhd.ew_res || window.ns_res < cellhd.ns_res)
+    if (window.ew_res + 1e-10 < cellhd.ew_res ||
+	window.ns_res + 1e-10 < cellhd.ns_res)
 	G_warning(_("Region resolution shoudn't be lesser than map %s resolution. Run g.region raster=%s to set proper resolution"),
 		  rast->elevname, rast->elevname);
 

+ 2 - 1
raster/r.geomorphon/r.geomorphon.html

@@ -72,7 +72,7 @@ especially with low resolution DEMS.
 <center>
 	
 <h3>Forms represented by geomorphons:</h3>
-<img src="legend.png" border="1"><br>
+<img src="legend.png" alt="forms legend" border="1"><br>
 </center></DD>
 <DT><b>ternary</b></DT>
 <DD>returns code of one of 498 unique ternary patterns for every cell. The code is a decimal representation of 8-tuple minimalised patterns written in ternary system. Full list of patterns is available in source code directory as patterns.txt. This map can be used to create alternative form classification using supervised approach.</DD>
@@ -95,6 +95,7 @@ especially with low resolution DEMS.
 <DD>returns proportion between sides of the bounding box rectangle calculated for geomorphon rotated to fit least square line.</DD>
 <DT><b>width</b></DT>
 <DD>returns length of the shorter side of the bounding box rectangle calculated for geomorphon rotated to fit least square line.</DD>
+</DL>
 
 
 <h2>NOTES</h2>