[GRASS-SVN] r71487 - in grass-addons/grass7/raster: . r.cell.area

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Sep 12 20:53:04 PDT 2017


Author: awickert
Date: 2017-09-12 20:53:04 -0700 (Tue, 12 Sep 2017)
New Revision: 71487

Added:
   grass-addons/grass7/raster/r.cell.area/
   grass-addons/grass7/raster/r.cell.area/Makefile
   grass-addons/grass7/raster/r.cell.area/r.cell.area.html
   grass-addons/grass7/raster/r.cell.area/r.cell.area.py
Log:
Tool to compute area in each raster cell


Added: grass-addons/grass7/raster/r.cell.area/Makefile
===================================================================
--- grass-addons/grass7/raster/r.cell.area/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.cell.area/Makefile	2017-09-13 03:53:04 UTC (rev 71487)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.cell.area
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/grass7/raster/r.cell.area/Makefile
___________________________________________________________________
Added: svn:executable
   + *

Added: grass-addons/grass7/raster/r.cell.area/r.cell.area.html
===================================================================
--- grass-addons/grass7/raster/r.cell.area/r.cell.area.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.cell.area/r.cell.area.html	2017-09-13 03:53:04 UTC (rev 71487)
@@ -0,0 +1,21 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.cell.area</em> uses the current computational region to compute the area of each raster cell. It can do so on a projected coordinate system or on a geographic coordinate system; the latter is accomplished via the latitude of the cell's midpoint.
+
+<h2>NOTES</h2>
+
+Output units can be either square meters or square kilometers.
+
+This module is useful for determining the flow accumulation area to weight flow accumulation algorithms by rainfall and/or on lat/lon grids.
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.mapcalc">r.mapcalc</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Andrew D. Wickert<br>
+
+<p><i>Last changed: $Date 2017-10-12$</i>

Added: grass-addons/grass7/raster/r.cell.area/r.cell.area.py
===================================================================
--- grass-addons/grass7/raster/r.cell.area/r.cell.area.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.cell.area/r.cell.area.py	2017-09-13 03:53:04 UTC (rev 71487)
@@ -0,0 +1,90 @@
+#! /usr/bin/env python
+
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:       r.cell.area
+#
+# AUTHOR(S):    Andrew Wickert
+#
+# PURPOSE:      Compute raster cell areas
+#
+# COPYRIGHT:    (c) 2017 Andrew Wickert
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+#
+
+#%module
+#% description: Calculate cell sizes within the computational region
+#% keyword: raster
+#%end
+
+#%option G_OPT_R_OUTPUT
+#%  key: output
+#%  type: string
+#%  description: Output grid of cell sizes
+#%  required: yes
+#%end
+
+#%option
+#%  key: units
+#%  type: string
+#%  description: Units for output areas
+#%  options: m2, km2
+#%  required: yes
+#%end
+
+##################
+# IMPORT MODULES #
+##################
+
+# PYTHON
+import os
+import glob
+import numpy as np
+# GRASS
+import grass.script as grass
+from grass.script import array as garray
+from grass.pygrass.vector import VectorTopo
+
+def main():
+    """
+    Compute cell areas
+    """
+    
+    projinfo = grass.parse_command('g.proj', flags='g')
+    
+    options, flags = grass.parser()
+    output = options['output']
+    units = options['units']
+    
+    # First check if output exists
+    if len(grass.parse_command('g.list', type='rast', 
+                               pattern=options['output'])):
+        if not grass.overwrite():
+            grass.fatal("Raster map '" + options['output'] + 
+                        "' already exists. Use '--o' to overwrite.")
+
+    # Then compute
+    if projinfo['units'] == 'meters':
+        if units == 'm2':
+            grass.mapcalc(output+' = nsres() * ewres()')
+        elif units == 'km2':
+            grass.mapcalc(output+' = nsres() * ewres() / 10.^6')
+    elif projinfo['units'] == 'degrees':
+        if units == 'm2':
+            grass.mapcalc(output+' = ( 111195. * nsres() ) * \
+                          ( ewres() * (3.14159/180.) * 6371000. * cos(y()) )')
+        elif units == 'km2':
+            grass.mapcalc(output+' = ( 111.195 * nsres() ) * \
+                          ( ewres() * (3.14159/180.) * 6371. * cos(y()) )')
+    else:
+        print 'Units: ', + projinfo['units'] + ' not currently supported'
+    
+if __name__ == "__main__":
+    main()
+



More information about the grass-commit mailing list