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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 6 14:34:02 PDT 2015


Author: huhabla
Date: 2015-09-06 14:34:02 -0700 (Sun, 06 Sep 2015)
New Revision: 66135

Modified:
   grass/trunk/lib/python/temporal/c_libraries_interface.py
Log:
temporal framework: add time stamp support in read_*_full_info() functions 


Modified: grass/trunk/lib/python/temporal/c_libraries_interface.py
===================================================================
--- grass/trunk/lib/python/temporal/c_libraries_interface.py	2015-09-06 19:25:04 UTC (rev 66134)
+++ grass/trunk/lib/python/temporal/c_libraries_interface.py	2015-09-06 21:34:02 UTC (rev 66135)
@@ -57,6 +57,7 @@
 
 ###############################################################################
 
+
 def _read_map_full_info(lock, conn, data):
     """Read full map specific metadata from the spatial database using 
        PyGRASS functions.
@@ -79,6 +80,9 @@
     finally:
         conn.send(info)
 
+###############################################################################
+
+
 def _read_raster_full_info(name, mapset):
     """Read raster info, history and cats using PyGRASS RasterRow
        and return a dictionary. Colors should be supported in the 
@@ -103,9 +107,22 @@
             info["cats"] = list(r.cats)
         r.close()
 
+        ts = libgis.TimeStamp()
+        check = libgis.G_read_raster_timestamp(name, mapset, byref(ts))
+
+        if check:
+            dates = _convert_timestamp_from_grass(ts)
+            info["start_time"] = dates[0]
+            info["end_time"] = dates[1]
+            if len(dates) > 2:
+                info["time_unit"] = dates[2]
+
     return(info)
 
-def _read_vector_full_info(name, mapset):
+###############################################################################
+
+
+def _read_vector_full_info(name, mapset, layer = None):
     """Read vector info using PyGRASS VectorTopo
        and return a dictionary. C
     """
@@ -144,13 +161,25 @@
         if v.table is not None:
             info["columns"] = v.table.columns
 
+        ts = libgis.TimeStamp()
+        check = libgis.G_read_vector_timestamp(name, layer, mapset, byref(ts))
+
+        if check:
+            dates = _convert_timestamp_from_grass(ts)
+            info["start_time"] = dates[0]
+            info["end_time"] = dates[1]
+            if len(dates) > 2:
+                info["time_unit"] = dates[2]
+
     return(info)
 
 def _fatal_error(lock, conn, data):
     """Calls G_fatal_error()"""
     libgis.G_fatal_error("Fatal Error in C library server")
 
+###############################################################################
 
+
 def _get_mapset(lock, conn, data):
     """Return the current mapset
 
@@ -163,7 +192,9 @@
     mapset = libgis.G_mapset()
     conn.send(mapset)
 
+###############################################################################
 
+
 def _get_location(lock, conn, data):
     """Return the current location
 
@@ -176,7 +207,9 @@
     location = libgis.G_location()
     conn.send(location)
 
+###############################################################################
 
+
 def _get_gisdbase(lock, conn, data):
     """Return the current gisdatabase
 
@@ -189,7 +222,9 @@
     gisdbase = libgis.G_gisdbase()
     conn.send(gisdbase)
 
+###############################################################################
 
+
 def _get_driver_name(lock, conn, data):
     """Return the temporal database driver of a specific mapset
 
@@ -280,7 +315,9 @@
     finally:
         conn.send(mapset_list)
 
+###############################################################################
 
+
 def _has_timestamp(lock, conn, data):
     """Check if the file based GRASS timestamp is present and send
        True or False using the provided pipe.
@@ -963,9 +1000,15 @@
            >>> ciface.read_raster_info("test", tgis.get_current_mapset())
            {'rows': 12, 'north': 80.0, 'min': 1, 'datatype': 'CELL', 'max': 1, 'ewres': 10.0, 'cols': 8, 'west': 0.0, 'east': 120.0, 'nsres': 10.0, 'south': 0.0}
            
-           >>> ciface.read_raster_full_info("test", tgis.get_current_mapset()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
-           {u'tbres': 1.0, ... 'title': 'test', u'south': 0.0}
+           >>> info = ciface.read_raster_full_info("test", tgis.get_current_mapset()) 
+           >>> info           # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+           {u'tbres': 1.0, ... 'keyword': 'generated by r.mapcalc', 
+            u'bottom': 0.0, 'end_time': None, 'title': 'test', u'south': 0.0}
 
+           >>> info["start_time"]
+           datetime.datetime(1995, 3, 12, 10, 34, 40)
+           >>> info["end_time"]
+           
            >>> check = ciface.has_raster_timestamp("test", tgis.get_current_mapset())
            >>> print check
            True
@@ -1029,6 +1072,9 @@
            0
            >>> 'columns' in kvp
            False
+           >>> kvp["start_time"]
+           datetime.datetime(1995, 3, 12, 10, 34, 40)
+           >>> kvp["end_time"]
            
            >>> check = ciface.has_vector_timestamp("test", tgis.get_current_mapset(), None)
            >>> print check



More information about the grass-commit mailing list