pythontemporallib.dox 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*! \page pythontemporallib GRASS GIS Temporal Framework
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. The GRASS GIS Temporal Framework
  4. \section PythonTGISIntro Introduction
  5. The GRASS GIS Temporal Framework implements the temporal GIS functionality of GRASS GIS
  6. and provides an API to implement spatio-temporal processing modules. The framework
  7. introduces space time datasets that represent time series of raster, 3D raster or vector maps.
  8. This framework provides the following functionalities:
  9. - Assign time stamp to maps and register maps in the temporal database
  10. - Modification of time stamps
  11. - Creation, renaming and deletion of space time datasets
  12. - Registration and un-registration of maps in space time datasets
  13. - Query of maps that are registered in space time datasets using SQL where statements
  14. - Analysis of the spatio-temporal topology of space time datasets
  15. - Sampling of space time datasets
  16. - Computation of temporal and spatial relationships between registered maps
  17. - Higher level functions that are shared between modules
  18. Most of the functions described above are member functions of the maps and space time dataset classes.
  19. Maps and space time datasets are represented as objects in the temporal framework.
  20. \section PythonTGISPackages Library
  21. Core functionality such as the database interface connection to sqlite3
  22. and postgresql as well as the creation of the temporal database are defined here:
  23. - python::temporal::core
  24. In these modules are the temporal database interfaces for raster maps,
  25. 3D raster maps, vector maps and space time datasets defined.
  26. In addition the temporal and spatial extent modules implement the topological
  27. relationship computation that is needed for spatio-temporal topology computation:
  28. - python::temporal::base
  29. - python::temporal::spatial_extent
  30. - python::temporal::temporal_extent
  31. - python::temporal::metadata
  32. Several "abstract" classes are defined that implement the shared functionality
  33. of time stamped maps and space time datasets, such as temporal and spatial
  34. handling and representation:
  35. - python::temporal::spatial_topology_dataset_connector
  36. - python::temporal::temporal_topology_dataset_connector
  37. - python::temporal::abstract_dataset
  38. - python::temporal::abstract_map_dataset
  39. - python::temporal::abstract_space_time_dataset
  40. All dataset classes that are used in the GRASS temporal modules are specified
  41. here:
  42. - python::temporal::space_time_datasets
  43. Functions to compute temporal granularity, handling of datetime objects
  44. and their conversion as well as spatio-temporal topology computation are defined in these modules:
  45. - python::temporal::datetime_math
  46. - python::temporal::spatio_temporal_relationships
  47. - python::temporal::temporal_granularity
  48. Functionality that is shared between different temporal GRASS modules, such as
  49. map listing, space time dataset creation, map registration and unregistration,
  50. aggregation, extraction, map calculation, statistics as well as import and export of
  51. space time datasets are defined here:
  52. - python::temporal::aggregation
  53. - python::temporal::create
  54. - python::temporal::extract
  55. - python::temporal::factory
  56. - python::temporal::list
  57. - python::temporal::mapcalc
  58. - python::temporal::register
  59. - python::temporal::sampling
  60. - python::temporal::stds_export
  61. - python::temporal::stds_import
  62. - python::temporal::univar_statistics
  63. Two helper functions to support the listing of space time datasets in the automatically generated GUI:
  64. - python::temporal::gui_support
  65. Lots of unit tests:
  66. - python::temporal::unit_tests
  67. \section PythonTGISExamples Examples
  68. \subsection PythonTGISExamplesSimple Simple example
  69. This simple example shows how to open a space time raster dataset
  70. to access its registered maps.
  71. \code
  72. # Lets import the temporal framework and
  73. # the script framework
  74. import grass.temporal as tgis
  75. import grass.script as grass
  76. # Make sure the temporal database exists
  77. # and set the temporal GIS environment
  78. tgis.init()
  79. # We create the temporal database interface for fast processing
  80. dbif = tgis.SQLDatabaseInterfaceConnection()
  81. dbif.connect()
  82. # The id of a space time raster dataset is build from its name and its mapset
  83. id = "test@PERMANENT"
  84. # We create a space time raster dataset object
  85. strds = tgis.SpaceTimeRasterDataset(id)
  86. # Check if the space time raster dataset is in the temporal database
  87. if strds.is_in_db(dbif=dbif) == False:
  88. dbif.close()
  89. grass.fatal(_("Space time %s dataset <%s> not found") % (
  90. strds.get_new_map_instance(None).get_type(), id))
  91. # Fill the object with the content from the temporal database
  92. strds.select(dbif=dbif)
  93. # Print informations about the space time raster dataset to stdout
  94. strds.print_info()
  95. # Get all maps that are registered in the strds and print
  96. # informations about the maps to stdout
  97. maps = strds.get_registered_maps_as_objects(dbif=dbif)
  98. # We iterate over the temporal sorted map list
  99. for map in maps:
  100. # We fill the map object with the content
  101. # from the temporal database. We use the existing
  102. # database connection, otherwise a new connection
  103. # will be established for each map object
  104. # which slows the processing down
  105. map.select(dbif=dbif)
  106. map.print_info()
  107. # Close the database connection
  108. dbif.close()
  109. \endcode
  110. \subsection PythonTGISExamplesSTDSCreation Creation of a space time dataset
  111. This example shows howto create a space time dataset. The code is generic and works
  112. for different space time datasets (raster, 3D raster and vector):
  113. \code
  114. # Lets import the temporal framework and
  115. # the script framework
  116. import grass.temporal as tgis
  117. import grass.script as grass
  118. # The id of the new space time dataset
  119. id="test@PERMANENT"
  120. # The title of the new space time dataset
  121. title="This is a test dataset"
  122. # The description of the space time dataset
  123. description="The description"
  124. # The type of the space time dataset (strds, str3ds or stvds)
  125. type="strds"
  126. # The temporal type of the space time dataset (absolute or relative)
  127. temporal_type="absolute"
  128. # Make sure the temporal database exists
  129. # and set the temporal GIS environment
  130. tgis.init()
  131. # We use the dataset factory to create an new space time dataset instance of a specific type
  132. stds = tgis.dataset_factory(type, id)
  133. # We need a dtabase connection to insert the content of the space time dataset
  134. dbif = tgis.SQLDatabaseInterfaceConnection()
  135. dbif.connect()
  136. # First we check if the dataset is already in the database
  137. if stds.is_in_db(dbif=dbif) and overwrite == False:
  138. dbif.close()
  139. grass.fatal(_("Space time %s dataset <%s> is already in the database. "
  140. "Use the overwrite flag.") %
  141. (stds.get_new_map_instance(None).get_type(), name))
  142. # We delete the exiting dataset and create a new one in case we are allowed to overwrite it
  143. if stds.is_in_db(dbif=dbif) and overwrite == True:
  144. grass.warning(_("Overwrite space time %s dataset <%s> "
  145. "and unregister all maps.") %
  146. (stds.get_new_map_instance(None).get_type(), name))
  147. stds.delete(dbif=dbif)
  148. stds = stds.get_new_instance(id)
  149. # We set the initial values. This function also created the command history.
  150. stds.set_initial_values(temporal_type=temporaltype, semantic_type="mean",
  151. title=title, description=description)
  152. # Now we can insert the new space time dataset in the database
  153. stds.insert(dbif=dbif)
  154. # Close the database connection
  155. dbif.close()
  156. \endcode
  157. \subsection PythonTGISExamplesShifting Temporal shifting
  158. \code
  159. import grass.script as grass
  160. import grass.temporal as tgis
  161. id="test@PERMANENT"
  162. type="strds"
  163. # Make sure the temporal database exists
  164. tgis.init()
  165. dbif = tgis.SQLDatabaseInterfaceConnection()
  166. dbif.connect()
  167. stds = tgis.dataset_factory(type, id)
  168. if stds.is_in_db(dbif) == False:
  169. dbif.close()
  170. grass.fatal(_("Space time dataset <%s> not found in temporal database") % (id))
  171. stds.select(dbif=dbif)
  172. stds.snap(dbif=dbif)
  173. stds.update_command_string(dbif=dbif)
  174. dbif.close()
  175. \endcode
  176. \section PythonTGISAuthors Authors
  177. Soeren Gebbert
  178. TODO: add more documentation
  179. */