[GRASS-SVN] r33788 - in grass/trunk: lib/python scripts/i.fusion.brovey scripts/i.image.mosaic scripts/v.rast.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 9 07:23:35 EDT 2008


Author: glynn
Date: 2008-10-09 07:23:35 -0400 (Thu, 09 Oct 2008)
New Revision: 33788

Modified:
   grass/trunk/lib/python/grass.py
   grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py
   grass/trunk/scripts/i.image.mosaic/i.image.mosaic.py
   grass/trunk/scripts/v.rast.stats/v.rast.stats.py
Log:
Add, use raster_info function (interface to r.info)


Modified: grass/trunk/lib/python/grass.py
===================================================================
--- grass/trunk/lib/python/grass.py	2008-10-09 10:42:55 UTC (rev 33787)
+++ grass/trunk/lib/python/grass.py	2008-10-09 11:23:35 UTC (rev 33788)
@@ -518,3 +518,12 @@
     """
     run_command('r.support', map = map, history = os.environ['CMDLINE'])
 
+# run "r.info -rgstmpud ..." and parse output
+
+def raster_info(map):
+    """Return information about a raster map (interface to `r.info')."""
+    s = read_command('r.info', flags = 'rgstmpud', map = map)
+    kv = parse_key_val(s)
+    for k in ['min', 'max', 'north', 'south', 'east', 'west', 'nsres', 'ewres']:
+	kv[k] = float(kv[k])
+    return kv

Modified: grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py
===================================================================
--- grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py	2008-10-09 10:42:55 UTC (rev 33787)
+++ grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py	2008-10-09 11:23:35 UTC (rev 33788)
@@ -103,10 +103,9 @@
 	grass.fatal("Please select a flag to specify the satellite sensor")
 
     #get PAN resolution:
-    s = grass.read_command('r.info', flags = 's', map = pan)
-    kv = grass.parse_key_val(s)
-    nsres = float(kv['nsres'])
-    ewres = float(kv['ewres'])
+    kv = grass.raster_info(map = pan)
+    nsres = kv['nsres']
+    ewres = kv['ewres']
     panres = (nsres + ewres) / 2
 
     # clone current region

Modified: grass/trunk/scripts/i.image.mosaic/i.image.mosaic.py
===================================================================
--- grass/trunk/scripts/i.image.mosaic/i.image.mosaic.py	2008-10-09 10:42:55 UTC (rev 33787)
+++ grass/trunk/scripts/i.image.mosaic/i.image.mosaic.py	2008-10-09 11:23:35 UTC (rev 33788)
@@ -59,9 +59,7 @@
     p.wait()
 
 def get_limit(map):
-    s = grass.read_command('r.info', flags = 'r', map = map)
-    kv = grass.parse_key_val(s)
-    return float(kv['max'])
+    return grass.raster_info(map)['max']
 
 def make_expression(i, count):
     if i > count:

Modified: grass/trunk/scripts/v.rast.stats/v.rast.stats.py
===================================================================
--- grass/trunk/scripts/v.rast.stats/v.rast.stats.py	2008-10-09 10:42:55 UTC (rev 33787)
+++ grass/trunk/scripts/v.rast.stats/v.rast.stats.py	2008-10-09 11:23:35 UTC (rev 33788)
@@ -79,11 +79,12 @@
     if mask_found:
 	grass.message("Restoring previous MASK...")
 	grass.run_command('g.rename', rast = (tmpname + "_origmask", 'MASK'), quiet = True)
-    for f in [tmp, tmpname, sqltmp]:
-	grass.try_remove(f)
+#    for f in [tmp, tmpname, sqltmp]:
+#	grass.try_remove(f)
 
 def main():
     global tmp, sqltmp, tmpname, nuldev, vector, mask_found
+    mask_found = False
     #### setup temporary files
     tmp = grass.tempfile()
     sqltmp = tmp + ".sql"
@@ -126,10 +127,9 @@
 
     #get RASTER resolution of map which we want to query:
     #fetch separated to permit for non-square cells (latlong etc)
-    s = grass.read_command('r.info', flags = 's', map = raster)
-    kv = grass.parse_key_val(s)
-    nsres = float(kv['nsres'])
-    ewres = float(kv['ewres'])
+    kv = grass.raster_info(map = raster)
+    nsres = kv['nsres']
+    ewres = kv['ewres']
 
     #save current settings:
     grass.use_temp_region()
@@ -205,9 +205,10 @@
 		coltype = "DOUBLE PRECISION"
 	    addcols.append(currcolumn + ' ' + coltype)
 
-    grass.verbose("Adding columns <%s>" % addcols)
-    if grass.run_command('v.db.addcol', map = vector, columns = addcols) != 0:
-	grass.fatal("Cannot continue (problem adding columns).")
+    if addcols:
+	grass.verbose("Adding columns <%s>" % addcols)
+	if grass.run_command('v.db.addcol', map = vector, columns = addcols) != 0:
+	    grass.fatal("Cannot continue (problem adding columns).")
 
     #loop over cats and calculate statistics:
     grass.verbose("Processing data ...")



More information about the grass-commit mailing list