[GRASS-SVN] r67112 - in grass-addons/grass7/raster: . r.tri
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Dec 13 22:01:20 PST 2015
Author: spawley
Date: 2015-12-13 22:01:20 -0800 (Sun, 13 Dec 2015)
New Revision: 67112
Added:
grass-addons/grass7/raster/r.tri/
grass-addons/grass7/raster/r.tri/Makefile
grass-addons/grass7/raster/r.tri/r.tri.html
grass-addons/grass7/raster/r.tri/r.tri.py
Log:
First comit of r.tri (simple tool to calculate the terrain ruggedness index)
Added: grass-addons/grass7/raster/r.tri/Makefile
===================================================================
--- grass-addons/grass7/raster/r.tri/Makefile (rev 0)
+++ grass-addons/grass7/raster/r.tri/Makefile 2015-12-14 06:01:20 UTC (rev 67112)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.tri
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Property changes on: grass-addons/grass7/raster/r.tri/Makefile
___________________________________________________________________
Added: svn:eol-style
+ native
Added: grass-addons/grass7/raster/r.tri/r.tri.html
===================================================================
--- grass-addons/grass7/raster/r.tri/r.tri.html (rev 0)
+++ grass-addons/grass7/raster/r.tri/r.tri.html 2015-12-14 06:01:20 UTC (rev 67112)
@@ -0,0 +1,19 @@
+<h2>DESCRIPTION</h2>
+
+<i>r.tri </i>calculates the Terrain Ruggedness Index (TRI) of Riley et al. (1999). The index represents the sum change in elevation between a grid cell and its neighbours, over a user-specified moving window size. Unlike the original calculation in Riley et al., (1999) which used only a 3x3 neighbourhood, the TRI result is averaged over the number of neighbouring cells to allow the calculation to be extended over different window sizes. The calculation employed here produced exactly the same results as when using the terrain ruggedness focal function in the R raster package, which provides an alternative way to calculate the index using the R interface.
+
+<h2>NOTES</h2>
+<i>r.tri</i> uses <i>r.mapcalc</i> to calculate the sum of differences between the centre pixel and its neighbours. <i>r.mapcalc</i> statements are limited in character length, so only a range of neighbourhood sizes are allowed based on the methodology employed. If other window sizes are required, the R package <i>raster</i> can be used via <i>rgrass7</i>.
+
+<h2>TODO</h2>
+Null values are not evaluated at present, so there will be an edge effect and the resulting TRI will not be calculated at the image edges so there will be missing pixels along the margins relative to the size of the input raster. There is potential to calculate TRI at the image edges by using the <i>is.null()</i> r.mapcalc function.
+
+<h2>EXAMPLE</h2>
+r.tri dem=srtm wsize=3 output=tri
+
+<h2>REFERENCES</h2>
+Riley, S. J., S. D. DeGloria and R. Elliot (1999). A terrain ruggedness index that quantifies topographic heterogeneity, Intermountain Journal of Sciences, vol. 5, No. 1-4, 1999.
+
+<h2>AUTHOR</h2>
+Steven Pawley
+<br><i>Last changed: Saturday 12 December 2015</i>
\ No newline at end of file
Property changes on: grass-addons/grass7/raster/r.tri/r.tri.html
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ native
Added: grass-addons/grass7/raster/r.tri/r.tri.py
===================================================================
--- grass-addons/grass7/raster/r.tri/r.tri.py (rev 0)
+++ grass-addons/grass7/raster/r.tri/r.tri.py 2015-12-14 06:01:20 UTC (rev 67112)
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+##############################################################################
+#
+# MODULE: Topographic Ruggedness Index
+#
+# AUTHOR(S): Steven Pawley
+#
+# PURPOSE: Calculates the Topographic Ruggedness Index (TRI) of
+# Riley et al. (1999)
+#
+# COPYRIGHT: (C) 2015 Steven Pawley, and by the GRASS Development Team
+#
+# DATE: May 5 2015
+#
+##############################################################################
+
+#%module
+#% description: Topographic Ruggedness Index
+#%end
+
+#%option G_OPT_R_INPUT
+#% description: Input elevation raster
+#% key: dem
+#% required : yes
+#%end
+
+#%option G_OPT_R_OUTPUT
+#% description: Output Topographic Ruggedness Index (TRI)
+#% key: tri
+#% required : yes
+#%end
+
+#%option
+#% key: wsize
+#% type: integer
+#% description: Size of neighbourhood (valid 3,5,7,9,11)
+#% answer: 3
+#% guisection: Required
+#% options: 3,5,7,9,11
+#%end
+
+import sys
+import os
+import grass.script as grass
+
+def main():
+ dem = options['dem']
+ tri = options['tri']
+ wsize = int(options['wsize'])
+ neighcells = wsize^2 -1
+
+ # calculate TRI based on map calc statements
+ # NB could create script to calculate matrix but mapcalc is limited by statement length
+ grass.message("Calculating the Topographic Ruggedness Index:")
+ if wsize == 3:
+ grass.mapcalc('{x} = (abs({a}[0,0]-{a}[-1,-1])+abs({a}[0,0]-{a}[0,-1])+abs({a}[0,0]-{a}[1,-1])+abs({a}[0,0]-{a}[-1,0])+abs({a}[0,0]-{a}[0,0])+abs({a}[0,0]-{a}[1,0])+abs({a}[0,0]-{a}[-1,1])+abs({a}[0,0]-{a}[0,1])+abs({a}[0,0]-{a}[1,1]))/1'.format(x=tri, a=dem, b=neighcells))
+ elif wsize == 5:
+ grass.mapcalc('{x} = (abs({a}[0,0]-{a}[-2,-2])+abs({a}[0,0]-{a}[-1,-2])+abs({a}[0,0]-{a}[0,-2])+abs({a}[0,0]-{a}[1,-2])+abs({a}[0,0]-{a}[2,-2])+abs({a}[0,0]-{a}[-2,-1])+abs({a}[0,0]-{a}[-1,-1])+abs({a}[0,0]-{a}[0,-1])+abs({a}[0,0]-{a}[1,-1])+abs({a}[0,0]-{a}[2,-1])+abs({a}[0,0]-{a}[-2,0])+abs({a}[0,0]-{a}[-1,0])+abs({a}[0,0]-{a}[0,0])+abs({a}[0,0]-{a}[1,0])+abs({a}[0,0]-{a}[2,0])+abs({a}[0,0]-{a}[-2,1])+abs({a}[0,0]-{a}[-1,1])+abs({a}[0,0]-{a}[0,1])+abs({a}[0,0]-{a}[1,1])+abs({a}[0,0]-{a}[2,1])+abs({a}[0,0]-{a}[-2,2])+abs({a}[0,0]-{a}[-1,2])+abs({a}[0,0]-{a}[0,2])+abs({a}[0,0]-{a}[1,2])+abs({a}[0,0]-{a}[2,2]))/{b}'.format(x=tri, a=dem, b=neighcells))
+ elif wsize == 7:
+ grass.mapcalc('{x} = (abs({a}[0,0]-{a}[-3,-3])+abs({a}[0,0]-{a}[-2,-3])+abs({a}[0,0]-{a}[-1,-3])+abs({a}[0,0]-{a}[0,-3])+abs({a}[0,0]-{a}[1,-3])+abs({a}[0,0]-{a}[2,-3])+abs({a}[0,0]-{a}[3,-3])+abs({a}[0,0]-{a}[-3,-2])+abs({a}[0,0]-{a}[-2,-2])+abs({a}[0,0]-{a}[-1,-2])+abs({a}[0,0]-{a}[0,-2])+abs({a}[0,0]-{a}[1,-2])+abs({a}[0,0]-{a}[2,-2])+abs({a}[0,0]-{a}[3,-2])+abs({a}[0,0]-{a}[-3,-1])+abs({a}[0,0]-{a}[-2,-1])+abs({a}[0,0]-{a}[-1,-1])+abs({a}[0,0]-{a}[0,-1])+abs({a}[0,0]-{a}[1,-1])+abs({a}[0,0]-{a}[2,-1])+abs({a}[0,0]-{a}[3,-1])+abs({a}[0,0]-{a}[-3,0])+abs({a}[0,0]-{a}[-2,0])+abs({a}[0,0]-{a}[-1,0])+abs({a}[0,0]-{a}[0,0])+abs({a}[0,0]-{a}[1,0])+abs({a}[0,0]-{a}[2,0])+abs({a}[0,0]-{a}[3,0])+abs({a}[0,0]-{a}[-3,1])+abs({a}[0,0]-{a}[-2,1])+abs({a}[0,0]-{a}[-1,1])+abs({a}[0,0]-{a}[0,1])+abs({a}[0,0]-{a}[1,1])+abs({a}[0,0]-{a}[2,1])+abs({a}[0,0]-{a}[3,1])+abs({a}[0,0]-{a}[-3,2])+abs({a}[0,0]-{a}[-2,2])+abs({a}[0,0]-{a}[-1,2])+abs({a}[0,0]-{a}[0,2])+abs({a}[0,0]-{a}[1,2])+abs({a}[
0,0]-{a}[2,2])+abs({a}[0,0]-{a}[3,2])+abs({a}[0,0]-{a}[-3,3])+abs({a}[0,0]-{a}[-2,3])+abs({a}[0,0]-{a}[-1,3])+abs({a}[0,0]-{a}[0,3])+abs({a}[0,0]-{a}[1,3])+abs({a}[0,0]-{a}[2,3])+abs({a}[0,0]-{a}[3,3]))/{b}'.format(x=tri, a=dem, b=neighcells))
+ elif wsize == 9:
+ grass.mapcalc('{x} = (abs({a}[0,0]-{a}[-4,-4])+abs({a}[0,0]-{a}[-3,-4])+abs({a}[0,0]-{a}[-2,-4])+abs({a}[0,0]-{a}[-1,-4])+abs({a}[0,0]-{a}[0,-4])+abs({a}[0,0]-{a}[1,-4])+abs({a}[0,0]-{a}[2,-4])+abs({a}[0,0]-{a}[3,-4])+abs({a}[0,0]-{a}[4,-4])+abs({a}[0,0]-{a}[-4,-3])+abs({a}[0,0]-{a}[-3,-3])+abs({a}[0,0]-{a}[-2,-3])+abs({a}[0,0]-{a}[-1,-3])+abs({a}[0,0]-{a}[0,-3])+abs({a}[0,0]-{a}[1,-3])+abs({a}[0,0]-{a}[2,-3])+abs({a}[0,0]-{a}[3,-3])+abs({a}[0,0]-{a}[4,-3])+abs({a}[0,0]-{a}[-4,-2])+abs({a}[0,0]-{a}[-3,-2])+abs({a}[0,0]-{a}[-2,-2])+abs({a}[0,0]-{a}[-1,-2])+abs({a}[0,0]-{a}[0,-2])+abs({a}[0,0]-{a}[1,-2])+abs({a}[0,0]-{a}[2,-2])+abs({a}[0,0]-{a}[3,-2])+abs({a}[0,0]-{a}[4,-2])+abs({a}[0,0]-{a}[-4,-1])+abs({a}[0,0]-{a}[-3,-1])+abs({a}[0,0]-{a}[-2,-1])+abs({a}[0,0]-{a}[-1,-1])+abs({a}[0,0]-{a}[0,-1])+abs({a}[0,0]-{a}[1,-1])+abs({a}[0,0]-{a}[2,-1])+abs({a}[0,0]-{a}[3,-1])+abs({a}[0,0]-{a}[4,-1])+abs({a}[0,0]-{a}[-4,0])+abs({a}[0,0]-{a}[-3,0])+abs({a}[0,0]-{a}[-2,0])+abs({a}[0,0]-{a
}[-1,0])+abs({a}[0,0]-{a}[0,0])+abs({a}[0,0]-{a}[1,0])+abs({a}[0,0]-{a}[2,0])+abs({a}[0,0]-{a}[3,0])+abs({a}[0,0]-{a}[4,0])+abs({a}[0,0]-{a}[-4,1])+abs({a}[0,0]-{a}[-3,1])+abs({a}[0,0]-{a}[-2,1])+abs({a}[0,0]-{a}[-1,1])+abs({a}[0,0]-{a}[0,1])+abs({a}[0,0]-{a}[1,1])+abs({a}[0,0]-{a}[2,1])+abs({a}[0,0]-{a}[3,1])+abs({a}[0,0]-{a}[4,1])+abs({a}[0,0]-{a}[-4,2])+abs({a}[0,0]-{a}[-3,2])+abs({a}[0,0]-{a}[-2,2])+abs({a}[0,0]-{a}[-1,2])+abs({a}[0,0]-{a}[0,2])+abs({a}[0,0]-{a}[1,2])+abs({a}[0,0]-{a}[2,2])+abs({a}[0,0]-{a}[3,2])+abs({a}[0,0]-{a}[4,2])+abs({a}[0,0]-{a}[-4,3])+abs({a}[0,0]-{a}[-3,3])+abs({a}[0,0]-{a}[-2,3])+abs({a}[0,0]-{a}[-1,3])+abs({a}[0,0]-{a}[0,3])+abs({a}[0,0]-{a}[1,3])+abs({a}[0,0]-{a}[2,3])+abs({a}[0,0]-{a}[3,3])+abs({a}[0,0]-{a}[4,3])+abs({a}[0,0]-{a}[-4,4])+abs({a}[0,0]-{a}[-3,4])+abs({a}[0,0]-{a}[-2,4])+abs({a}[0,0]-{a}[-1,4])+abs({a}[0,0]-{a}[0,4])+abs({a}[0,0]-{a}[1,4])+abs({a}[0,0]-{a}[2,4])+abs({a}[0,0]-{a}[3,4])+abs({a}[0,0]-{a}[4,4]))/{b}'.format(x=tri, a=dem, b=
neighcells))
+ elif wsize == 11:
+ grass.mapcalc('{x} = (abs({a}[0,0]-{a}[-5,-5])+abs({a}[0,0]-{a}[-4,-5])+abs({a}[0,0]-{a}[-3,-5])+abs({a}[0,0]-{a}[-2,-5])+abs({a}[0,0]-{a}[-1,-5])+abs({a}[0,0]-{a}[0,-5])+abs({a}[0,0]-{a}[1,-5])+abs({a}[0,0]-{a}[2,-5])+abs({a}[0,0]-{a}[3,-5])+abs({a}[0,0]-{a}[4,-5])+abs({a}[0,0]-{a}[5,-5])+abs({a}[0,0]-{a}[-5,-4])+abs({a}[0,0]-{a}[-4,-4])+abs({a}[0,0]-{a}[-3,-4])+abs({a}[0,0]-{a}[-2,-4])+abs({a}[0,0]-{a}[-1,-4])+abs({a}[0,0]-{a}[0,-4])+abs({a}[0,0]-{a}[1,-4])+abs({a}[0,0]-{a}[2,-4])+abs({a}[0,0]-{a}[3,-4])+abs({a}[0,0]-{a}[4,-4])+abs({a}[0,0]-{a}[5,-4])+abs({a}[0,0]-{a}[-5,-3])+abs({a}[0,0]-{a}[-4,-3])+abs({a}[0,0]-{a}[-3,-3])+abs({a}[0,0]-{a}[-2,-3])+abs({a}[0,0]-{a}[-1,-3])+abs({a}[0,0]-{a}[0,-3])+abs({a}[0,0]-{a}[1,-3])+abs({a}[0,0]-{a}[2,-3])+abs({a}[0,0]-{a}[3,-3])+abs({a}[0,0]-{a}[4,-3])+abs({a}[0,0]-{a}[5,-3])+abs({a}[0,0]-{a}[-5,-2])+abs({a}[0,0]-{a}[-4,-2])+abs({a}[0,0]-{a}[-3,-2])+abs({a}[0,0]-{a}[-2,-2])+abs({a}[0,0]-{a}[-1,-2])+abs({a}[0,0]-{a}[0,-2])+abs({a}[0,0
]-{a}[1,-2])+abs({a}[0,0]-{a}[2,-2])+abs({a}[0,0]-{a}[3,-2])+abs({a}[0,0]-{a}[4,-2])+abs({a}[0,0]-{a}[5,-2])+abs({a}[0,0]-{a}[-5,-1])+abs({a}[0,0]-{a}[-4,-1])+abs({a}[0,0]-{a}[-3,-1])+abs({a}[0,0]-{a}[-2,-1])+abs({a}[0,0]-{a}[-1,-1])+abs({a}[0,0]-{a}[0,-1])+abs({a}[0,0]-{a}[1,-1])+abs({a}[0,0]-{a}[2,-1])+abs({a}[0,0]-{a}[3,-1])+abs({a}[0,0]-{a}[4,-1])+abs({a}[0,0]-{a}[5,-1])+abs({a}[0,0]-{a}[-5,0])+abs({a}[0,0]-{a}[-4,0])+abs({a}[0,0]-{a}[-3,0])+abs({a}[0,0]-{a}[-2,0])+abs({a}[0,0]-{a}[-1,0])+abs({a}[0,0]-{a}[0,0])+abs({a}[0,0]-{a}[1,0])+abs({a}[0,0]-{a}[2,0])+abs({a}[0,0]-{a}[3,0])+abs({a}[0,0]-{a}[4,0])+abs({a}[0,0]-{a}[5,0])+abs({a}[0,0]-{a}[-5,1])+abs({a}[0,0]-{a}[-4,1])+abs({a}[0,0]-{a}[-3,1])+abs({a}[0,0]-{a}[-2,1])+abs({a}[0,0]-{a}[-1,1])+abs({a}[0,0]-{a}[0,1])+abs({a}[0,0]-{a}[1,1])+abs({a}[0,0]-{a}[2,1])+abs({a}[0,0]-{a}[3,1])+abs({a}[0,0]-{a}[4,1])+abs({a}[0,0]-{a}[5,1])+abs({a}[0,0]-{a}[-5,2])+abs({a}[0,0]-{a}[-4,2])+abs({a}[0,0]-{a}[-3,2])+abs({a}[0,0]-{a}[-2,2])+abs({a}
[0,0]-{a}[-1,2])+abs({a}[0,0]-{a}[0,2])+abs({a}[0,0]-{a}[1,2])+abs({a}[0,0]-{a}[2,2])+abs({a}[0,0]-{a}[3,2])+abs({a}[0,0]-{a}[4,2])+abs({a}[0,0]-{a}[5,2])+abs({a}[0,0]-{a}[-5,3])+abs({a}[0,0]-{a}[-4,3])+abs({a}[0,0]-{a}[-3,3])+abs({a}[0,0]-{a}[-2,3])+abs({a}[0,0]-{a}[-1,3])+abs({a}[0,0]-{a}[0,3])+abs({a}[0,0]-{a}[1,3])+abs({a}[0,0]-{a}[2,3])+abs({a}[0,0]-{a}[3,3])+abs({a}[0,0]-{a}[4,3])+abs({a}[0,0]-{a}[5,3])+abs({a}[0,0]-{a}[-5,4])+abs({a}[0,0]-{a}[-4,4])+abs({a}[0,0]-{a}[-3,4])+abs({a}[0,0]-{a}[-2,4])+abs({a}[0,0]-{a}[-1,4])+abs({a}[0,0]-{a}[0,4])+abs({a}[0,0]-{a}[1,4])+abs({a}[0,0]-{a}[2,4])+abs({a}[0,0]-{a}[3,4])+abs({a}[0,0]-{a}[4,4])+abs({a}[0,0]-{a}[5,4])+abs({a}[0,0]-{a}[-5,5])+abs({a}[0,0]-{a}[-4,5])+abs({a}[0,0]-{a}[-3,5])+abs({a}[0,0]-{a}[-2,5])+abs({a}[0,0]-{a}[-1,5])+abs({a}[0,0]-{a}[0,5])+abs({a}[0,0]-{a}[1,5])+abs({a}[0,0]-{a}[2,5])+abs({a}[0,0]-{a}[3,5])+abs({a}[0,0]-{a}[4,5])+abs({a}[0,0]-{a}[5,5]))/{b}'.format(x=tri, a=dem, b=neighcells))
+
+ return 0
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ sys.exit(main())
Property changes on: grass-addons/grass7/raster/r.tri/r.tri.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list