[GRASS-SVN] r51254 - in grass/trunk/temporal: . t.vect.observe.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 4 08:26:24 EDT 2012


Author: huhabla
Date: 2012-04-04 05:26:24 -0700 (Wed, 04 Apr 2012)
New Revision: 51254

Added:
   grass/trunk/temporal/t.vect.observe.strds/
   grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.html
   grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
   grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh
Removed:
   grass/trunk/temporal/t.vect.observe.strds/test.tv.observe.strds.sh
   grass/trunk/temporal/t.vect.observe.strds/tv.observe.strds.html
   grass/trunk/temporal/t.vect.observe.strds/tv.observe.strds.py
Modified:
   grass/trunk/temporal/t.vect.observe.strds/Makefile
Log:
Renamed tv.observe.strds to meet new naming scheme


Modified: grass/trunk/temporal/t.vect.observe.strds/Makefile
===================================================================
--- grass/trunk/temporal/tv.observe.strds/Makefile	2012-04-04 09:39:32 UTC (rev 51251)
+++ grass/trunk/temporal/t.vect.observe.strds/Makefile	2012-04-04 12:26:24 UTC (rev 51254)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../../
 
-PGM = tv.observe.strds
+PGM = t.vect.observe.strds
 
 include $(MODULE_TOPDIR)/include/Make/Script.make
 

