[GRASS-SVN] r50820 - in grass/trunk/temporal: . tv.observe.strds
tv.what.strds
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Feb 15 04:33:48 EST 2012
Author: huhabla
Date: 2012-02-15 01:33:48 -0800 (Wed, 15 Feb 2012)
New Revision: 50820
Added:
grass/trunk/temporal/tv.observe.strds/
grass/trunk/temporal/tv.observe.strds/test.tv.observe.strds.sh
grass/trunk/temporal/tv.observe.strds/tv.observe.strds.html
grass/trunk/temporal/tv.observe.strds/tv.observe.strds.py
grass/trunk/temporal/tv.what.strds/
grass/trunk/temporal/tv.what.strds/test.tv.what.strds.layer.sh
grass/trunk/temporal/tv.what.strds/test.tv.what.strds.sh
grass/trunk/temporal/tv.what.strds/tv.what.strds.html
grass/trunk/temporal/tv.what.strds/tv.what.strds.py
Removed:
grass/trunk/temporal/tv.observe.rast/
grass/trunk/temporal/tv.observe.strds/test.tv.observe.rast.sh
grass/trunk/temporal/tv.observe.strds/tv.observe.rast.html
grass/trunk/temporal/tv.observe.strds/tv.observe.rast.py
grass/trunk/temporal/tv.what.rast/
grass/trunk/temporal/tv.what.strds/test.tv.what.rast.layer.sh
grass/trunk/temporal/tv.what.strds/test.tv.what.rast.sh
grass/trunk/temporal/tv.what.strds/tv.what.rast.html
grass/trunk/temporal/tv.what.strds/tv.what.rast.py
Modified:
grass/trunk/temporal/tv.observe.strds/Makefile
grass/trunk/temporal/tv.what.strds/Makefile
Log:
More meaningful module naming
Property changes on: grass/trunk/temporal/tv.observe.strds
___________________________________________________________________
Added: svn:ignore
+ .Makefile.swp
.test.tv.observe.strds.sh.swp
Modified: grass/trunk/temporal/tv.observe.strds/Makefile
===================================================================
--- grass/trunk/temporal/tv.observe.rast/Makefile 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.observe.strds/Makefile 2012-02-15 09:33:48 UTC (rev 50820)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../../
-PGM = tv.observe.rast
+PGM = tv.observe.strds
include $(MODULE_TOPDIR)/include/Make/Script.make
Deleted: grass/trunk/temporal/tv.observe.strds/test.tv.observe.rast.sh
===================================================================
--- grass/trunk/temporal/tv.observe.rast/test.tv.observe.rast.sh 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.observe.strds/test.tv.observe.rast.sh 2012-02-15 09:33:48 UTC (rev 50820)
@@ -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.rast 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
Copied: grass/trunk/temporal/tv.observe.strds/test.tv.observe.strds.sh (from rev 50815, grass/trunk/temporal/tv.observe.rast/test.tv.observe.rast.sh)
===================================================================
--- grass/trunk/temporal/tv.observe.strds/test.tv.observe.strds.sh (rev 0)
+++ grass/trunk/temporal/tv.observe.strds/test.tv.observe.strds.sh 2012-02-15 09:33:48 UTC (rev 50820)
@@ -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/tv.observe.strds/tv.observe.rast.html
===================================================================
Deleted: grass/trunk/temporal/tv.observe.strds/tv.observe.rast.py
===================================================================
--- grass/trunk/temporal/tv.observe.rast/tv.observe.rast.py 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.observe.strds/tv.observe.rast.py 2012-02-15 09:33:48 UTC (rev 50820)
@@ -1,224 +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: space time raster dataset
-#% keywords: space time vector dataset
-#% keywords: sampling
-#%end
-
-#%option
-#% key: input
-#% type: string
-#% description: Name of a vector map
-#% required: yes
-#% multiple: no
-#%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
-#% key: where
-#% type: string
-#% description: A where statement for attribute selection related to the input dataset without "WHERE" e.g: "cat < 200"
-#% required: no
-#% multiple: no
-#%end
-
-#%option
-#% key: tempwhere
-#% type: string
-#% description: A where statement for temporal selection related to the input dataset without "WHERE" e.g: "start_time < '2001-01-01' AND end_time > '2001-01-01'"
-#% required: no
-#% multiple: no
-#%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["tempwhere"]
-
- 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(_("Dataset <%s> not found in temporal database") % (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/tv.observe.strds/tv.observe.strds.html (from rev 50815, grass/trunk/temporal/tv.observe.rast/tv.observe.rast.html)
===================================================================
Copied: grass/trunk/temporal/tv.observe.strds/tv.observe.strds.py (from rev 50815, grass/trunk/temporal/tv.observe.rast/tv.observe.rast.py)
===================================================================
--- grass/trunk/temporal/tv.observe.strds/tv.observe.strds.py (rev 0)
+++ grass/trunk/temporal/tv.observe.strds/tv.observe.strds.py 2012-02-15 09:33:48 UTC (rev 50820)
@@ -0,0 +1,224 @@
+#!/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: space time raster dataset
+#% keywords: space time vector dataset
+#% keywords: sampling
+#%end
+
+#%option
+#% key: input
+#% type: string
+#% description: Name of a vector map
+#% required: yes
+#% multiple: no
+#%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
+#% key: where
+#% type: string
+#% description: A where statement for attribute selection related to the input dataset without "WHERE" e.g: "cat < 200"
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: tempwhere
+#% type: string
+#% description: A where statement for temporal selection related to the input dataset without "WHERE" e.g: "start_time < '2001-01-01' AND end_time > '2001-01-01'"
+#% required: no
+#% multiple: no
+#%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["tempwhere"]
+
+ 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(_("Dataset <%s> not found in temporal database") % (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()
+
Property changes on: grass/trunk/temporal/tv.what.strds
___________________________________________________________________
Added: svn:ignore
+ .Makefile.swp
.tv.what.rast.py.swp
.tv.what.strds.py.swp
.test.tv.what.strds.sh.swp
.test.tv.what.strds.layer.sh.swp
Modified: grass/trunk/temporal/tv.what.strds/Makefile
===================================================================
--- grass/trunk/temporal/tv.what.rast/Makefile 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.what.strds/Makefile 2012-02-15 09:33:48 UTC (rev 50820)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../../
-PGM = tv.what.rast
+PGM = tv.what.strds
include $(MODULE_TOPDIR)/include/Make/Script.make
Deleted: grass/trunk/temporal/tv.what.strds/test.tv.what.rast.layer.sh
===================================================================
--- grass/trunk/temporal/tv.what.rast/test.tv.what.rast.layer.sh 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.what.strds/test.tv.what.rast.layer.sh 2012-02-15 09:33:48 UTC (rev 50820)
@@ -1,80 +0,0 @@
-# Test the temporal and spatial sampling of raster maps by vector point maps
-# using timetamped vector tables
-# 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
-# The raster maps
-r.mapcalc --o expr="sand_frac = 50.0"
-r.mapcalc --o expr="sand_frac_1 = 25.0"
-r.mapcalc --o expr="sand_frac_2 = 35.0"
-r.mapcalc --o expr="sand_frac_3 = 45.0"
-r.mapcalc --o expr="sand_frac_4 = 55.0"
-r.mapcalc --o expr="sand_frac_5 = 65.0"
-r.mapcalc --o expr="sand_frac_6 = 75.0"
-# The vector map
-v.random --o -z seed=1 output=soil_orig n=100 zmin=0 zmax=100 column=sand
-# Adding new layer with categories
-v.category input=soil_orig out=soils option=transfer layer=1,2,3,4,5,6 --o
-# Creating new tables for each layer
-db.copy from_table=soil_orig to_table=soils_2
-db.copy from_table=soil_orig to_table=soils_3
-db.copy from_table=soil_orig to_table=soils_4
-db.copy from_table=soil_orig to_table=soils_5
-db.copy from_table=soil_orig to_table=soils_6
-v.db.addtable map=soils table=soils_2 layer=2
-v.db.addtable map=soils table=soils_3 layer=3
-v.db.addtable map=soils table=soils_4 layer=4
-v.db.addtable map=soils table=soils_5 layer=5
-v.db.addtable map=soils table=soils_6 layer=6
-
-n1=`g.tempfile pid=1 -d`
-
-cat > "${n1}" << EOF
-soils:1
-soils:2
-soils:3
-soils:4
-soils:5
-soils:6
-EOF
-
-t.create --o type=stvds temporaltype=absolute output=soil_abs title="A test" descr="A test"
-t.register -i type=vect input=soil_abs file="${n1}" start="2001-03-01 00:00:00" increment="1 months"
-tv.list input=soil_abs columns=name,layer,start_time,end_time
-
-t.create --o type=strds temporaltype=absolute output=sand_frac_abs_1 title="A test" descr="A test"
-t.register -i type=rast input=sand_frac_abs_1 maps=sand_frac start="2001-01-01 00:00:00" increment="12 months"
-tr.list input=sand_frac_abs_1 columns=name,start_time,end_time
-
-t.create --o type=strds temporaltype=absolute output=sand_frac_abs_2 title="A test" descr="A test"
-t.register -i type=rast input=sand_frac_abs_2 maps=sand_frac_1,sand_frac_2,sand_frac_3,sand_frac_4,sand_frac_5,sand_frac_6 \
- start="2001-03-01 00:00:00" increment="1 months"
-tr.list input=sand_frac_abs_2 columns=name,start_time,end_time
-
-# Start the @test
-tv.what.rast --v input=soil_abs strds=sand_frac_abs_1 sampling=overlap,during,contain column=sand_frac
-v.db.select map=soils layer=1
-v.db.select map=soils layer=2
-v.db.select map=soils layer=3
-v.db.select map=soils layer=4
-v.db.select map=soils layer=5
-v.db.select map=soils layer=6
-
-tv.what.rast --v input=soil_abs strds=sand_frac_abs_2 sampling=equal
-v.db.select map=soils layer=1
-v.db.select map=soils layer=2
-v.db.select map=soils layer=3
-v.db.select map=soils layer=4
-v.db.select map=soils layer=5
-v.db.select map=soils layer=6
-
-# @postprocess
-t.unregister type=vect maps=soils:1,soils:2,soils:3,soils:4,soils:5,soils:6
-t.remove type=stvds input=soil_abs
-
-t.unregister type=rast maps=sand_frac,sand_frac_1,sand_frac_2,sand_frac_3,sand_frac_4,sand_frac_5,sand_frac_6
-t.remove type=strds input=sand_frac_abs_1,sand_frac_abs_2
-
-g.remove rast=sand_frac,sand_frac_1,sand_frac_2,sand_frac_3,sand_frac_4,sand_frac_5,sand_frac_6
-g.remove vect=soils,soil_orig
Deleted: grass/trunk/temporal/tv.what.strds/test.tv.what.rast.sh
===================================================================
--- grass/trunk/temporal/tv.what.rast/test.tv.what.rast.sh 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.what.strds/test.tv.what.rast.sh 2012-02-15 09:33:48 UTC (rev 50820)
@@ -1,52 +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=soil_1 n=5 zmin=0 zmax=100 column=heigh seed=1
-v.random --o -z output=soil_2 n=5 zmin=0 zmax=100 column=height seed=2
-v.random --o -z output=soil_3 n=5 zmin=0 zmax=100 column=height seed=3
-
-n1=`g.tempfile pid=1 -d`
-
-cat > "${n1}" << EOF
-soil_1|2001-01-01|2001-04-01
-soil_2|2001-05-01|2001-07-01
-soil_3|2001-08-01|2001-12-01
-EOF
-
-t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" descr="A test"
-t.register type=vect input=soil_abs1 file="${n1}" start=file end=file
-
-t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
-t.register -i type=rast 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.what.rast --v input=soil_abs1 strds=precip_abs1 sampling=start,during column=map_vals
-v.db.select map=soil_1
-v.db.select map=soil_2
-v.db.select map=soil_3
-
-tv.what.rast --v input=soil_abs1 strds=precip_abs1 sampling=start,during
-v.db.select map=soil_1
-v.db.select map=soil_2
-v.db.select map=soil_3
-
-# @postprocess
-t.unregister type=vect maps=soil_1,soil_2,soil_3
-t.remove type=stvds input=soil_abs1
-
-t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-t.remove type=strds input=precip_abs1
-
-g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-g.remove vect=soil_1,soil_2,soil_3
Copied: grass/trunk/temporal/tv.what.strds/test.tv.what.strds.layer.sh (from rev 50815, grass/trunk/temporal/tv.what.rast/test.tv.what.rast.layer.sh)
===================================================================
--- grass/trunk/temporal/tv.what.strds/test.tv.what.strds.layer.sh (rev 0)
+++ grass/trunk/temporal/tv.what.strds/test.tv.what.strds.layer.sh 2012-02-15 09:33:48 UTC (rev 50820)
@@ -0,0 +1,80 @@
+# Test the temporal and spatial sampling of raster maps by vector point maps
+# using timetamped vector tables
+# 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
+# The raster maps
+r.mapcalc --o expr="sand_frac = 50.0"
+r.mapcalc --o expr="sand_frac_1 = 25.0"
+r.mapcalc --o expr="sand_frac_2 = 35.0"
+r.mapcalc --o expr="sand_frac_3 = 45.0"
+r.mapcalc --o expr="sand_frac_4 = 55.0"
+r.mapcalc --o expr="sand_frac_5 = 65.0"
+r.mapcalc --o expr="sand_frac_6 = 75.0"
+# The vector map
+v.random --o -z seed=1 output=soil_orig n=100 zmin=0 zmax=100 column=sand
+# Adding new layer with categories
+v.category input=soil_orig out=soils option=transfer layer=1,2,3,4,5,6 --o
+# Creating new tables for each layer
+db.copy from_table=soil_orig to_table=soils_2
+db.copy from_table=soil_orig to_table=soils_3
+db.copy from_table=soil_orig to_table=soils_4
+db.copy from_table=soil_orig to_table=soils_5
+db.copy from_table=soil_orig to_table=soils_6
+v.db.addtable map=soils table=soils_2 layer=2
+v.db.addtable map=soils table=soils_3 layer=3
+v.db.addtable map=soils table=soils_4 layer=4
+v.db.addtable map=soils table=soils_5 layer=5
+v.db.addtable map=soils table=soils_6 layer=6
+
+n1=`g.tempfile pid=1 -d`
+
+cat > "${n1}" << EOF
+soils:1
+soils:2
+soils:3
+soils:4
+soils:5
+soils:6
+EOF
+
+t.create --o type=stvds temporaltype=absolute output=soil_abs title="A test" descr="A test"
+t.register -i type=vect input=soil_abs file="${n1}" start="2001-03-01 00:00:00" increment="1 months"
+tv.list input=soil_abs columns=name,layer,start_time,end_time
+
+t.create --o type=strds temporaltype=absolute output=sand_frac_abs_1 title="A test" descr="A test"
+t.register -i type=rast input=sand_frac_abs_1 maps=sand_frac start="2001-01-01 00:00:00" increment="12 months"
+tr.list input=sand_frac_abs_1 columns=name,start_time,end_time
+
+t.create --o type=strds temporaltype=absolute output=sand_frac_abs_2 title="A test" descr="A test"
+t.register -i type=rast input=sand_frac_abs_2 maps=sand_frac_1,sand_frac_2,sand_frac_3,sand_frac_4,sand_frac_5,sand_frac_6 \
+ start="2001-03-01 00:00:00" increment="1 months"
+tr.list input=sand_frac_abs_2 columns=name,start_time,end_time
+
+# Start the @test
+tv.what.strds --v input=soil_abs strds=sand_frac_abs_1 sampling=overlap,during,contain column=sand_frac
+v.db.select map=soils layer=1
+v.db.select map=soils layer=2
+v.db.select map=soils layer=3
+v.db.select map=soils layer=4
+v.db.select map=soils layer=5
+v.db.select map=soils layer=6
+
+tv.what.strds --v input=soil_abs strds=sand_frac_abs_2 sampling=equal
+v.db.select map=soils layer=1
+v.db.select map=soils layer=2
+v.db.select map=soils layer=3
+v.db.select map=soils layer=4
+v.db.select map=soils layer=5
+v.db.select map=soils layer=6
+
+# @postprocess
+t.unregister type=vect maps=soils:1,soils:2,soils:3,soils:4,soils:5,soils:6
+t.remove type=stvds input=soil_abs
+
+t.unregister type=rast maps=sand_frac,sand_frac_1,sand_frac_2,sand_frac_3,sand_frac_4,sand_frac_5,sand_frac_6
+t.remove type=strds input=sand_frac_abs_1,sand_frac_abs_2
+
+g.remove rast=sand_frac,sand_frac_1,sand_frac_2,sand_frac_3,sand_frac_4,sand_frac_5,sand_frac_6
+g.remove vect=soils,soil_orig
Copied: grass/trunk/temporal/tv.what.strds/test.tv.what.strds.sh (from rev 50815, grass/trunk/temporal/tv.what.rast/test.tv.what.rast.sh)
===================================================================
--- grass/trunk/temporal/tv.what.strds/test.tv.what.strds.sh (rev 0)
+++ grass/trunk/temporal/tv.what.strds/test.tv.what.strds.sh 2012-02-15 09:33:48 UTC (rev 50820)
@@ -0,0 +1,52 @@
+# 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=soil_1 n=5 zmin=0 zmax=100 column=heigh seed=1
+v.random --o -z output=soil_2 n=5 zmin=0 zmax=100 column=height seed=2
+v.random --o -z output=soil_3 n=5 zmin=0 zmax=100 column=height seed=3
+
+n1=`g.tempfile pid=1 -d`
+
+cat > "${n1}" << EOF
+soil_1|2001-01-01|2001-04-01
+soil_2|2001-05-01|2001-07-01
+soil_3|2001-08-01|2001-12-01
+EOF
+
+t.create --o type=stvds temporaltype=absolute output=soil_abs1 title="A test" descr="A test"
+t.register type=vect input=soil_abs1 file="${n1}"
+
+t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test"
+t.register -i type=rast 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.what.strds --v input=soil_abs1 strds=precip_abs1 sampling=start,during column=map_vals
+v.db.select map=soil_1
+v.db.select map=soil_2
+v.db.select map=soil_3
+
+tv.what.strds --v input=soil_abs1 strds=precip_abs1 sampling=start,during
+v.db.select map=soil_1
+v.db.select map=soil_2
+v.db.select map=soil_3
+
+# @postprocess
+t.unregister type=vect maps=soil_1,soil_2,soil_3
+t.remove type=stvds input=soil_abs1
+
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_abs1
+
+g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+g.remove vect=soil_1,soil_2,soil_3
Deleted: grass/trunk/temporal/tv.what.strds/tv.what.rast.html
===================================================================
Deleted: grass/trunk/temporal/tv.what.strds/tv.what.rast.py
===================================================================
--- grass/trunk/temporal/tv.what.rast/tv.what.rast.py 2012-02-15 06:41:29 UTC (rev 50815)
+++ grass/trunk/temporal/tv.what.strds/tv.what.rast.py 2012-02-15 09:33:48 UTC (rev 50820)
@@ -1,201 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE: tv.what.rast
-# AUTHOR(S): Soeren Gebbert
-#
-# PURPOSE: Uploads raster map values at spatial and temporal positions of vector points to the tables. The maps are registered in space time datasets
-# 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: Uploads raster map values at spatial and temporal positions of vector points to the tables. The maps are registered in space time datasets
-#% keywords: space time vector dataset
-#% keywords: space time raster dataset
-#% keywords: sampling
-#%end
-
-#%option
-#% key: input
-#% type: string
-#% description: Name of a space time vector dataset
-#% required: yes
-#% multiple: no
-#%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. The use of a column name forces tv.what.rast to sample only values from the first map found in an interval. Otherwise the raster map names are used as column names.
-#% required: no
-#% multiple: no
-#%end
-
-#%option
-#% key: where
-#% type: string
-#% description: A where statement for attribute selection related to the input dataset without "WHERE" e.g: "cat < 200"
-#% required: no
-#% multiple: no
-#%end
-
-#%option
-#% key: tempwhere
-#% type: string
-#% description: A where statement for temporal selection related to the input dataset without "WHERE" e.g: "start_time < '2001-01-01' AND end_time > '2001-01-01'"
-#% required: no
-#% multiple: no
-#%end
-
-#%option
-#% key: sampling
-#% type: string
-#% description: The method to be used for temporal sampling
-#% required: no
-#% multiple: yes
-#% options: start,during,overlap,contain,equal
-#% answer: start
-#%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"]
- strds = options["strds"]
- where = options["where"]
- column = options["column"]
- tempwhere = options["tempwhere"]
- sampling = options["sampling"]
-
- 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 input.find("@") >= 0:
- id = input
- else:
- id = input + "@" + mapset
-
- sp = tgis.space_time_vector_dataset(id)
-
- if sp.is_in_db() == False:
- dbif.close()
- grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
-
- sp.select(dbif)
-
- 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(_("Dataset <%s> not found in temporal database") % (id))
-
- strds_sp.select(dbif)
-
- if strds_sp.get_temporal_type() != sp.get_temporal_type():
- dbif.close()
- grass.fatal(_("Input and aggregation dataset must have the same temporal type"))
-
- # Check if intervals are present
- if sp.get_temporal_type() == "absolute":
- map_time = strds_sp.absolute_time.get_map_time()
- else:
- map_time = strds_sp.relative_time.get_map_time()
-
- if map_time != "interval":
- dbif.close()
- grass.fatal(_("All registered maps of the space time vector dataset must have time intervals"))
-
- rows = sp.get_registered_maps("name,layer,mapset,start_time,end_time", tempwhere, "start_time", dbif)
- dummy = tgis.vector_dataset(None)
-
- if not rows:
- dbif.close()
- grass.fatal(_("Space time vector dataset <%s> is empty") % sg.get_id())
-
- # Sample the raster dataset with the vector dataset and run v.what.rast
- for row in rows:
- start = row["start_time"]
- end = row["end_time"]
- vectmap = row["name"] + "@" + row["mapset"]
- layer = row["layer"]
-
- raster_maps = tgis.collect_map_names(strds_sp, dbif, start, end, sampling)
-
- if raster_maps:
- # Collect the names of the raster maps
- for rastermap in raster_maps:
-
- if column:
- col_name = column
- else:
- # Create a new column with the SQL compliant name of the sampled raster map
- col_name = rastermap.split("@")[0].replace(".", "_")
-
- coltype = "DOUBLE PRECISION"
- # Get raster type
- rasterinfo = raster.raster_info(rastermap)
- if rasterinfo["datatype"] == "CELL":
- coltype = "INT"
-
- if layer:
- ret = grass.run_command("v.db.addcolumn", map=vectmap, layer=layer, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
- else:
- ret = grass.run_command("v.db.addcolumn", map=vectmap, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
-
- if ret != 0:
- dbif.close()
- grass.fatal(_("Unable to add column %s to vector map <%s>")%(col_name, vectmap))
-
- # Call v.what.rast
- if layer:
- ret = grass.run_command("v.what.rast", map=vectmap, layer=layer, raster=rastermap, column=col_name, where=where)
- else:
- ret = grass.run_command("v.what.rast", map=vectmap, raster=rastermap, column=col_name, where=where)
- if ret != 0:
- dbif.close()
- grass.fatal(_("Unable to run v.what.rast for vector map <%s> and raster map <%s>")%(vectmap, rastermap))
-
- # Use the first map in case a column names was provided
- if column:
- break
-
- dbif.close()
-
-if __name__ == "__main__":
- options, flags = grass.parser()
- main()
-
Copied: grass/trunk/temporal/tv.what.strds/tv.what.strds.html (from rev 50815, grass/trunk/temporal/tv.what.rast/tv.what.rast.html)
===================================================================
Copied: grass/trunk/temporal/tv.what.strds/tv.what.strds.py (from rev 50815, grass/trunk/temporal/tv.what.rast/tv.what.rast.py)
===================================================================
--- grass/trunk/temporal/tv.what.strds/tv.what.strds.py (rev 0)
+++ grass/trunk/temporal/tv.what.strds/tv.what.strds.py 2012-02-15 09:33:48 UTC (rev 50820)
@@ -0,0 +1,201 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE: tv.what.strds
+# AUTHOR(S): Soeren Gebbert
+#
+# PURPOSE: Uploads raster map values at spatial and temporal positions of vector points to the tables. The maps are registered in space time datasets
+# 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: Uploads raster map values at spatial and temporal positions of vector points to the tables. The maps are registered in space time datasets
+#% keywords: space time vector dataset
+#% keywords: space time raster dataset
+#% keywords: sampling
+#%end
+
+#%option
+#% key: input
+#% type: string
+#% description: Name of a space time vector dataset
+#% required: yes
+#% multiple: no
+#%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. The use of a column name forces tv.what.rast to sample only values from the first map found in an interval. Otherwise the raster map names are used as column names.
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: where
+#% type: string
+#% description: A where statement for attribute selection related to the input dataset without "WHERE" e.g: "cat < 200"
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: tempwhere
+#% type: string
+#% description: A where statement for temporal selection related to the input dataset without "WHERE" e.g: "start_time < '2001-01-01' AND end_time > '2001-01-01'"
+#% required: no
+#% multiple: no
+#%end
+
+#%option
+#% key: sampling
+#% type: string
+#% description: The method to be used for temporal sampling
+#% required: no
+#% multiple: yes
+#% options: start,during,overlap,contain,equal
+#% answer: start
+#%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"]
+ strds = options["strds"]
+ where = options["where"]
+ column = options["column"]
+ tempwhere = options["tempwhere"]
+ sampling = options["sampling"]
+
+ 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 input.find("@") >= 0:
+ id = input
+ else:
+ id = input + "@" + mapset
+
+ sp = tgis.space_time_vector_dataset(id)
+
+ if sp.is_in_db() == False:
+ dbif.close()
+ grass.fatal(_("Dataset <%s> not found in temporal database") % (id))
+
+ sp.select(dbif)
+
+ 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(_("Dataset <%s> not found in temporal database") % (id))
+
+ strds_sp.select(dbif)
+
+ if strds_sp.get_temporal_type() != sp.get_temporal_type():
+ dbif.close()
+ grass.fatal(_("Input and aggregation dataset must have the same temporal type"))
+
+ # Check if intervals are present
+ if sp.get_temporal_type() == "absolute":
+ map_time = strds_sp.absolute_time.get_map_time()
+ else:
+ map_time = strds_sp.relative_time.get_map_time()
+
+ if map_time != "interval":
+ dbif.close()
+ grass.fatal(_("All registered maps of the space time vector dataset must have time intervals"))
+
+ rows = sp.get_registered_maps("name,layer,mapset,start_time,end_time", tempwhere, "start_time", dbif)
+ dummy = tgis.vector_dataset(None)
+
+ if not rows:
+ dbif.close()
+ grass.fatal(_("Space time vector dataset <%s> is empty") % sg.get_id())
+
+ # Sample the raster dataset with the vector dataset and run v.what.rast
+ for row in rows:
+ start = row["start_time"]
+ end = row["end_time"]
+ vectmap = row["name"] + "@" + row["mapset"]
+ layer = row["layer"]
+
+ raster_maps = tgis.collect_map_names(strds_sp, dbif, start, end, sampling)
+
+ if raster_maps:
+ # Collect the names of the raster maps
+ for rastermap in raster_maps:
+
+ if column:
+ col_name = column
+ else:
+ # Create a new column with the SQL compliant name of the sampled raster map
+ col_name = rastermap.split("@")[0].replace(".", "_")
+
+ coltype = "DOUBLE PRECISION"
+ # Get raster type
+ rasterinfo = raster.raster_info(rastermap)
+ if rasterinfo["datatype"] == "CELL":
+ coltype = "INT"
+
+ if layer:
+ ret = grass.run_command("v.db.addcolumn", map=vectmap, layer=layer, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
+ else:
+ ret = grass.run_command("v.db.addcolumn", map=vectmap, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
+
+ if ret != 0:
+ dbif.close()
+ grass.fatal(_("Unable to add column %s to vector map <%s>")%(col_name, vectmap))
+
+ # Call v.what.rast
+ if layer:
+ ret = grass.run_command("v.what.rast", map=vectmap, layer=layer, raster=rastermap, column=col_name, where=where)
+ else:
+ ret = grass.run_command("v.what.rast", map=vectmap, raster=rastermap, column=col_name, where=where)
+ if ret != 0:
+ dbif.close()
+ grass.fatal(_("Unable to run v.what.rast for vector map <%s> and raster map <%s>")%(vectmap, rastermap))
+
+ # Use the first map in case a column names was provided
+ if column:
+ break
+
+ dbif.close()
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
+
More information about the grass-commit
mailing list