[GRASS-SVN] r52181 - in grass/trunk: lib/gis lib/python/temporal temporal/t.sample

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 21 06:47:31 PDT 2012


Author: huhabla
Date: 2012-06-21 06:47:30 -0700 (Thu, 21 Jun 2012)
New Revision: 52181

Modified:
   grass/trunk/lib/gis/parser_standard_options.c
   grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
   grass/trunk/lib/python/temporal/unit_tests.py
   grass/trunk/temporal/t.sample/test.t.sample.sh
Log:
Added follows and precedes to sampling methods


Modified: grass/trunk/lib/gis/parser_standard_options.c
===================================================================
--- grass/trunk/lib/gis/parser_standard_options.c	2012-06-21 10:00:25 UTC (rev 52180)
+++ grass/trunk/lib/gis/parser_standard_options.c	2012-06-21 13:47:30 UTC (rev 52181)
@@ -773,7 +773,7 @@
 	Opt->required = NO;
 	Opt->multiple = YES;
 	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");
 	break;
     }

Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2012-06-21 10:00:25 UTC (rev 52180)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2012-06-21 13:47:30 UTC (rev 52181)
@@ -301,7 +301,7 @@
 
            Allowed and not allowed temporal relationships for correct topology
            after      -> allowed
-           before     -> allowed
+           precedes     -> allowed
            follows    -> allowed
            precedes   -> allowed
 
@@ -415,6 +415,14 @@
                             map    :  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.
            @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
@@ -428,6 +436,8 @@
         use_overlap = False
         use_contain = False
         use_equal = False
+        use_follows = False
+        use_precedes = False
 
         # Initialize the methods
         if method:
@@ -442,6 +452,10 @@
                     use_contain = True
                 if name == "equal":
                     use_equal = True
+                if name == "follows":
+                    use_follows = True
+                if name == "precedes":
+                    use_precedes = True
         else:
             use_during = True
             use_overlap = True
@@ -463,6 +477,8 @@
             use_overlap = False
             use_contain = False
             use_equal = False
+            use_follows = False
+            use_precedes = False
 
         dbif, connect = init_dbif(dbif)
 
@@ -476,8 +492,8 @@
             start, end = granule.get_valid_time()
 
             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)
 
             result = {}
@@ -878,7 +894,7 @@
         # Create tables
         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:
             # Create a unique id
             uuid_rand = "map_" + str(uuid.uuid4()).replace("-", "")
@@ -1236,7 +1252,8 @@
 ###############################################################################
 
 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
 
         @param start: The start time
@@ -1269,6 +1286,15 @@
         @param use_equal: Select maps which temporally equal to the selection granule
                          map    :  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 = "("
@@ -1304,6 +1330,18 @@
 
         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 += ")"
     
     # Catch empty where statement

Modified: grass/trunk/lib/python/temporal/unit_tests.py
===================================================================
--- grass/trunk/lib/python/temporal/unit_tests.py	2012-06-21 10:00:25 UTC (rev 52180)
+++ grass/trunk/lib/python/temporal/unit_tests.py	2012-06-21 13:47:30 UTC (rev 52181)
@@ -28,6 +28,7 @@
 from space_time_datasets import *
 
 import grass.lib.vector as vector
+import grass.lib.gis as gis
 from ctypes import *
 
 # Uncomment this to detect the error
@@ -1599,7 +1600,7 @@
     rect.boundary[4] = 0
     rect.boundary[5] = 0
 
-    _list = vector.ilist()
+    _list = gis.ilist()
 
     num = vector.RTreeSearch2(tree, byref(rect), byref(_list))
 
@@ -1622,5 +1623,5 @@
     test_spatial_relations()
     test_temporal_topology_builder()
     test_map_list_sorting()
-    test_rtree()
+    #test_rtree()
     

Modified: grass/trunk/temporal/t.sample/test.t.sample.sh
===================================================================
--- grass/trunk/temporal/t.sample/test.t.sample.sh	2012-06-21 10:00:25 UTC (rev 52180)
+++ grass/trunk/temporal/t.sample/test.t.sample.sh	2012-06-21 13:47:30 UTC (rev 52181)
@@ -67,6 +67,9 @@
 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=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
 
 



More information about the grass-commit mailing list