[GRASS-SVN] r73259 - grass-addons/grass7/raster/r.neighborhoodmatrix

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Sep 4 11:58:04 PDT 2018


Author: mlennert
Date: 2018-09-04 11:58:04 -0700 (Tue, 04 Sep 2018)
New Revision: 73259

Modified:
   grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.html
   grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.py
Log:
r.neighborhoodmatrix: use r.info, not r.category to test for number of segments + add null check at the end + info about region in manual

Modified: grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.html
===================================================================
--- grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.html	2018-09-04 16:31:01 UTC (rev 73258)
+++ grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.html	2018-09-04 18:58:04 UTC (rev 73259)
@@ -42,7 +42,11 @@
 resolution is not the same in East-West and in North-South direction 
 (rectangular pixels).
 
+<p>
+The module respects the region settings, so if the raster map is outside the 
+current computational region, the resulting list of neighbors will be empty.
 
+
 <h2>TODO</h2>
 
 <ul>

Modified: grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.py
===================================================================
--- grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.py	2018-09-04 16:31:01 UTC (rev 73258)
+++ grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.py	2018-09-04 18:58:04 UTC (rev 73259)
@@ -111,9 +111,8 @@
     if datatype != 'CELL':
         gscript.fatal(_("Input map has to be of CELL (integer) type"))
 
-    numneighbors = len(gscript.read_command('r.category',
-                                            map_=rinput).splitlines())
-    if numneighbors < 2:
+    mapinfo = gscript.raster_info(rinput)
+    if mapinfo['max'] == mapinfo['min']:
         gscript.fatal(_("Need at least two different category values to determine neighbors"))
 
     global separator
@@ -188,11 +187,12 @@
                 OldAcat = Acat
                 OldBcat = Bcat
                 Sum = value
-    if flags['l']:
-        woutput = separator.join([OldAcat, OldBcat, str(Sum)])
-    else:
-        woutput = separator.join([OldAcat, OldBcat])
-    of.write(woutput+"\n")	
+    if OldAcat and OldBcat:
+        if flags['l']:
+            woutput = separator.join([OldAcat, OldBcat, str(Sum)])
+        else:
+            woutput = separator.join([OldAcat, OldBcat])
+        of.write(woutput+"\n")	
     of.close()
 
 if __name__ == "__main__":



More information about the grass-commit mailing list