瀏覽代碼

Added follows and precedes to sampling methods

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52181 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 年之前
父節點
當前提交
a9b08a187e

+ 1 - 1
lib/gis/parser_standard_options.c

@@ -773,7 +773,7 @@ struct Option *G_define_standard_option(int opt)
 	Opt->required = NO;
 	Opt->required = NO;
 	Opt->multiple = YES;
 	Opt->multiple = YES;
 	Opt->answer = "start";
 	Opt->answer = "start";
-	Opt->options = "start,during,overlap,contain,equal";
+	Opt->options = "start,during,overlap,contain,equal,follows,precedes";
 	Opt->description = _("The method to be used for sampling the input dataset");
 	Opt->description = _("The method to be used for sampling the input dataset");
 	break;
 	break;
     }
     }

+ 43 - 5
lib/python/temporal/abstract_space_time_dataset.py

@@ -301,7 +301,7 @@ class abstract_space_time_dataset(abstract_dataset):
 
 
            Allowed and not allowed temporal relationships for correct topology
            Allowed and not allowed temporal relationships for correct topology
            after      -> allowed
            after      -> allowed
-           before     -> allowed
+           precedes     -> allowed
            follows    -> allowed
            follows    -> allowed
            precedes   -> allowed
            precedes   -> allowed
 
 
@@ -415,6 +415,14 @@ class abstract_space_time_dataset(abstract_dataset):
                             map    :  s-----------e
                             map    :  s-----------e
                             granule:  s-----------e
                             granule:  s-----------e
 
 
+                          * follows: Select maps which temporally follow the selection granule
+                            map    :              s-----------e
+                            granule:  s-----------e
+                     
+                          * precedes: Select maps which temporally precedes the selection granule
+                            map    :  s-----------e
+                            granule:              s-----------e
+
                           All these methods can be combined. Method must be of type tuple including the identification strings.
                           All these methods can be combined. Method must be of type tuple including the identification strings.
            @param spatial: If set True additional the spatial overlapping is used for selection -> spatio-temporal relation. 
            @param spatial: If set True additional the spatial overlapping is used for selection -> spatio-temporal relation. 
                            The returned map objects will have temporal and spatial extents
                            The returned map objects will have temporal and spatial extents
@@ -428,6 +436,8 @@ class abstract_space_time_dataset(abstract_dataset):
         use_overlap = False
         use_overlap = False
         use_contain = False
         use_contain = False
         use_equal = False
         use_equal = False
+        use_follows = False
+        use_precedes = False
 
 
         # Initialize the methods
         # Initialize the methods
         if method:
         if method:
@@ -442,6 +452,10 @@ class abstract_space_time_dataset(abstract_dataset):
                     use_contain = True
                     use_contain = True
                 if name == "equal":
                 if name == "equal":
                     use_equal = True
                     use_equal = True
+                if name == "follows":
+                    use_follows = True
+                if name == "precedes":
+                    use_precedes = True
         else:
         else:
             use_during = True
             use_during = True
             use_overlap = True
             use_overlap = True
@@ -463,6 +477,8 @@ class abstract_space_time_dataset(abstract_dataset):
             use_overlap = False
             use_overlap = False
             use_contain = False
             use_contain = False
             use_equal = False
             use_equal = False
+            use_follows = False
+            use_precedes = False
 
 
         dbif, connect = init_dbif(dbif)
         dbif, connect = init_dbif(dbif)
 
 
@@ -476,8 +492,8 @@ class abstract_space_time_dataset(abstract_dataset):
             start, end = granule.get_valid_time()
             start, end = granule.get_valid_time()
 
 
             where = create_temporal_relation_sql_where_statement(start, end, use_start, \
             where = create_temporal_relation_sql_where_statement(start, end, use_start, \
-                    use_during, use_overlap, use_contain, use_equal)  
-                    
+                    use_during, use_overlap, use_contain, use_equal, use_follows, use_precedes)  
+
             maps = self.get_registered_maps_as_objects(where, "start_time", dbif)
             maps = self.get_registered_maps_as_objects(where, "start_time", dbif)
 
 
             result = {}
             result = {}
@@ -878,7 +894,7 @@ class abstract_space_time_dataset(abstract_dataset):
         # Create tables
         # Create tables
         sql_path = get_sql_template_path()
         sql_path = get_sql_template_path()
 
 
