[GRASS-SVN] r56967 - grass/trunk/lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 2 02:33:07 PDT 2013


Author: huhabla
Date: 2013-07-02 02:31:21 -0700 (Tue, 02 Jul 2013)
New Revision: 56967

Modified:
   grass/trunk/lib/python/temporal/spatio_temporal_relationships.py
Log:
Added topology build test


Modified: grass/trunk/lib/python/temporal/spatio_temporal_relationships.py
===================================================================
--- grass/trunk/lib/python/temporal/spatio_temporal_relationships.py	2013-07-02 08:38:02 UTC (rev 56966)
+++ grass/trunk/lib/python/temporal/spatio_temporal_relationships.py	2013-07-02 09:31:21 UTC (rev 56967)
@@ -48,21 +48,78 @@
 
         dbif, connected = init_dbif(None)
 
-        for _map in tb:
-            _map.select(dbif)
-            _map.print_info()
+        for map in tb:
+            map.select(dbif)
+            map.print_info()
+            
+        # Same can be done with the existing map list
+        # But be aware that this is might not be temporally ordered
+        for map in maps:
+            map.select(dbf)
+            map.print_info()
 
         # Using the next and previous methods, we can iterate over the
         # topological related maps in this way
 
-        _first = tb.get_first()
+        first = tb.get_first()
 
-        while _first:
-            _first.print_topology_info()
-            _first = _first.next()
+        while first:
+            first.print_topology_info()
+            first = first.next()
 
         # Dictionary like accessed
-        _map = tb["name at mapset"]
+        map = tb["name at mapset"]
+        
+        >>> # Example with two lists of maps
+        >>> import grass.temporal as tgis
+        >>> # Create two list of maps with equal time stamps
+        >>> mapsA = []
+        >>> mapsB = []
+        >>> for i in range(10):
+        ...     idA = "a%i at B"%(i)
+        ...     mapA = tgis.RasterDataset(idA)
+        ...     idB = "b%i at B"%(i)
+        ...     mapB = tgis.RasterDataset(idB)
+        ...     check = mapA.set_relative_time(i, i + 1, "months")
+        ...     check = mapB.set_relative_time(i, i + 1, "months")
+        ...     mapsA.append(mapA)
+        ...     mapsB.append(mapB)
+        >>> # Build the topology between the two map lists
+        >>> tb = SpatioTemporalTopologyBuilder()
+        >>> tb.build(mapsA, mapsB, None)
+        >>> # Check relations of mapsA
+        >>> for map in mapsA:
+        ...     if map.get_equal():
+        ...         relations = map.get_equal()
+        ...         print "Map %s has equal relation to map %s"%(map.get_name(),
+        ...               relations[0].get_name())
+        Map a0 has equal relation to map b0
+        Map a1 has equal relation to map b1
+        Map a2 has equal relation to map b2
+        Map a3 has equal relation to map b3
+        Map a4 has equal relation to map b4
+        Map a5 has equal relation to map b5
+        Map a6 has equal relation to map b6
+        Map a7 has equal relation to map b7
+        Map a8 has equal relation to map b8
+        Map a9 has equal relation to map b9
+        >>> # Check relations of mapsB
+        >>> for map in mapsB:
+        ...     if map.get_equal():
+        ...         relations = map.get_equal()
+        ...         print "Map %s has equal relation to map %s"%(map.get_name(),
+        ...               relations[0].get_name())
+        Map b0 has equal relation to map a0
+        Map b1 has equal relation to map a1
+        Map b2 has equal relation to map a2
+        Map b3 has equal relation to map a3
+        Map b4 has equal relation to map a4
+        Map b5 has equal relation to map a5
+        Map b6 has equal relation to map a6
+        Map b7 has equal relation to map a7
+        Map b8 has equal relation to map a8
+        Map b9 has equal relation to map a9
+        
         @endcode
 
     """



More information about the grass-commit mailing list