[GRASS-SVN] r68790 - sandbox/moritz/r.object.geometry

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 28 02:36:38 PDT 2016


Author: mlennert
Date: 2016-06-28 02:36:38 -0700 (Tue, 28 Jun 2016)
New Revision: 68790

Modified:
   sandbox/moritz/r.object.geometry/main.c
Log:
r.object.geometry: added missing G_begin_distance_calculations(), corrected bug for righter-most pixels, added compactness to output


Modified: sandbox/moritz/r.object.geometry/main.c
===================================================================
--- sandbox/moritz/r.object.geometry/main.c	2016-06-28 08:40:38 UTC (rev 68789)
+++ sandbox/moritz/r.object.geometry/main.c	2016-06-28 09:36:38 UTC (rev 68790)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
@@ -145,6 +146,7 @@
         }
     }
     compute_areas = flag_m->answer && !planimetric;
+    G_begin_distance_calculations();
 
     for (row = 0; row < nrows; row++) {
 	G_percent(row, nrows + 1, 2);
@@ -226,6 +228,22 @@
 	    }
 	}
 
+	/* last col, right borders */
+	if (flag_m->answer) {
+	    double perimeter;
+	    perimeter = G_distance(cellhd.east,
+				   Rast_row_to_northing(row, &cellhd),
+				   cellhd.east,
+				   Rast_row_to_northing(row + 1, &cellhd));
+	    if (!cur_null)
+  	        obj_geos[cur - min].perimeter += perimeter;
+	} 
+	else {
+	    if (!cur_null)
+	        obj_geos[cur - min].perimeter += 1;
+	}
+		
+
 	/* switch the buffers so that the current buffer becomes the previous */
 	temp_in = cur_in;
 	cur_in = prev_in;
@@ -272,9 +290,10 @@
 	if (obj_geos[i].area == 0)
 	    continue;
 
-	fprintf(out_fp, "%d%s", i, sep);
+	fprintf(out_fp, "%d%s", min+i, sep);
 	fprintf(out_fp, "%f%s", obj_geos[i].area, sep);
-	fprintf(out_fp, "%f", obj_geos[i].perimeter);
+	fprintf(out_fp, "%f%s", obj_geos[i].perimeter, sep);
+	fprintf(out_fp, "%f", 4 * sqrt(obj_geos[i].area) / obj_geos[i].perimeter);
 	/* TODO: convert bounding box area and perimeter to (square) meters for -m flag */
 
 	
@@ -296,6 +315,11 @@
 	 * compactness = 4 * sqrt(area) / perimeter
 	 * -> compactness is in the range 0 < compactness <= 1
 	 */
+	 /*QUESTION: in v.to.db compactness is defined relative to the circle
+	  * of same area: perimeter / (2 * sqrt(PI * area))
+	  * shouldn't we keep the two comparable (even though in a grid we can
+	  * never reach 1 ?
+	  */
 
 	/* fractal dimension */
 



More information about the grass-commit mailing list