-        # We need to create the map raster register table before we can register the map
+        # We need to create the map raster register table precedes we can register the map
         if map_register_table == None:
         if map_register_table == None:
             # Create a unique id
             # Create a unique id
             uuid_rand = "map_" + str(uuid.uuid4()).replace("-", "")
             uuid_rand = "map_" + str(uuid.uuid4()).replace("-", "")
@@ -1236,7 +1252,8 @@ class abstract_space_time_dataset(abstract_dataset):
 ###############################################################################
 ###############################################################################
 
 
 def create_temporal_relation_sql_where_statement(start, end, use_start=True, use_during=False, 
 def create_temporal_relation_sql_where_statement(start, end, use_start=True, use_during=False, 
-                                        use_overlap=False, use_contain=False, use_equal=False):
+                                        use_overlap=False, use_contain=False, use_equal=False,
+                                        use_follows=False, use_precedes=False):
     """!Create a SQL WHERE statement for temporal relation selection of maps in space time datasets
     """!Create a SQL WHERE statement for temporal relation selection of maps in space time datasets
 
 
         @param start: The start time
         @param start: The start time
@@ -1269,6 +1286,15 @@ def create_temporal_relation_sql_where_statement(start, end, use_start=True, use
         @param use_equal: Select maps which temporally equal to the selection granule
         @param use_equal: Select maps which temporally equal to the selection granule
                          map    :  s-----------e
                          map    :  s-----------e
                          granule:  s-----------e
                          granule:  s-----------e
+
+        @param use_follows: Select maps which temporally follow the selection granule
+                         map    :              s-----------e
+                         granule:  s-----------e
+ 
+        @param use_precedes: Select maps which temporally precedes the selection granule
+                         map    :  s-----------e
+                         granule:              s-----------e
+
     """
     """
 
 
     where = "("
     where = "("
@@ -1304,6 +1330,18 @@ def create_temporal_relation_sql_where_statement(start, end, use_start=True, use
 
 
         where += "(start_time = '%s' and end_time = '%s')" % (start, end)
         where += "(start_time = '%s' and end_time = '%s')" % (start, end)
 
 
+    if use_follows:
+        if use_start or use_during or use_overlap or use_contain or use_equal:
+            where += " OR "
+
+        where += "(start_time = '%s')" % (end)
+
+    if use_precedes:
+        if use_start or use_during or use_overlap or use_contain or use_equal or use_follows: 
+            where += " OR "
+
+        where += "(end_time = '%s')" % (start)
+
     where += ")"
     where += ")"
     
     
     # Catch empty where statement
     # Catch empty where statement

+ 3 - 2
lib/python/temporal/unit_tests.py

@@ -28,6 +28,7 @@ from datetime_math import *
 from space_time_datasets import *
 from space_time_datasets import *
 
 
 import grass.lib.vector as vector
 import grass.lib.vector as vector
+import grass.lib.gis as gis
 from ctypes import *
 from ctypes import *
 
 
 # Uncomment this to detect the error
 # Uncomment this to detect the error
@@ -1599,7 +1600,7 @@ def test_rtree():
     rect.boundary[4] = 0
     rect.boundary[4] = 0
     rect.boundary[5] = 0
     rect.boundary[5] = 0
 
 
-    _list = vector.ilist()
+    _list = gis.ilist()
 
 
     num = vector.RTreeSearch2(tree, byref(rect), byref(_list))
     num = vector.RTreeSearch2(tree, byref(rect), byref(_list))
 
 
@@ -1622,5 +1623,5 @@ if __name__ == "__main__":
     test_spatial_relations()
     test_spatial_relations()
     test_temporal_topology_builder()
     test_temporal_topology_builder()
     test_map_list_sorting()
     test_map_list_sorting()
-    test_rtree()
+    #test_rtree()
     
     

+ 3 - 0
temporal/t.sample/test.t.sample.sh

@@ -67,6 +67,9 @@ t.sample method=equal   input=precip_abs0,precip_abs0,precip_abs0,precip_abs0 sa
 t.sample method=during  input=precip_abs0,precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -c
 t.sample method=during  input=precip_abs0,precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -c
 t.sample method=overlap input=precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -cs
 t.sample method=overlap input=precip_abs0,precip_abs0 samtype=stvds sample=pnts_abs0 -cs
 t.sample method=contain input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
 t.sample method=contain input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
+t.sample method=precedes input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
+t.sample method=follows input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
+t.sample method=precedes,follows input=precip_abs0 samtype=stvds sample=pnts_abs0 -c
 t.sample input=precip_abs0 samtype=strds sample=precip_abs0 -cs
 t.sample input=precip_abs0 samtype=strds sample=precip_abs0 -cs