Kaynağa Gözat

Better time-stamped vector layer support implemented.

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50499 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 yıl önce
ebeveyn
işleme
81280a1032

+ 7 - 1
lib/python/temporal/abstract_map_dataset.py

@@ -380,7 +380,13 @@ class abstract_map_dataset(abstract_dataset):
             self.base.delete(dbif)
             self.base.delete(dbif)
 
 
         # Remove the timestamp from the file system
         # 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)
         self.reset(None)
         dbif.connection.commit()
         dbif.connection.commit()

+ 63 - 31
lib/python/temporal/space_time_datasets_tools.py

@@ -40,7 +40,8 @@ def register_maps_in_space_time_dataset(type, name, maps=None, layer=None, file=
        @param type: The type of the maps raster, raster3d or vector
        @param type: The type of the maps raster, raster3d or vector
        @param name: The name of the space time dataset
        @param name: The name of the space time dataset
        @param maps: A comma separated list of map names
        @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 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 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
        @param unit: The unit of the relative time: years, months, days, hours, minutes, seconds
@@ -52,8 +53,6 @@ def register_maps_in_space_time_dataset(type, name, maps=None, layer=None, file=
 
 
     start_time_in_file = False
     start_time_in_file = False
     end_time_in_file = False
     end_time_in_file = False
-    layer_in_file = False
-
     if maps and file:
     if maps and file:
         core.fatal(_("%s= and %s= are mutually exclusive") % ("input","file"))
         core.fatal(_("%s= and %s= are mutually exclusive") % ("input","file"))
 
 
@@ -66,6 +65,8 @@ def register_maps_in_space_time_dataset(type, name, maps=None, layer=None, file=
     if not maps and not file:
     if not maps and not file:
         core.fatal(_("Please specify %s= or %s=") % ("input","file"))
         core.fatal(_("Please specify %s= or %s=") % ("input","file"))
 
 
+    layer_in_file = False
+
     if layer and layer == "file":
     if layer and layer == "file":
         layer_in_file = True
         layer_in_file = True
         
         
@@ -243,6 +244,8 @@ def unregister_maps_from_space_time_datasets(type, name, maps, layer=None, file=
        @param type: The type of the maps raster, vector or raster3d
        @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 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 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
        @param dbif: The database interface to be used
     """
     """
 
 
@@ -363,7 +366,7 @@ def unregister_maps_from_space_time_datasets(type, name, maps, layer=None, file=
 
 
 ###############################################################################
 ###############################################################################
 
 
-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,
     """Use this method to assign valid time (absolute or relative) to raster,
        raster3d and vector datasets.
        raster3d and vector datasets.
 
 
@@ -374,6 +377,7 @@ def assign_valid_time_to_maps(type, maps, ttype, start, end=None, unit=None, fil
 
 
        @param type: The type of the maps raster, raster3d or vector
        @param type: The type of the maps raster, raster3d or vector
        @param maps: A comma separated list of map names
        @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 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 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
        @param unit: The unit of the relative time: years, months, days, hours, minutes, seconds
@@ -407,6 +411,11 @@ def assign_valid_time_to_maps(type, maps, ttype, start, end=None, unit=None, fil
     if not maps and not file:
     if not maps and not file:
         core.fatal(_("Please specify %s= or %s=") % ("input","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":
     if start and start == "file":
         start_time_in_file = True
         start_time_in_file = True
 
 
@@ -424,14 +433,38 @@ def assign_valid_time_to_maps(type, maps, ttype, start, end=None, unit=None, fil
         connect = True
         connect = True
 
 
     maplist = []
     maplist = []
+    layerlist = []
 
 
+    dummy = raster_dataset(None)
+    
     # Map names as comma separated string
     # Map names as comma separated string
     if maps:
     if maps:
-        if maps.find(",") == -1:
-            maplist = (maps,)
+        if maps.find(",") < 0:
+            maplist = [maps,]
         else:
         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
     # Read the map list from file
     if file:
     if file:
         fd = open(file, "r")
         fd = open(file, "r")
@@ -446,43 +479,42 @@ def assign_valid_time_to_maps(type, maps, ttype, start, end=None, unit=None, fil
 
 
             mapname = line_list[0].strip()
             mapname = line_list[0].strip()
 
 
-            if mapname.find("@") < 0:
-                mapid = mapname + "@" + mapset
-            else:
-                mapid = mapname
-
             row = {}
             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)
             maplist.append(row)
     
     
     num_maps = len(maplist)
     num_maps = len(maplist)
-    count = 0
-
-    for entry in maplist:
+    for count in range(len(maplist)):
 	core.percent(count, num_maps, 1)
 	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
         # Use the time data from file
         if start_time_in_file:
         if start_time_in_file:
-            start = entry["start"]
+            start = maplist[count]["start"]
         if end_time_in_file:
         if end_time_in_file:
-            end = entry["end"]
+            end = maplist[count]["end"]
 
 
         if map.is_in_db(dbif) == False:
         if map.is_in_db(dbif) == False:
             # Load the data from the grass file database
             # Load the data from the grass file database

+ 2 - 2
lib/python/temporal/temporal_extent.py

@@ -376,12 +376,12 @@ class absolute_temporal_extent(abstract_temporal_extent):
         #      0123456789012345678901234567890
         #      0123456789012345678901234567890
         print " +-------------------- Absolute time -----------------------------------------+"
         print " +-------------------- Absolute time -----------------------------------------+"
         abstract_temporal_extent.print_info(self)
         abstract_temporal_extent.print_info(self)
-        print " | Timezone:................... " + str(self.get_timezone())
+        #print " | Timezone:................... " + str(self.get_timezone())
 
 
     def print_shell_info(self):
     def print_shell_info(self):
         """Print information about this class in shell style"""
         """Print information about this class in shell style"""
         abstract_temporal_extent.print_shell_info(self)
         abstract_temporal_extent.print_shell_info(self)
-        print "timezone=" + str(self.get_timezone())
+        #print "timezone=" + str(self.get_timezone())
 
 
 ###############################################################################
 ###############################################################################
 
 

+ 18 - 9
temporal/t.time.abs/t.time.abs.py

@@ -32,33 +32,41 @@
 #%end
 #%end
 
 
 #%option
 #%option
-#% key: start
+#% 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
 #% 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: 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
 #% required: no
 #% multiple: no
 #% multiple: no
 #%end
 #%end
 
 
 #%option
 #%option
-#% key: end
+#% key: start
 #% type: string
 #% 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
 #% required: no
 #% multiple: no
 #% multiple: no
 #%end
 #%end
 
 
 #%option
 #%option
-#% key: increment
+#% key: end
 #% type: string
 #% 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
 #% required: no
 #% multiple: no
 #% multiple: no
 #%end
 #%end
 
 
 #%option
 #%option
-#% key: file
+#% key: increment
 #% type: string
 #% 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
 #% required: no
 #% multiple: no
 #% multiple: no
 #%end
 #%end
@@ -94,6 +102,7 @@ def main():
 
 
     # Get the options
     # Get the options
     maps = options["input"]
     maps = options["input"]
+    layer = options["layer"]
     file = options["file"]
     file = options["file"]
     start = options["start"]
     start = options["start"]
     end = options["end"]
     end = options["end"]
@@ -105,7 +114,7 @@ def main():
     # Make sure the temporal database exists
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     tgis.create_temporal_database()
     # Set valid absolute time to maps
     # 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, \
                                    start=start, end=end, file=file, increment=increment, \
                                    dbif=None, interval=interval, fs=fs)
                                    dbif=None, interval=interval, fs=fs)
     
     

+ 73 - 0
temporal/t.time.abs/test.t.time.abs.file.layer.sh

@@ -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

+ 18 - 9
temporal/t.time.rel/t.time.rel.py

@@ -32,6 +32,22 @@
 #%end
 #%end
 
 
 #%option
 #%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
 #% key: start
 #% type: string
 #% 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 
 #% 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
 #%end
 
 
 #%option
 #%option
-#% key: file
-#% type: string
-#% description: Input file with map names, one per line
-#% required: no
-#% multiple: no
-#%end
-
-#%option
 #% key: type
 #% key: type
 #% type: string
 #% type: string
 #% description: Input map type
 #% description: Input map type
@@ -104,6 +112,7 @@ def main():
 
 
     # Get the options
     # Get the options
     maps = options["input"]
     maps = options["input"]
+    layer = options["layer"]
     file = options["file"]
     file = options["file"]
     start = options["start"]
     start = options["start"]
     end = options["end"]
     end = options["end"]
@@ -116,7 +125,7 @@ def main():
     # Make sure the temporal database exists
     # Make sure the temporal database exists
     tgis.create_temporal_database()
     tgis.create_temporal_database()
     # Set valid absolute time to maps
     # 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, \
                                    start=start, end=end, unit=unit, file=file, increment=increment, \
                                    dbif=None, interval=interval, fs=fs)
                                    dbif=None, interval=interval, fs=fs)