Copied: grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.html (from rev 51251, grass/trunk/temporal/tv.observe.strds/tv.observe.strds.html)
===================================================================
Copied: grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py (from rev 51251, grass/trunk/temporal/tv.observe.strds/tv.observe.strds.py)
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	                        (rev 0)
+++ grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2012-04-04 12:26:24 UTC (rev 51254)
@@ -0,0 +1,209 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:	t.vect.oberve.rast
+# AUTHOR(S):	Soeren Gebbert
+#
+# PURPOSE:	Observe specific locations in a space time raster dataset over a periode of time using vector points
+# COPYRIGHT:	(C) 2011 by the GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (version 2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+#%module
+#% description: Observe specific locations in a space time raster dataset over a periode of time using vector points
+#% keywords: temporal
+#% keywords: sampling
+#%end
+
+#%option G_OPT_STVDS_INPUT
+#%end
+
+#%option
+#% key: strds
+#% type: string
+#% description: The space time raster dataset to use
+#% required: yes
+#% multiple: no
+#%end
+
+#%option
+#% key: column
+#% type: string
+#% description: Name of the vector column to be created and to store sampled raster values, otherwise the space time raster name is used as column name 
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: output
+#% type: string
+#% description: Name the new created space time vector dataset and the new vector map 
+#% required: yes
+#% multiple: no
+#%end
+
+#%option G_OPT_DB_WHERE
+#%end
+
+#%option G_OPT_T_WHERE
+#% key: t_where
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+import grass.script.raster as raster
+
+############################################################################
+
+def main():
+
+    # Get the options
+    input = options["input"]
+    output = options["output"]
+    strds = options["strds"]
+    where = options["where"]
+    column = options["column"]
+    tempwhere = options["t_where"]
+
+    if where == "" or where == " " or where == "\n":
+        where = None
+
+    # Make sure the temporal database exists
+    tgis.create_temporal_database()
+    # We need a database interface
+    dbif = tgis.sql_database_interface()
+    dbif.connect()
+   
+    mapset =  grass.gisenv()["MAPSET"]
+
+    if strds.find("@") >= 0:
+        strds_id = strds
+    else:
+        strds_id = strds + "@" + mapset
+
+    strds_sp = tgis.space_time_raster_dataset(strds_id)
+    
+    if strds_sp.is_in_db() == False:
+        dbif.close()
+        grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
+
+    strds_sp.select(dbif)
+
+    if output.find("@") >= 0:
+        id = output
+    else:
+        id = output + "@" + mapset
+
+    out_sp = tgis.space_time_vector_dataset(id)
+    
+    if out_sp.is_in_db(dbif) == True and grass.overwrite() == False: 
+        dbif.close()
+        grass.fatal(_("Dataset <%s> found in temporal database, use the overwrite flag to overwrite") % (id))
+
+    # Overwrite existing stvds
+    if out_sp.is_in_db(dbif) == True and grass.overwrite() == True:
+        out_sp.select()
+        out_sp.delete()
+        out_sp = tgis.space_time_vector_dataset(id)
+
+    # Select the raster maps
+    rows = strds_sp.get_registered_maps("name,mapset,start_time,end_time", tempwhere, "start_time", dbif)
+
+    if not rows:
+        dbif.close()
+        grass.fatal(_("Space time vector dataset <%s> is empty") % sg.get_id())
+
+    # Create the output space time vector dataset
+
+    out_sp.set_initial_values(strds_sp.get_temporal_type(), \
+                              strds_sp.get_semantic_type(),\
+                              _("Observation of space time raster dataset <%s>")%(strds_id),\
+                              _("Observattion of space time raster dataset <%s> with vector map <%s>")%(strds_id, input))
+
+    out_sp.insert(dbif)
+
+    num_rows = len(rows)
+
+    # We copy the vector table and create the new layers
+    layers= ""
+    first = True
+    for layer in range(num_rows):
+        layer += 1
+        if first:
+            layers += "%i"%(layer)    
+            first = False
+        else:
+            layers += ",%i"%(layer)    
+
+    print layers
+
+    vectmap = output
+    ret = grass.run_command("v.category", input=input, layer=layers, output=vectmap, option="transfer", overwrite=grass.overwrite())
+    if ret != 0:
+        grass.fatal(_("Unable to create new layers for vector map <%s>") % (vectmap))
+        
+    dummy = out_sp.get_new_map_instance(None)
+
+    # Sample the space time raster dataset with the vector map at specific layer with v.what.rast
+    count = 1
+    for row in rows:
+        start = row["start_time"]
+        end = row["end_time"]
+        rastmap = row["name"] + "@" + row["mapset"]
+
+	if column:
+	    col_name = column
+	else:
+	    # Create a new column with name of the sampled space time raster dataset
+	    col_name = row["name"]
+
+	coltype = "DOUBLE PRECISION"
+	# Get raster map type
+	rasterinfo = raster.raster_info(rastmap)
+	if rasterinfo["datatype"] == "CELL":
+	    coltype = "INT"
+	
+        # Try to add a column
+	ret = grass.run_command("v.db.addcolumn", map=vectmap, layer=count, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
+	if ret != 0:
+            # Try to add a new table
+            grass.message("Add table to layer %i"%(count))
+	    ret = grass.run_command("v.db.addtable", map=vectmap, layer=count, columns="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
+	    if ret != 0:
+	        dbif.close()
+	        grass.fatal(_("Unable to add column %s to vector map <%s> with layer %i")%(col_name, vectmap, count))
+
+	# Call v.what.rast
+	ret = grass.run_command("v.what.rast", map=vectmap, layer=count, raster=rastmap, column=col_name, where=where)
+	if ret != 0:
+	    dbif.close()
+	    grass.fatal(_("Unable to run v.what.rast for vector map <%s> with layer %i and raster map <%s>")%(vectmap, count, rastmap))
+        
+        vect = out_sp.get_new_map_instance(dummy.build_id(vectmap, mapset, str(count)))
+        vect.load()
+ 
+        if out_sp.is_time_absolute():
+            vect.set_absolute_time(start, end)
+        else:
+            vect.set_relative_time(start, end, strds_ds.get_relative_time_unit())
+       
+        if vect.is_in_db():
+            vect.update(dbif)
+        else:
+            vect.insert(dbif)
+
+        out_sp.register_map(vect, dbif) 
+        count += 1
+
+    out_sp.update_from_registered_maps(dbif)
+    dbif.close()
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()
+

Copied: grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh (from rev 51251, grass/trunk/temporal/tv.observe.strds/test.tv.observe.strds.sh)
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh	                        (rev 0)
+++ grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh	2012-04-04 12:26:24 UTC (rev 51254)
@@ -0,0 +1,31 @@
+# Test the temporal and spatial sampling of raster maps by vector point maps
+# We need to set a specific region in the
+# @preprocess step of this test. 
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc --o expr="prec_1 = 100.0"
+r.mapcalc --o expr="prec_2 = 200.0"
+r.mapcalc --o expr="prec_3 = 300"
+r.mapcalc --o expr="prec_4 = 400"
+r.mapcalc --o expr="prec_5 = 500.0"
+r.mapcalc --o expr="prec_6 = 600.0"
+
+v.random --o -z output=prec n=5 seed=1
+
+t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
+t.register -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-03-01 00:00:00" increment="1 months"
+
+# The @test
+tv.observe.strds input=prec strds=precip_abs1 output=prec_observer 
+v.info prec_observer
+t.info type=stvds input=prec_observer
+
+# @postprocess
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_abs1
+t.remove type=stvds input=prec_observer
+t.unregister type=vect maps=prec_observer:1,prec_observer:2,prec_observer:3,prec_observer:4,prec_observer:5,prec_observer:6
+
+g.remove vect=prec_observer
+g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6

Deleted: grass/trunk/temporal/t.vect.observe.strds/test.tv.observe.strds.sh
===================================================================
--- grass/trunk/temporal/tv.observe.strds/test.tv.observe.strds.sh	2012-04-04 09:39:32 UTC (rev 51251)
+++ grass/trunk/temporal/t.vect.observe.strds/test.tv.observe.strds.sh	2012-04-04 12:26:24 UTC (rev 51254)
@@ -1,31 +0,0 @@
-# Test the temporal and spatial sampling of raster maps by vector point maps
-# We need to set a specific region in the
-# @preprocess step of this test. 
-# The region setting should work for UTM and LL test locations
-g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
-
-r.mapcalc --o expr="prec_1 = 100.0"
-r.mapcalc --o expr="prec_2 = 200.0"
-r.mapcalc --o expr="prec_3 = 300"
-r.mapcalc --o expr="prec_4 = 400"
-r.mapcalc --o expr="prec_5 = 500.0"
-r.mapcalc --o expr="prec_6 = 600.0"
-
-v.random --o -z output=prec n=5 seed=1
-
-t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-03-01 00:00:00" increment="1 months"
-
-# The @test
-tv.observe.strds input=prec strds=precip_abs1 output=prec_observer 
-v.info prec_observer
-t.info type=stvds input=prec_observer
-
-# @postprocess
-t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-t.remove type=strds input=precip_abs1
-t.remove type=stvds input=prec_observer
-t.unregister type=vect maps=prec_observer:1,prec_observer:2,prec_observer:3,prec_observer:4,prec_observer:5,prec_observer:6
-
-g.remove vect=prec_observer
-g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6

Deleted: grass/trunk/temporal/t.vect.observe.strds/tv.observe.strds.html
===================================================================
Deleted: grass/trunk/temporal/t.vect.observe.strds/tv.observe.strds.py
===================================================================
--- grass/trunk/temporal/tv.observe.strds/tv.observe.strds.py	2012-04-04 09:39:32 UTC (rev 51251)
+++ grass/trunk/temporal/t.vect.observe.strds/tv.observe.strds.py	2012-04-04 12:26:24 UTC (rev 51254)
@@ -1,209 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE:	tv.oberve.rast
-# AUTHOR(S):	Soeren Gebbert
-#
-# PURPOSE:	Observe specific locations in a space time raster dataset over a periode of time using vector points
-# COPYRIGHT:	(C) 2011 by the GRASS Development Team
-#
-#		This program is free software under the GNU General Public
-#		License (version 2). Read the file COPYING that comes with GRASS
-#		for details.
-#
-#############################################################################
-
-#%module
-#% description: Observe specific locations in a space time raster dataset over a periode of time using vector points
-#% keywords: temporal
-#% keywords: sampling
-#%end
-
-#%option G_OPT_STVDS_INPUT
-#%end
-
-#%option
-#% key: strds
-#% type: string
-#% description: The space time raster dataset to use
-#% required: yes
-#% multiple: no
-#%end
-
-#%option
-#% key: column
-#% type: string
-#% description: Name of the vector column to be created and to store sampled raster values, otherwise the space time raster name is used as column name 
-#% required: no
-#% multiple: no
-#%end
-
-#%option
-#% key: output
-#% type: string
-#% description: Name the new created space time vector dataset and the new vector map 
-#% required: yes
-#% multiple: no
-#%end
-
-#%option G_OPT_DB_WHERE
-#%end
-
-#%option G_OPT_T_WHERE
-#% key: t_where
-#%end
-
-import grass.script as grass
-import grass.temporal as tgis
-import grass.script.raster as raster
-
-############################################################################
-
-def main():
-
-    # Get the options
-    input = options["input"]
-    output = options["output"]
-    strds = options["strds"]
-    where = options["where"]
-    column = options["column"]
-    tempwhere = options["t_where"]
-
-    if where == "" or where == " " or where == "\n":
-        where = None
-
-    # Make sure the temporal database exists
-    tgis.create_temporal_database()
-    # We need a database interface
-    dbif = tgis.sql_database_interface()
-    dbif.connect()
-   
-    mapset =  grass.gisenv()["MAPSET"]
-
-    if strds.find("@") >= 0:
-        strds_id = strds
-    else:
-        strds_id = strds + "@" + mapset
-
-    strds_sp = tgis.space_time_raster_dataset(strds_id)
-    
-    if strds_sp.is_in_db() == False:
-        dbif.close()
-        grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
-
-    strds_sp.select(dbif)
-
-    if output.find("@") >= 0:
-        id = output
-    else:
-        id = output + "@" + mapset
-
-    out_sp = tgis.space_time_vector_dataset(id)
-    
-    if out_sp.is_in_db(dbif) == True and grass.overwrite() == False: 
-        dbif.close()
-        grass.fatal(_("Dataset <%s> found in temporal database, use the overwrite flag to overwrite") % (id))
-
-    # Overwrite existing stvds
-    if out_sp.is_in_db(dbif) == True and grass.overwrite() == True:
-        out_sp.select()
-        out_sp.delete()
-        out_sp = tgis.space_time_vector_dataset(id)
-
-    # Select the raster maps
-    rows = strds_sp.get_registered_maps("name,mapset,start_time,end_time", tempwhere, "start_time", dbif)
-
-    if not rows:
-        dbif.close()
-        grass.fatal(_("Space time vector dataset <%s> is empty") % sg.get_id())
-
-    # Create the output space time vector dataset
-
-    out_sp.set_initial_values(strds_sp.get_temporal_type(), \
-                              strds_sp.get_semantic_type(),\
-                              _("Observation of space time raster dataset <%s>")%(strds_id),\
-                              _("Observattion of space time raster dataset <%s> with vector map <%s>")%(strds_id, input))
-
-    out_sp.insert(dbif)
-
-    num_rows = len(rows)
-
-    # We copy the vector table and create the new layers
-    layers= ""
-    first = True
-    for layer in range(num_rows):
-        layer += 1
-        if first:
-            layers += "%i"%(layer)    
-            first = False
-        else:
-            layers += ",%i"%(layer)    
-
-    print layers
-
-    vectmap = output
-    ret = grass.run_command("v.category", input=input, layer=layers, output=vectmap, option="transfer", overwrite=grass.overwrite())
-    if ret != 0:
-        grass.fatal(_("Unable to create new layers for vector map <%s>") % (vectmap))
-        
-    dummy = out_sp.get_new_map_instance(None)
-
-    # Sample the space time raster dataset with the vector map at specific layer with v.what.rast
-    count = 1
-    for row in rows:
-        start = row["start_time"]
-        end = row["end_time"]
-        rastmap = row["name"] + "@" + row["mapset"]
-
-	if column:
-	    col_name = column
-	else:
-	    # Create a new column with name of the sampled space time raster dataset
-	    col_name = row["name"]
-
-	coltype = "DOUBLE PRECISION"
-	# Get raster map type
-	rasterinfo = raster.raster_info(rastmap)
-	if rasterinfo["datatype"] == "CELL":
-	    coltype = "INT"
-	
-        # Try to add a column
-	ret = grass.run_command("v.db.addcolumn", map=vectmap, layer=count, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
-	if ret != 0:
-            # Try to add a new table
-            grass.message("Add table to layer %i"%(count))
-	    ret = grass.run_command("v.db.addtable", map=vectmap, layer=count, columns="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
-	    if ret != 0:
-	        dbif.close()
-	        grass.fatal(_("Unable to add column %s to vector map <%s> with layer %i")%(col_name, vectmap, count))
-
-	# Call v.what.rast
-	ret = grass.run_command("v.what.rast", map=vectmap, layer=count, raster=rastmap, column=col_name, where=where)
-	if ret != 0:
-	    dbif.close()
-	    grass.fatal(_("Unable to run v.what.rast for vector map <%s> with layer %i and raster map <%s>")%(vectmap, count, rastmap))
-        
-        vect = out_sp.get_new_map_instance(dummy.build_id(vectmap, mapset, str(count)))
-        vect.load()
- 
-        if out_sp.is_time_absolute():
-            vect.set_absolute_time(start, end)
-        else:
-            vect.set_relative_time(start, end, strds_ds.get_relative_time_unit())
-       
-        if vect.is_in_db():
-            vect.update(dbif)
-        else:
-            vect.insert(dbif)
-
-        out_sp.register_map(vect, dbif) 
-        count += 1
-
-    out_sp.update_from_registered_maps(dbif)
-    dbif.close()
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()
-



More information about the grass-commit mailing list