浏览代码

r.mapcalc: +area()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@69962 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 8 年之前
父节点
当前提交
02ab861f03

+ 2 - 0
raster/r.mapcalc/func_proto.h

@@ -14,3 +14,5 @@ extern func_t f_z;
 extern func_t f_ewres;
 extern func_t f_nsres;
 extern func_t f_tbres;
+
+extern func_t f_area;

+ 2 - 0
raster/r.mapcalc/function.c

@@ -23,6 +23,8 @@ func_desc local_func_descs[] = {
     {"nsres", c_double0, f_nsres},
     {"tbres", c_double0, f_tbres},
 
+    {"area", c_double0, f_area},
+
     {NULL, NULL, NULL}
 };
 

+ 3 - 3
raster/r.mapcalc/map.c

@@ -123,7 +123,7 @@ static void cache_setup(struct row_cache *cache, int fd, int nrows)
     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 @@ static void cache_release(struct row_cache *cache)
 
 	G_free(sub);
     }
-};
+}
 
 static void *cache_get_raw(struct row_cache *cache, int row, int data_type)
 {
@@ -209,7 +209,7 @@ static void cache_get(struct row_cache *cache, void *buf, int row, int res_type)
 {
     void *p = cache_get_raw(cache, row, res_type);
     memcpy(buf, p, columns * Rast_cell_size(res_type));
-};
+}
 
 /****************************************************************************/
 

+ 1 - 0
raster/r.mapcalc/r.mapcalc.html

@@ -339,6 +339,7 @@ Internal variables:
  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.

+ 1 - 0
raster/r.mapcalc/r3.mapcalc.html

@@ -253,6 +253,7 @@ Internal variables:
  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. 

+ 37 - 0
raster/r.mapcalc/xarea.c

@@ -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;
+}