[GRASS-SVN] r52252 - grass/trunk/temporal/t.vect.observe.strds
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 28 15:43:03 PDT 2012
Author: huhabla
Date: 2012-06-28 15:43:02 -0700 (Thu, 28 Jun 2012)
New Revision: 52252
Modified:
grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.relative.sh
grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh
Log:
More robust implementation and bug fixing
Modified: grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py 2012-06-28 16:09:07 UTC (rev 52251)
+++ grass/trunk/temporal/t.vect.observe.strds/t.vect.observe.strds.py 2012-06-28 22:43:02 UTC (rev 52252)
@@ -27,6 +27,14 @@
#% key: strds
#%end
+#%option G_OPT_STVDS_OUTPUT
+#%end
+
+#%option G_OPT_V_OUTPUT
+#% key: vector_output
+#% description: Name of the new created vector map that stores the sampled values
+#%end
+
#%option
#% key: column
#% type: string
@@ -35,13 +43,6 @@
#% 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
@@ -61,6 +62,7 @@
# Get the options
input = options["input"]
output = options["output"]
+ vector_output = options["vector_output"]
strds = options["strds"]
where = options["where"]
column = options["column"]
@@ -114,35 +116,46 @@
dbif.close()
grass.fatal(_("Space time vector dataset <%s> is empty") % out_sp.get_id())
- # Create the output space time vector dataset
+ num_rows = len(rows)
- out_sp.set_initial_values(strds_sp.get_temporal_type(), \
- strds_sp.get_semantic_type(),\
- _("Observaion of space time raster dataset <%s>")%(strds_id),\
- _("Observation of space time raster dataset <%s> with vector map <%s>")%(strds_id, input))
+ # Get the layer and database connections of the input vector
+ vector_db = grass.vector.vector_db(input)
- out_sp.insert(dbif)
-
- num_rows = len(rows)
-
# We copy the vector table and create the new layers
- layers= ""
+
+ if vector_db:
+ # Use the first layer to copy the categories from
+ layers= "1,"
+ else:
+ layers= ""
first = True
for layer in range(num_rows):
layer += 1
+ # Skip existing layer
+ if vector_db and vector_db.has_key(layer) and vector_db[layer]["layer"] == layer:
+ continue
if first:
layers += "%i"%(layer)
first = False
else:
layers += ",%i"%(layer)
- print layers
-
- vectmap = output
+ # Use the name of the space time vector dataset as new vector name
+ vectmap = vector_output
+
+ # We create a new vector map using the categories of the original map
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))
-
+
+ # Create the output space time vector dataset
+ out_sp.set_initial_values(strds_sp.get_temporal_type(), \
+ strds_sp.get_semantic_type(),\
+ _("Observaion of space time raster dataset <%s>")%(strds_id),\
+ _("Observation of space time raster dataset <%s> with vector map <%s>")%(strds_id, input))
+
+ out_sp.insert(dbif)
+
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
@@ -165,14 +178,18 @@
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:
+ if vector_db and vector_db.has_key(count) and vector_db[count]["table"]:
+ ret = grass.run_command("v.db.addcolumn", map=vectmap, layer=count, 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> with layer %i")%(col_name, vectmap, count))
+ else:
# 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))
+ grass.fatal(_("Unable to add table to vector map <%s> with layer %i")%(vectmap, count))
# Call v.what.rast
ret = grass.run_command("v.what.rast", map=vectmap, layer=count, raster=rastmap, column=col_name, where=where)
Modified: grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.relative.sh
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.relative.sh 2012-06-28 16:09:07 UTC (rev 52251)
+++ grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.relative.sh 2012-06-28 22:43:02 UTC (rev 52252)
@@ -19,10 +19,11 @@
t.register -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start=0 increment=1 unit=months
# The @test
-t.vect.observe.strds input=prec strds=precip_abs1 output=prec_observer
+t.vect.observe.strds input=prec strds=precip_abs1 output=prec_observer vector=prec_observer
v.info prec_observer
t.info type=stvds input=prec_observer
t.vect.list input=prec_observer
+t.vect.db.select input=prec_observer
# @postprocess
t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
Modified: grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh
===================================================================
--- grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh 2012-06-28 16:09:07 UTC (rev 52251)
+++ grass/trunk/temporal/t.vect.observe.strds/test.t.vect.observe.strds.sh 2012-06-28 22:43:02 UTC (rev 52252)
@@ -12,22 +12,32 @@
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
+v.random --o output=prec n=5 seed=1
+v.random --o -z output=test_1 column=test 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
-t.vect.observe.strds input=prec strds=precip_abs1 output=prec_observer
+t.vect.observe.strds input=prec strds=precip_abs1 output=prec_observer vector=prec_observer column="test_val"
v.info prec_observer
t.info type=stvds input=prec_observer
t.vect.list input=prec_observer
+t.vect.db.select input=prec_observer
+t.vect.observe.strds input=test_1 strds=precip_abs1 output=test_1_observer vector=test_1_observer
+v.info test_1_observer
+t.info type=stvds input=test_1_observer
+t.vect.list input=test_1_observer
+t.vect.db.select input=test_1_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.remove type=stvds input=prec_observer,test_1_observer
t.unregister type=vect maps=prec_observer:1,prec_observer:2,prec_observer:3,prec_observer:4,prec_observer:5,prec_observer:6
+t.unregister type=vect maps=test_1_observer:1,test_1_observer:2,test_1_observer:3,test_1_observer:4,test_1_observer:5,test_1_observer:6
-g.remove vect=prec_observer,test_extract
+g.remove vect=prec_observer,test_1_observer
g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
More information about the grass-commit
mailing list