[GRASS-SVN] r50465 - in grass/trunk/temporal: tr.register tv.list tv.register tv.unregister tv.what.rast

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 26 07:22:21 EST 2012


Author: huhabla
Date: 2012-01-26 04:22:21 -0800 (Thu, 26 Jan 2012)
New Revision: 50465

Added:
   grass/trunk/temporal/tv.list/test.tv.list.layer.sh
   grass/trunk/temporal/tv.what.rast/test.tv.what.rast.layer.sh
Modified:
   grass/trunk/temporal/tr.register/tr.register.py
   grass/trunk/temporal/tv.list/tv.list.py
   grass/trunk/temporal/tv.register/tv.register.py
   grass/trunk/temporal/tv.unregister/tv.unregister.py
   grass/trunk/temporal/tv.what.rast/tv.what.rast.py
Log:
Implemented handling of time-stamped vector layers


Modified: grass/trunk/temporal/tr.register/tr.register.py
===================================================================
--- grass/trunk/temporal/tr.register/tr.register.py	2012-01-26 10:25:30 UTC (rev 50464)
+++ grass/trunk/temporal/tr.register/tr.register.py	2012-01-26 12:22:21 UTC (rev 50465)
@@ -112,7 +112,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # Register maps
-    tgis.register_maps_in_space_time_dataset(type="strds", name=name, maps=maps, file=file, start=start, end=end, \
+    tgis.register_maps_in_space_time_dataset(type="strds", name=name, maps=maps, layer=None, file=file, start=start, end=end, \
                                              unit=unit, increment=increment, dbif=None, interval=interval, fs=fs)
     
 if __name__ == "__main__":

Added: grass/trunk/temporal/tv.list/test.tv.list.layer.sh
===================================================================
--- grass/trunk/temporal/tv.list/test.tv.list.layer.sh	                        (rev 0)
+++ grass/trunk/temporal/tv.list/test.tv.list.layer.sh	2012-01-26 12:22:21 UTC (rev 50465)
@@ -0,0 +1,121 @@
+# This is a test to list vecter maps of a space time vecter dataset
+
+# 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
+
+v.random --o -z seed=1 output=soil_orig n=20 zmin=0 zmax=100 column=sand
+# Adding new layer with categories
+v.category input=soil_orig out=soils option=transfer layer=1,1 --o
+v.category input=soils out=soil_orig option=transfer layer=1,2 --o
+v.category input=soil_orig out=soils option=transfer layer=1,3 --o
+v.category input=soils out=soil_orig option=transfer layer=1,4 --o
+v.category input=soil_orig out=soils option=transfer layer=1,5 --o
+v.category input=soils out=soil_orig option=transfer layer=1,6 --o
+g.copy --o vect=soil_orig,soils
+# 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` 
+n2=`g.tempfile pid=2 -d`
+n3=`g.tempfile pid=3 -d`
+n4=`g.tempfile pid=4 -d`
+n5=`g.tempfile pid=5 -d`
+
+cat > "${n1}" << EOF
+soils|1
+soils|2
+soils|3
+soils|4
+soils|5
+soils|6
+EOF
+
+cat > "${n2}" << EOF
+soils|1|2001-01-01
+soils|2|2001-02-01
+soils|3|2001-03-01
+soils|4|2001-04-01
+soils|5|2001-05-01
+soils|6|2001-06-01
+EOF
+
+cat > "${n3}" << EOF
+soils|1|2001-01-01|2001-04-01
+soils|2|2001-05-01|2001-07-01
+soils|3|2001-08-01|2001-10-01
+soils|4|2001-11-01|2002-01-01
+soils|5|2002-02-01|2002-04-01
+soils|6|2002-05-01|2002-07-01
+EOF
+
+cat > "${n4}" << EOF
+soils|1|2001-01-01|2001-07-01
+soils|2|2001-02-01|2001-04-01
+soils|3|2001-03-01|2001-04-01
+soils|4|2001-04-01|2001-06-01
+soils|5|2001-05-01|2001-06-01
+soils|6|2001-06-01|2001-07-01
+EOF
+
+cat > "${n5}" << EOF
+soils|1|2001-01-01|2001-03-11
+soils|2|2001-02-01|2001-04-01
+soils|3|2001-03-01|2001-06-02
+soils|4|2001-04-01|2001-04-01
+soils|5|2001-05-01|2001-05-01
+soils|6|2001-06-01|2001-07-01
+EOF
+
+t.create --o type=stvds temporaltype=absolute output=soils_abs1 title="A test with input files" descr="A test with input files"
+t.create --o type=stvds temporaltype=absolute output=soils_abs2 title="A test with input files" descr="A test with input files"
+t.create --o type=stvds temporaltype=absolute output=soils_abs3 title="A test with input files" descr="A test with input files"
+t.create --o type=stvds temporaltype=absolute output=soils_abs4 title="A test with input files" descr="A test with input files"
+t.create --o type=stvds temporaltype=absolute output=soils_abs5 title="A test with input files" descr="A test with input files"
+
+# The first @test
+tv.register    input=soils_abs1 file="${n1}" layer=file start="2001-01-01" increment="1 months"
+tv.list    fs=" | " method=comma     input=soils_abs1
+tv.list -h input=soils_abs1
+tv.list -h fs=" | " method=cols      input=soils_abs1
+tv.list -h fs=" | " method=delta     input=soils_abs1
+tv.list -h fs=" | " method=deltagaps input=soils_abs1
+
+tv.register -i input=soils_abs2 file="${n2}" layer=file start=file
+tv.list    fs=" | " method=comma     input=soils_abs2
+tv.list -h input=soils_abs2
+tv.list -h fs=" | " method=cols      input=soils_abs2
+tv.list -h fs=" | " method=delta     input=soils_abs2
+tv.list -h fs=" | " method=deltagaps input=soils_abs2
+
+tv.register -i input=soils_abs3 file="${n3}" layer=file start=file end=file
+tv.list    fs=" | " method=comma     input=soils_abs3
+tv.list -h fs=" | " method=delta     input=soils_abs3
+tv.list -h fs=" | " method=deltagaps input=soils_abs3
+
+tv.register -i input=soils_abs4 file="${n4}" layer=file start=file end=file
+tv.list    fs=" | " method=comma     input=soils_abs4
+tv.list -h fs=" | " method=delta     input=soils_abs4
+tv.list -h fs=" | " method=deltagaps input=soils_abs4
+
+tv.register -i input=soils_abs5 file="${n5}" layer=file start=file end=file
+tv.list    fs=" | " method=comma     input=soils_abs5
+tv.list -h input=soils_abs5
+tv.list -h fs=" | " method=cols      input=soils_abs5
+tv.list -h fs=" | " method=delta     input=soils_abs5
+tv.list -h fs=" | " method=deltagaps input=soils_abs5
+
+t.remove type=vect input=soils:1,soils:2,soils:3,soils:4,soils:5,soils:6
+t.remove type=stvds input=soils_abs1,soils_abs2,soils_abs3,soils_abs4,soils_abs5
+
+g.remove vect=soil_orig,soils

Modified: grass/trunk/temporal/tv.list/tv.list.py
===================================================================
--- grass/trunk/temporal/tv.list/tv.list.py	2012-01-26 10:25:30 UTC (rev 50464)
+++ grass/trunk/temporal/tv.list/tv.list.py	2012-01-26 12:22:21 UTC (rev 50465)
@@ -36,7 +36,7 @@
 #% description: Order the space time dataset by category. 
 #% required: no
 #% multiple: yes
-#% options: id,name,creator,mapset,temporal_type,creation_time,start_time,end_time,north,south,west,east
+#% options: id,name,layer,creator,mapset,temporal_type,creation_time,start_time,end_time,north,south,west,east
 #% answer: start_time
 #%end
 
@@ -46,8 +46,8 @@
 #% description: Select columns to be printed to stdout 
 #% required: no
 #% multiple: yes
-#% options: id,name,creator,mapset,temporal_type,creation_time,start_time,end_time,north,south,west,east
-#% answer: name,mapset,start_time,end_time
+#% options: id,name,layer,creator,mapset,temporal_type,creation_time,start_time,end_time,north,south,west,east
+#% answer: id,name,layer,mapset,start_time,end_time
 #%end
 
 #%option

Modified: grass/trunk/temporal/tv.register/tv.register.py
===================================================================
--- grass/trunk/temporal/tv.register/tv.register.py	2012-01-26 10:25:30 UTC (rev 50464)
+++ grass/trunk/temporal/tv.register/tv.register.py	2012-01-26 12:22:21 UTC (rev 50465)
@@ -37,9 +37,17 @@
 #%end
 
 #%option
+#% key: layer
+#% type: string
+#% description: Id(s)/Name(s) of existing vector map layer or the identifier "file" in case the layer definition is in the input file
+#% required: no
+#% multiple: yes
+#%end
+
+#%option
 #% key: file
 #% type: string
-#% description: Input file with vector map names, one per line. Additionally the start time and the end time can be specified per line
+#% description: Input file with vector map names, one per line. Additionally the layer, the start time and the end time can be specified per line
 #% required: no
 #% multiple: no
 #%end
@@ -101,6 +109,7 @@
     # Get the options
     name = options["input"]
     maps = options["maps"]
+    layer = options["layer"]
     file = options["file"]
     fs = options["fs"]
     start = options["start"]
@@ -112,7 +121,7 @@
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # Register maps
-    tgis.register_maps_in_space_time_dataset(type="stvds", name=name, maps=maps, file=file, start=start, end=end, \
+    tgis.register_maps_in_space_time_dataset(type="stvds", name=name, maps=maps, layer=layer, file=file, start=start, end=end, \
                                              unit=unit, increment=increment, dbif=None, interval=interval, fs=fs)
     
 if __name__ == "__main__":

Modified: grass/trunk/temporal/tv.unregister/tv.unregister.py
===================================================================
--- grass/trunk/temporal/tv.unregister/tv.unregister.py	2012-01-26 10:25:30 UTC (rev 50464)
+++ grass/trunk/temporal/tv.unregister/tv.unregister.py	2012-01-26 12:22:21 UTC (rev 50465)
@@ -29,6 +29,14 @@
 #%end
 
 #%option
+#% key: layer
+#% type: string
+#% description: Id(s)/Name(s) of existing vector map layer or the identifier "file" in case the layer definition is in the input file
+#% required: no
+#% multiple: yes
+#%end
+
+#%option
 #% key: file
 #% type: string
 #% description: Input file with vector map names, one per line
@@ -55,11 +63,12 @@
     file = options["file"]
     name = options["input"]
     maps = options["maps"]
+    layer = options["layer"]
 
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     # Unregister maps
-    tgis.unregister_maps_from_space_time_datasets(type="vect", name=name, maps=maps, file=file, dbif=None)
+    tgis.unregister_maps_from_space_time_datasets(type="vect", name=name, maps=maps, layer=layer, file=file, dbif=None)
 
 if __name__ == "__main__":
     options, flags = grass.parser()

Added: grass/trunk/temporal/tv.what.rast/test.tv.what.rast.layer.sh
===================================================================
--- grass/trunk/temporal/tv.what.rast/test.tv.what.rast.layer.sh	                        (rev 0)
+++ grass/trunk/temporal/tv.what.rast/test.tv.what.rast.layer.sh	2012-01-26 12:22:21 UTC (rev 50465)
@@ -0,0 +1,86 @@
+# 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=20 zmin=0 zmax=100 column=sand
+# Adding new layer with categories
+v.category input=soil_orig out=soils option=transfer layer=1,1 --o
+v.category input=soils out=soil_orig option=transfer layer=1,2 --o
+v.category input=soil_orig out=soils option=transfer layer=1,3 --o
+v.category input=soils out=soil_orig option=transfer layer=1,4 --o
+v.category input=soil_orig out=soils option=transfer layer=1,5 --o
+v.category input=soils out=soil_orig option=transfer layer=1,6 --o
+g.copy --o vect=soil_orig,soils
+# 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"
+tv.register -i input=soil_abs file="${n1}" layer=file 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"
+tr.register -i 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"
+tr.register -i 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 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
+
+# @postprocess
+t.remove type=vect input=soils:1,soils:2,soils:3,soils:4,soils:5,soils:6
+t.remove type=stvds input=soil_abs
+
+t.remove type=rast input=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

Modified: grass/trunk/temporal/tv.what.rast/tv.what.rast.py
===================================================================
--- grass/trunk/temporal/tv.what.rast/tv.what.rast.py	2012-01-26 10:25:30 UTC (rev 50464)
+++ grass/trunk/temporal/tv.what.rast/tv.what.rast.py	2012-01-26 12:22:21 UTC (rev 50465)
@@ -139,7 +139,8 @@
         dbif.close()
         grass.fatal(_("All registered maps of the space time vector dataset must have time intervals"))
 
-    rows = sp.get_registered_maps("id,name,start_time,end_time", tempwhere, "start_time", dbif)
+    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()
@@ -149,7 +150,8 @@
     for row in rows:
         start = row["start_time"]
         end = row["end_time"]
-        vectmap = row["id"]
+        vectmap = row["name"] + "@" + row["mapset"]
+        layer = row["layer"]
 
         raster_maps = tgis.collect_map_names(strds_sp, dbif, start, end, sampling)
 
@@ -168,14 +170,21 @@
                 rasterinfo = raster.raster_info(rastermap)
                 if rasterinfo["datatype"] == "CELL":
                     coltype = "INT"
-
-                ret = grass.run_command("v.db.addcolumn", map=vectmap, column="%s %s" % (col_name, coltype), overwrite=grass.overwrite())
+		
+		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
-                ret = grass.run_command("v.what.rast", map=vectmap, raster=rastermap, column=col_name, where=where)
+                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))



More information about the grass-commit mailing list