[GRASS-SVN] r73123 - grass-addons/grass7/raster/r.terrain.texture

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 19 21:41:47 PDT 2018


Author: spawley
Date: 2018-08-19 21:41:47 -0700 (Sun, 19 Aug 2018)
New Revision: 73123

Modified:
   grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py
Log:
Bug fix for calculation of raster stats for terrain classification

Modified: grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py
===================================================================
--- grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py	2018-08-18 09:28:45 UTC (rev 73122)
+++ grass-addons/grass7/raster/r.terrain.texture/r.terrain.texture.py	2018-08-20 04:41:47 UTC (rev 73123)
@@ -99,6 +99,7 @@
 #% required : no
 #%end
 
+
 import os
 import sys
 import random
@@ -305,6 +306,7 @@
 
 
 def main():
+
     elevation = options['elevation']
     slope = options['slope']
     flat_thres = float(options['flat_thres'])
@@ -323,18 +325,6 @@
     concavity = concavity.split('@')[0]
     features = features.split('@')[0]
 
-    # error checking
-    if flat_thres < 0:
-        gs.fatal('Parameter thres cannot be negative')
-
-    if filter_size % 2 == 0 or counting_size % 2 == 0:
-        gs.fatal(
-            'Filter or counting windows require an odd-numbered window size')
-
-    if filter_size >= counting_size:
-        gs.fatal(
-            'Filter size needs to be smaller than the counting window size')
-
     # store current region settings
     global current_reg
     current_reg = parse_key_val(g.region(flags='pg', stdout_=PIPE).outputs.stdout)
@@ -341,7 +331,7 @@
     del current_reg['projection']
     del current_reg['zone']
     del current_reg['cells']
-    
+
     # check for existing mask and backup if found
     global mask_test
     mask_test = gs.list_grouped(
@@ -350,6 +340,21 @@
         global original_mask
         original_mask = temp_map('tmp_original_mask')
         g.copy(raster=['MASK', original_mask])
+
+    # error checking
+    if flat_thres < 0:
+        gs.fatal('Parameter thres cannot be negative')
+
+    if filter_size % 2 == 0 or counting_size % 2 == 0:
+        gs.fatal(
+            'Filter or counting windows require an odd-numbered window size')
+
+    if filter_size >= counting_size:
+        gs.fatal(
+            'Filter size needs to be smaller than the counting window size')
+    
+    if features != '' and slope == '':
+        gs.fatal('Need to supply a slope raster in order to produce the terrain classification')
                 
     # Terrain Surface Texture -------------------------------------------------
     # smooth the dem
@@ -466,12 +471,17 @@
                 r.mask(raster=clf_msk, flags='i', quiet=True, overwrite=True)
 
             # image statistics
-            smean = parse_key_val(r.univar(
-                map=slope, flags='g', stdout_=PIPE).outputs.stdout)['mean']
-            cmean = parse_key_val(r.univar(
-                map=convexity, flags='g', stdout_=PIPE).outputs.stdout)['mean']
-            tmean = parse_key_val(r.univar(
-                map=texture, flags='g', stdout_=PIPE).outputs.stdout)['mean']
+            smean = r.univar(
+                map=slope, flags='g', stdout_=PIPE).outputs.stdout.split(os.linesep)
+            smean = [i for i in smean if i.startswith('mean=') is True][0].split('=')[1]
+
+            cmean = r.univar(
+                map=convexity, flags='g', stdout_=PIPE).outputs.stdout.split(os.linesep)
+            cmean = [i for i in cmean if i.startswith('mean=') is True][0].split('=')[1]
+
+            tmean = r.univar(
+                map=texture, flags='g', stdout_=PIPE).outputs.stdout.split(os.linesep)
+            tmean = [i for i in tmean if i.startswith('mean=') is True][0].split('=')[1]
             classif.append(temp_map('tmp_classes'))
             
             if level != 0:



More information about the grass-commit mailing list