[GRASS-SVN] r65359 - in grass-addons/grass7/raster: . r.sample.category

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 3 19:54:07 PDT 2015


Author: wenzeslaus
Date: 2015-06-03 19:54:07 -0700 (Wed, 03 Jun 2015)
New Revision: 65359

Modified:
   grass-addons/grass7/raster/Makefile
   grass-addons/grass7/raster/r.sample.category/r.sample.category.html
   grass-addons/grass7/raster/r.sample.category/r.sample.category.py
Log:
r.sample.category: fix bug when Mapset was specified, add example with actual sampling, add to main Makefile

Modified: grass-addons/grass7/raster/Makefile
===================================================================
--- grass-addons/grass7/raster/Makefile	2015-06-04 01:14:52 UTC (rev 65358)
+++ grass-addons/grass7/raster/Makefile	2015-06-04 02:54:07 UTC (rev 65359)
@@ -68,6 +68,7 @@
 	r.regression.series \
 	r.rock.stability \
 	r.roughness.vector \
+	r.sample.category \
 	r.segment \
 	r.shaded.pca \
 	r.shalstab \

Modified: grass-addons/grass7/raster/r.sample.category/r.sample.category.html
===================================================================
--- grass-addons/grass7/raster/r.sample.category/r.sample.category.html	2015-06-04 01:14:52 UTC (rev 65358)
+++ grass-addons/grass7/raster/r.sample.category/r.sample.category.html	2015-06-04 02:54:07 UTC (rev 65359)
@@ -14,10 +14,13 @@
 
 <h2>EXAMPLE</h2>
 
+<h3>Generate random points</h3>
+
 Generate three points at random location for each category (class)
 in the raster map:
 
 <div class="code"><pre>
+g.region raster=landclass96
 r.sample.category input=landclass96 output=landclass_points npoints=3
 </pre></div>
 
@@ -46,6 +49,43 @@
 Figure: Three random points in each category of landclass raster map
 </center>
 
+<h3>Create a table with values sampled from rasters</h3>
+
+Create 2 random points per each category (class) in landclass96 raster
+and sample elevation and geology_30m rasters at these points:
+
+<div class="code"><pre>
+r.sample.category input=landclass96 output=landclass_points sampled=elevation,geology_30m npoints=2
+</pre></div>
+
+Look at the created data:
+
+<div class="code"><pre>
+v.db.select landclass_points sep=comma
+</pre></div>
+
+The result of <em><a href="v.db.select.html">v.db.select</a></em>
+is CSV table which can be used, for example in a spreadsheet application:
+
+<div class="code"><pre>
+cat,landclass96,elevation,geology_30m
+1,1,102.7855,270
+2,1,105.78,270
+3,2,114.5954,217
+4,2,137.4816,921
+5,3,71.19167,270
+6,3,93.33904,270
+7,4,76.41077,262
+8,4,97.54424,217
+9,5,138.455,405
+10,5,88.8075,270
+11,6,126.5298,217
+12,6,86.73177,217
+13,7,134.5381,217
+14,7,99.6844,270
+</pre></div>
+
+
 <h2>KNOWN ISSUES</h2>
 
 The module does not respect mask. More precisely it does not allow mask

Modified: grass-addons/grass7/raster/r.sample.category/r.sample.category.py
===================================================================
--- grass-addons/grass7/raster/r.sample.category/r.sample.category.py	2015-06-04 01:14:52 UTC (rev 65358)
+++ grass-addons/grass7/raster/r.sample.category/r.sample.category.py	2015-06-04 02:54:07 UTC (rev 65359)
@@ -70,10 +70,26 @@
 
 
 def escape_sql_column(name):
+    """Escape string to create a safe name of column for SQL
+
+    >>> escape_sql_column("elevation.10m")
+    elevation_10m
+    """
     name = name.replace('.', '_')
     return name
 
 
+def strip_mapset(name):
+    """Strip Mapset name and '@' from map name
+
+    >>> strip_mapset('elevation at PERMANENT')
+    elevation
+    """
+    if '@' in name:
+        return name.split('@')[0]
+    return name
+
+
 def main():
     options, flags = gscript.parser()
 
@@ -125,8 +141,8 @@
     columns = []
     column_names = []
     sampled_rasters.insert(0, input_raster)
-    for predictor in sampled_rasters:
-        column = escape_sql_column(predictor.lower())
+    for raster in sampled_rasters:
+        column = escape_sql_column(strip_mapset(raster).lower())
         column_names.append(column)
         # TODO: column type according to map type
         columns.append("{column} double precision".format(column=column))



More information about the grass-commit mailing list