[GRASS-SVN] r67664 - in grass/trunk/raster/r.mapcalc: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 25 05:23:34 PST 2016


Author: marisn
Date: 2016-01-25 05:23:34 -0800 (Mon, 25 Jan 2016)
New Revision: 67664

Modified:
   grass/trunk/raster/r.mapcalc/func_proto.h
   grass/trunk/raster/r.mapcalc/function.c
   grass/trunk/raster/r.mapcalc/r.mapcalc.html
   grass/trunk/raster/r.mapcalc/r3.mapcalc.html
   grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py
   grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py
   grass/trunk/raster/r.mapcalc/xrowcol.c
Log:
r.mapcalc: Introduce new variables to access current region dimensions in number of cells

Modified: grass/trunk/raster/r.mapcalc/func_proto.h
===================================================================
--- grass/trunk/raster/r.mapcalc/func_proto.h	2016-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/func_proto.h	2016-01-25 13:23:34 UTC (rev 67664)
@@ -4,6 +4,9 @@
 extern func_t f_col;
 extern func_t f_row;
 extern func_t f_depth;
+extern func_t f_nrows;
+extern func_t f_ncols;
+extern func_t f_ndepths;
 
 extern func_t f_x;
 extern func_t f_y;

Modified: grass/trunk/raster/r.mapcalc/function.c
===================================================================
--- grass/trunk/raster/r.mapcalc/function.c	2016-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/function.c	2016-01-25 13:23:34 UTC (rev 67664)
@@ -11,6 +11,9 @@
     {"col", c_int0, f_col},
     {"row", c_int0, f_row},
     {"depth", c_int0, f_depth},
+    {"ncols", c_int0, f_ncols},
+    {"nrows", c_int0, f_nrows},
+    {"ndepths", c_int0, f_ndepths},
 
     {"x", c_double0, f_x},
     {"y", c_double0, f_y},

Modified: grass/trunk/raster/r.mapcalc/r.mapcalc.html
===================================================================
--- grass/trunk/raster/r.mapcalc/r.mapcalc.html	2016-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/r.mapcalc.html	2016-01-25 13:23:34 UTC (rev 67664)
@@ -332,12 +332,14 @@
 
 <div class="code"><pre>
 Internal variables:
- row()                  current row of moving window
- col()                  current col of moving window
- x()                    current x-coordinate of moving window
- y()                    current y-coordinate of moving window
- ewres()                current east-west resolution
- nsres()                current north-south resolution
+ row()                  current row of moving window                    I
+ col()                  current col of moving window                    I
+ nrows()                number of rows in computation region            I
+ ncols()                number of columns in computation region         I
+ x()                    current x-coordinate of moving window           F
+ y()                    current y-coordinate of moving window           F
+ ewres()                current east-west resolution                    F
+ nsres()                current north-south resolution                  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-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/r3.mapcalc.html	2016-01-25 13:23:34 UTC (rev 67664)
@@ -240,15 +240,18 @@
 
 <div class="code"><pre>
 Internal variables:
- row()                  current row of moving window
- col()                  current col of moving window
- depth()                return current depth
- x()                    current x-coordinate of moving window
- y()                    current y-coordinate of moving window
- z()                    return current z value
- ewres()                current east-west resolution
- nsres()                current north-south resolution
- tbres()                current top-bottom resolution
+ row()                  current row of moving window                    I
+ col()                  current col of moving window                    I
+ depth()                return current depth                            I
+ nrows()                number of rows in computation region            I
+ ncols()                number of columns in computation region         I
+ ndepths()              number of depth levels in computation region    I
+ x()                    current x-coordinate of moving window           F
+ y()                    current y-coordinate of moving window           F
+ z()                    return current z value                          F
+ ewres()                current east-west resolution                    F
+ nsres()                current north-south resolution                  F
+ tbres()                current top-bottom resolution                   F
  null()                 NULL value
 </pre></div>
 Note, that the row(), col() and depth() indexing starts with 1. 

Modified: grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py
===================================================================
--- grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py	2016-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/testsuite/test_r3_mapcalc.py	2016-01-25 13:23:34 UTC (rev 67664)
@@ -51,6 +51,14 @@
             expression='diff_e_e = 3 * x() * y() * z() - 3 * x() * y() * z()')
         self.to_remove.append('diff_e_e')
         self.assertRaster3dMinMax('diff_e_e', refmin=0, refmax=0)
+    
+    def test_nrows_ncols_ndepths_sum(self):
+        """Test if sum of nrows, ncols and ndepths matches one
+        expected from current region settigs"""
+        self.assertModule('r3.mapcalc',
+            expression='nrows_ncols_ndepths_sum = nrows() + ncols() + ndepths()')
+        self.to_remove.append('nrows_ncols_ndepths_sum')
+        self.assertRasterMinMax('nrows_ncols_ndepths_sum', refmin=2160, refmax=2160)
 
 
 if __name__ == '__main__':

Modified: grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py
===================================================================
--- grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py	2016-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/testsuite/test_r_mapcalc.py	2016-01-25 13:23:34 UTC (rev 67664)
@@ -218,6 +218,14 @@
             expression='diff_e_e = 3 * x() * y() - 3 * x() * y()')
         self.to_remove.append('diff_e_e')
         self.assertRasterMinMax('diff_e_e', refmin=0, refmax=0)
+    
+    def test_nrows_ncols_sum(self):
+        """Test if sum of nrows and ncols matches one
+        expected from current region settigs"""
+        self.assertModule('r.mapcalc',
+            expression='nrows_ncols_sum = nrows() + ncols()')
+        self.to_remove.append('nrows_ncols_sum')
+        self.assertRasterMinMax('nrows_ncols_sum', refmin=20, refmax=20)
 
 
 if __name__ == '__main__':

Modified: grass/trunk/raster/r.mapcalc/xrowcol.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xrowcol.c	2016-01-25 13:07:38 UTC (rev 67663)
+++ grass/trunk/raster/r.mapcalc/xrowcol.c	2016-01-25 13:23:34 UTC (rev 67664)
@@ -9,6 +9,9 @@
 col() column number
 row() row number
 depth() depth number
+ncols() number of columns
+nrows() number of rows
+ndepths() number of depths
 **********************************************************************/
 
 int f_col(int argc, const int *argt, void **args)
@@ -63,3 +66,54 @@
 
     return 0;
 }
+
+int f_nrows(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc > 0)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++)
+	res[i] = rows;
+
+    return 0;
+}
+
+int f_ncols(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc > 0)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++)
+	res[i] = columns;
+
+    return 0;
+}
+
+int f_ndepths(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc > 0)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++)
+	res[i] = depths;
+
+    return 0;
+}



More information about the grass-commit mailing list