[GRASS-SVN] r50499 - in grass/trunk: lib/python/temporal
temporal/t.time.abs temporal/t.time.rel
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 27 10:38:59 EST 2012
Author: huhabla
Date: 2012-01-27 07:38:59 -0800 (Fri, 27 Jan 2012)
New Revision: 50499
Added:
grass/trunk/temporal/t.time.abs/test.t.time.abs.file.layer.sh
Modified:
grass/trunk/lib/python/temporal/abstract_map_dataset.py
grass/trunk/lib/python/temporal/space_time_datasets_tools.py
grass/trunk/lib/python/temporal/temporal_extent.py
grass/trunk/temporal/t.time.abs/t.time.abs.py
grass/trunk/temporal/t.time.rel/t.time.rel.py
Log:
Better time-stamped vector layer support implemented.
Modified: grass/trunk/lib/python/temporal/abstract_map_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_map_dataset.py 2012-01-27 12:27:14 UTC (rev 50498)
+++ grass/trunk/lib/python/temporal/abstract_map_dataset.py 2012-01-27 15:38:59 UTC (rev 50499)
@@ -380,7 +380,13 @@
self.base.delete(dbif)
# Remove the timestamp from the file system
- core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date="none")
+ if self.get_type() == "vect":
+ if self.get_layer():
+ core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), layer=self.get_layer(), date="none")
+ else:
+ core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date="none")
+ else:
+ core.run_command(self.get_timestamp_module_name(), map=self.get_map_id(), date="none")
self.reset(None)
dbif.connection.commit()
Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py 2012-01-27 12:27:14 UTC (rev 50498)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py 2012-01-27 15:38:59 UTC (rev 50499)
@@ -40,7 +40,8 @@
@param type: The type of the maps raster, raster3d or vector
@param name: The name of the space time dataset
@param maps: A comma separated list of map names
- @param file: Input file one map with optional start and end time, one per line
+ @param layer: A comma separated list of layer id's or the file identifier in case the layer is provided in the input file
+ @param file: Input file one map with optional layer, start and end time, one per line
@param start: The start date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative is integer 5)
@param end: The end date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative is integer 5)
@param unit: The unit of the relative time: years, months, days, hours, minutes, seconds
@@ -52,8 +53,6 @@
start_time_in_file = False
end_time_in_file = False
- layer_in_file = False
-
if maps and file:
core.fatal(_("%s= and %s= are mutually exclusive") % ("input","file"))
@@ -66,6 +65,8 @@
if not maps and not file:
core.fatal(_("Please specify %s= or %s=") % ("input","file"))
+ layer_in_file = False
+
if layer and layer == "file":
layer_in_file = True
@@ -243,6 +244,8 @@
@param type: The type of the maps raster, vector or raster3d
@param name: Name of an existing space time raster dataset. If no name is provided the raster map(s) are unregistered from all space time datasets in which they are registered.
@param maps: A comma separated list of map names
+ @param layer: A comma separated list of layer id's or the file identifier in case the layer is provided in the input file
+ @param file: Input file one map with optional layer, start and end time, one per line
@param dbif: The database interface to be used
"""
@@ -363,7 +366,7 @@
###############################################################################
-def assign_valid_time_to_maps(type, maps, ttype, start, end=None, unit=None, file=file, increment=None, dbif = None, interval=False, fs="|"):
+def assign_valid_time_to_maps(type, maps, layer, ttype, start, end=None, unit=None, file=file, increment=None, dbif = None, interval=False, fs="|"):
"""Use this method to assign valid time (absolute or relative) to raster,
raster3d and vector datasets.
@@ -374,6 +377,7 @@
@param type: The type of the maps raster, raster3d or vector
@param maps: A comma separated list of map names
+ @param layer: A comma separated list of layer id's or the file identifier in case the layer is provided in the input file
@param start: The start date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative is integer 5)
@param end: The end date and time of the first raster map (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd", format relative is integer 5)
@param unit: The unit of the relative time: years, months, days, hours, minutes, seconds
@@ -407,6 +411,11 @@
if not maps and not file:
core.fatal(_("Please specify %s= or %s=") % ("input","file"))
+ layer_in_file = False
+
+ if layer and layer == "file":
+ layer_in_file = True
+
if start and start == "file":
start_time_in_file = True
@@ -424,14 +433,38 @@
connect = True
maplist = []
+ layerlist = []
+ dummy = raster_dataset(None)
+
# Map names as comma separated string
if maps:
- if maps.find(",") == -1:
- maplist = (maps,)
+ if maps.find(",") < 0:
+ maplist = [maps,]
else:
- maplist = tuple(maps.split(","))
+ maplist = maps.split(",")
+ # Layer as comma separated string
+ if layer:
+ if layer.find(",") < 0:
+ layerlist = (layer,)
+ else:
+ layerlist = layer.split(",")
+
+ if len(maplist) != len(layerlist):
+ core.fatal(_("Number of %s= and %s= must be equal") % ("maps","layer"))
+
+ # Build the maplist again with the ids
+ for count in range(len(maplist)):
+ row = {}
+ if layer:
+ mapid = dummy.build_id(maplist[count], mapset, layerlist[count])
+ else:
+ mapid = dummy.build_id(maplist[count], mapset, None)
+
+ row["id"] = mapid
+ maplist[count] = row
+
# Read the map list from file
if file:
fd = open(file, "r")
@@ -446,43 +479,42 @@
mapname = line_list[0].strip()
- if mapname.find("@") < 0:
- mapid = mapname + "@" + mapset
- else:
- mapid = mapname
-
row = {}
- row["id"] = mapid
+
+ if layer_in_file:
+ row["layer"] = line_list[1].strip()
+ if start_time_in_file and end_time_in_file:
+ row["start"] = line_list[2].strip()
+ row["end"] = line_list[3].strip()
- if start_time_in_file and end_time_in_file:
- row["start"] = line_list[1].strip()
- row["end"] = line_list[2].strip()
+ if start_time_in_file and not end_time_in_file:
+ row["start"] = line_list[2].strip()
+
+ row["id"] = dummy.build_id(mapname, mapset, row["layer"])
+ else:
+ if start_time_in_file and end_time_in_file:
+ row["start"] = line_list[1].strip()
+ row["end"] = line_list[2].strip()
- if start_time_in_file and not end_time_in_file:
- row["start"] = line_list[1].strip()
+ if start_time_in_file and not end_time_in_file:
+ row["start"] = line_list[1].strip()
+
+ row["id"] = dummy.build_id(mapname, mapset)
maplist.append(row)
num_maps = len(maplist)
- count = 0
-
- for entry in maplist:
+ for count in range(len(maplist)):
core.percent(count, num_maps, 1)
- if file:
- mapid = entry["id"]
- else:
- if entry.find("@") < 0:
- mapid = entry + "@" + mapset
- else:
- mapid = entry
- map = dataset_factory(type, mapid)
+ # Get a new instance of the space time dataset map type
+ map = map = dataset_factory(type, maplist[count]["id"])
# Use the time data from file
if start_time_in_file:
- start = entry["start"]
+ start = maplist[count]["start"]
if end_time_in_file:
- end = entry["end"]
+ end = maplist[count]["end"]
if map.is_in_db(dbif) == False:
# Load the data from the grass file database
Modified: grass/trunk/lib/python/temporal/temporal_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_extent.py 2012-01-27 12:27:14 UTC (rev 50498)
+++ grass/trunk/lib/python/temporal/temporal_extent.py 2012-01-27 15:38:59 UTC (rev 50499)
@@ -376,12 +376,12 @@
# 0123456789012345678901234567890
print " +-------------------- Absolute time -----------------------------------------+"
abstract_temporal_extent.print_info(self)
- print " | Timezone:................... " + str(self.get_timezone())
+ #print " | Timezone:................... " + str(self.get_timezone())
def print_shell_info(self):
"""Print information about this class in shell style"""
abstract_temporal_extent.print_shell_info(self)
- print "timezone=" + str(self.get_timezone())
+ #print "timezone=" + str(self.get_timezone())
###############################################################################
Modified: grass/trunk/temporal/t.time.abs/t.time.abs.py
===================================================================
--- grass/trunk/temporal/t.time.abs/t.time.abs.py 2012-01-27 12:27:14 UTC (rev 50498)
+++ grass/trunk/temporal/t.time.abs/t.time.abs.py 2012-01-27 15:38:59 UTC (rev 50499)
@@ -32,33 +32,41 @@
#%end
#%option
-#% key: start
+#% key: layer
#% type: string
-#% description: The valid start date and time of the first raster map. Time format is "yyyy-mm-dd HH:MM:SS" or only "yyyy-mm-dd", or file in case the start time is located in the input file
+#% 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 layer, the start time and the end time can be specified per line
+#% required: no
#% multiple: no
#%end
#%option
-#% key: end
+#% key: start
#% type: string
-#% description: The valid end date and time of the first raster map. Time format is "yyyy-mm-dd HH:MM:SS" or only "yyyy-mm-dd", or file in case the start time is located in the input file
+#% description: The valid start date and time of the first raster map. Time format is "yyyy-mm-dd HH:MM:SS" or only "yyyy-mm-dd", or "file" in case the start time is located in the input file
#% required: no
#% multiple: no
#%end
#%option
-#% key: increment
+#% key: end
#% type: string
-#% description: Time increment between maps for valid time interval creation. Interval format: NNN seconds, minutes, hours, days, weeks, months, years
+#% description: The valid end date and time of the first raster map. Time format is "yyyy-mm-dd HH:MM:SS" or only "yyyy-mm-dd", or "file" in case the start time is located in the input file
#% required: no
#% multiple: no
#%end
#%option
-#% key: file
+#% key: increment
#% type: string
-#% description: Input file with map names, one per line
+#% description: Time increment between maps for valid time interval creation. Interval format: NNN seconds, minutes, hours, days, weeks, months, years
#% required: no
#% multiple: no
#%end
@@ -94,6 +102,7 @@
# Get the options
maps = options["input"]
+ layer = options["layer"]
file = options["file"]
start = options["start"]
end = options["end"]
@@ -105,7 +114,7 @@
# Make sure the temporal database exists
tgis.create_temporal_database()
# Set valid absolute time to maps
- tgis.assign_valid_time_to_maps(type=type, maps=maps, ttype="absolute", \
+ tgis.assign_valid_time_to_maps(type=type, maps=maps, layer=layer, ttype="absolute", \
start=start, end=end, file=file, increment=increment, \
dbif=None, interval=interval, fs=fs)
Added: grass/trunk/temporal/t.time.abs/test.t.time.abs.file.layer.sh
===================================================================
--- grass/trunk/temporal/t.time.abs/test.t.time.abs.file.layer.sh (rev 0)
+++ grass/trunk/temporal/t.time.abs/test.t.time.abs.file.layer.sh 2012-01-27 15:38:59 UTC (rev 50499)
@@ -0,0 +1,73 @@
+# This is a test to absolute time for vector maps with layer support
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# vector with v.random and create several space time vector inputs
+# with absolute time
+# 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 output=lidar_abs_1 n=5 zmin=0 zmax=100
+
+n1=`g.tempfile pid=4 -d` # Only map names and layer
+n2=`g.tempfile pid=5 -d` # Map names, layer and start time
+n3=`g.tempfile pid=6 -d` # Map names, layer start time and increment
+v.random --o -z seed=1 output=lidar_abs_orig n=20 zmin=0 zmax=100 column=sand
+# Adding new layer with categories
+v.category input=lidar_abs_orig out=lidar_abs option=transfer layer=1,1 --o
+v.category input=lidar_abs out=lidar_abs_orig option=transfer layer=1,2 --o
+v.category input=lidar_abs_orig out=lidar_abs option=transfer layer=1,3 --o
+v.category input=lidar_abs out=lidar_abs_orig option=transfer layer=1,4 --o
+v.category input=lidar_abs_orig out=lidar_abs option=transfer layer=1,5 --o
+v.category input=lidar_abs out=lidar_abs_orig option=transfer layer=1,6 --o
+g.copy --o vect=lidar_abs_orig,lidar_abs_1
+
+cat > "${n1}" << EOF
+lidar_abs_1|1
+lidar_abs_1|2
+lidar_abs_1|3
+lidar_abs_1|4
+lidar_abs_1|5
+lidar_abs_1|6
+EOF
+cat "${n1}"
+
+cat > "${n2}" << EOF
+lidar_abs_1|1|2001-01-01
+lidar_abs_1|2|2001-02-01
+lidar_abs_1|3|2001-03-01
+lidar_abs_1|4|2001-04-01
+lidar_abs_1|5|2001-05-01
+lidar_abs_1|6|2001-06-01
+EOF
+cat "${n2}"
+
+cat > "${n3}" << EOF
+lidar_abs_1|1|2001-01-01|2001-04-01
+lidar_abs_1|2|2001-04-01|2001-07-01
+lidar_abs_1|3|2001-07-01|2001-10-01
+lidar_abs_1|4|2001-10-01|2002-01-01
+lidar_abs_1|5|2002-01-01|2002-04-01
+lidar_abs_1|6|2002-04-01|2002-07-01
+EOF
+cat "${n3}"
+
+# The first @test
+# Test with input files
+# File 1
+t.time.abs --v type=vect file="${n1}" start="2001-01-01" increment="1 months" layer=file
+t.list type=vect columns=id,name,start_time,end_time where='name = "lidar_abs_1"'
+# File 1
+t.time.abs --v type=vect file="${n1}" start="2001-01-01" layer=file
+t.list type=vect columns=id,name,start_time,end_time where='name = "lidar_abs_1"'
+# File 2
+t.time.abs --v type=vect file="${n2}" start=file layer=file
+t.list type=vect columns=id,name,start_time,end_time where='name = "lidar_abs_1"'
+# File 2
+t.time.abs --v type=vect -i file="${n2}" start=file increment="1 months" layer=file
+t.list type=vect columns=id,name,start_time,end_time where='name = "lidar_abs_1"'
+# File 3
+t.time.abs --v type=vect file="${n3}" start=file end=file layer=file
+t.list type=vect columns=id,name,start_time,end_time where='name = "lidar_abs_1"'
+
+t.remove --v type=vect input=lidar_abs_1:1,lidar_abs_1:2,lidar_abs_1:3,lidar_abs_1:4,lidar_abs_1:5,lidar_abs_1:6
+g.remove vect=lidar_abs_1,lidar_abs_orig
Modified: grass/trunk/temporal/t.time.rel/t.time.rel.py
===================================================================
--- grass/trunk/temporal/t.time.rel/t.time.rel.py 2012-01-27 12:27:14 UTC (rev 50498)
+++ grass/trunk/temporal/t.time.rel/t.time.rel.py 2012-01-27 15:38:59 UTC (rev 50499)
@@ -32,6 +32,22 @@
#%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 layer, the start time and the end time can be specified per line
+#% required: no
+#% multiple: no
+#%end
+
+#%option
#% key: start
#% type: string
#% description: The valid integer start value for all maps, or the identifier "file" in case the start time is located in the input file
@@ -66,14 +82,6 @@
#%end
#%option
-#% key: file
-#% type: string
-#% description: Input file with map names, one per line
-#% required: no
-#% multiple: no
-#%end
-
-#%option
#% key: type
#% type: string
#% description: Input map type
@@ -104,6 +112,7 @@
# Get the options
maps = options["input"]
+ layer = options["layer"]
file = options["file"]
start = options["start"]
end = options["end"]
@@ -116,7 +125,7 @@
# Make sure the temporal database exists
tgis.create_temporal_database()
# Set valid absolute time to maps
- tgis.assign_valid_time_to_maps(type=type, maps=maps, ttype="relative", \
+ tgis.assign_valid_time_to_maps(type=type, maps=maps, layer=layer, ttype="relative", \
start=start, end=end, unit=unit, file=file, increment=increment, \
dbif=None, interval=interval, fs=fs)
More information about the grass-commit
mailing list