[GRASS-SVN] r69962 - grass/trunk/raster/r.mapcalc

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 1 05:20:06 PST 2016


Author: mmetz
Date: 2016-12-01 05:20:05 -0800 (Thu, 01 Dec 2016)
New Revision: 69962

Added:
   grass/trunk/raster/r.mapcalc/xarea.c
Modified:
   grass/trunk/raster/r.mapcalc/func_proto.h
   grass/trunk/raster/r.mapcalc/function.c
   grass/trunk/raster/r.mapcalc/map.c
   grass/trunk/raster/r.mapcalc/r.mapcalc.html
   grass/trunk/raster/r.mapcalc/r3.mapcalc.html
Log:
r.mapcalc: +area()

Modified: grass/trunk/raster/r.mapcalc/func_proto.h
===================================================================
--- grass/trunk/raster/r.mapcalc/func_proto.h	2016-12-01 11:04:19 UTC (rev 69961)
+++ grass/trunk/raster/r.mapcalc/func_proto.h	2016-12-01 13:20:05 UTC (rev 69962)
@@ -14,3 +14,5 @@
 extern func_t f_ewres;
 extern func_t f_nsres;
 extern func_t f_tbres;
+
+extern func_t f_area;

Modified: grass/trunk/raster/r.mapcalc/function.c
===================================================================
--- grass/trunk/raster/r.mapcalc/function.c	2016-12-01 11:04:19 UTC (rev 69961)
+++ grass/trunk/raster/r.mapcalc/function.c	2016-12-01 13:20:05 UTC (rev 69962)
@@ -23,6 +23,8 @@
     {"nsres", c_double0, f_nsres},
     {"tbres", c_double0, f_tbres},
 
+    {"area", c_double0, f_area},
+
     {NULL, NULL, NULL}
 };
 

Modified: grass/trunk/raster/r.mapcalc/map.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map.c	2016-12-01 11:04:19 UTC (rev 69961)
+++ grass/trunk/raster/r.mapcalc/map.c	2016-12-01 13:20:05 UTC (rev 69962)
@@ -123,7 +123,7 @@
     cache->sub[CELL_TYPE] = NULL;
     cache->sub[FCELL_TYPE] = NULL;
     cache->sub[DCELL_TYPE] = NULL;
-};
+}
 
 static void cache_release(struct row_cache *cache)
 {
@@ -144,7 +144,7 @@
 
 	G_free(sub);
     }
-};
+}
 
 static void *cache_get_raw(struct row_cache *cache, int row, int data_type)
 {
@@ -209,7 +209,7 @@
 {
     void *p = cache_get_raw(cache, row, res_type);
     memcpy(buf, p, columns * Rast_cell_size(res_type));
-};
+}
 
 /****************************************************************************/
 

Modified: grass/trunk/raster/r.mapcalc/r.mapcalc.html
===================================================================
--- grass/trunk/raster/r.mapcalc/r.mapcalc.html	2016-12-01 11:04:19 UTC (rev 69961)
+++ grass/trunk/raster/r.mapcalc/r.mapcalc.html	2016-12-01 13:20:05 UTC (rev 69962)
@@ -339,6 +339,7 @@
  y()                    current y-coordinate of moving window           F
  ewres()                current east-west resolution                    F
  nsres()                current north-south resolution                  F
+ area()                 area of current cell in square meters           F
  null()                 NULL value
 </pre></div>
 Note, that the row() and col() indexing starts with 1.

Modified: grass/trunk/raster/r.mapcalc/r3.mapcalc.html
===================================================================
--- grass/trunk/raster/r.mapcalc/r3.mapcalc.html	2016-12-01 11:04:19 UTC (rev 69961)
+++ grass/trunk/raster/r.mapcalc/r3.mapcalc.html	2016-12-01 13:20:05 UTC (rev 69962)
@@ -253,6 +253,7 @@
  ewres()                current east-west resolution                    F
  nsres()                current north-south resolution                  F
  tbres()                current top-bottom resolution                   F
+ area()                 area of current cell in square meters           F
  null()                 NULL value
 </pre></div>
 Note, that the row(), col() and depth() indexing starts with 1. 

Added: grass/trunk/raster/r.mapcalc/xarea.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xarea.c	                        (rev 0)
+++ grass/trunk/raster/r.mapcalc/xarea.c	2016-12-01 13:20:05 UTC (rev 69962)
@@ -0,0 +1,37 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include "globals.h"
+#include "expression.h"
+#include "func_proto.h"
+
+/**********************************************************************
+area() area of a cell in square meters
+**********************************************************************/
+
+int f_area(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    int i;
+    static int row = -1;
+    static double cell_area = 0;
+
+    if (argc > 0)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (row != current_row) {
+	if (row == -1)
+	    G_begin_cell_area_calculations();
+
+	row = current_row;
+	cell_area = G_area_of_cell_at_row(row);
+    }
+
+    for (i = 0; i < columns; i++)
+	res[i] = cell_area;
+
+    return 0;
+}


Property changes on: grass/trunk/raster/r.mapcalc/xarea.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native



More information about the grass-commit mailing list