pythontemporallib.dox 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 initialization function, 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. The RPC C-library interface for exit safe and fast access to raster, vector and 3D raster informations:
  41. - python::temporal::c_libraries_interface
  42. All dataset classes that are used in the GRASS temporal modules are specified
  43. here:
  44. - python::temporal::space_time_datasets
  45. Functions to compute temporal granularity, handling of datetime objects
  46. and their conversion as well as spatio-temporal topology computation are defined in these modules:
  47. - python::temporal::datetime_math
  48. - python::temporal::spatio_temporal_relationships
  49. - python::temporal::temporal_granularity
  50. Functionality that is shared between different temporal GRASS modules, such as
  51. map listing, space time dataset creation, map registration and unregistration,
  52. aggregation, extraction, map calculation, statistics as well as import and export of
  53. space time datasets are defined here:
  54. - python::temporal::aggregation
  55. - python::temporal::extract
  56. - python::temporal::factory
  57. - python::temporal::open_stds
  58. - python::temporal::list_stds
  59. - python::temporal::mapcalc
  60. - python::temporal::register
  61. - python::temporal::sampling
  62. - python::temporal::stds_export
  63. - python::temporal::stds_import
  64. - python::temporal::univar_statistics
  65. Spatio-temporal algebra classes for space time raster and vector datasets are defined in:
  66. - python::temporal::temporal_algebra
  67. - python::temporal::temporal_vector_algebra
  68. - python::temporal::temporal_vector_operator
  69. Two helper functions to support the listing of space time datasets in the automatically generated GUI:
  70. - python::temporal::gui_support
  71. Unittests:
  72. - python::temporal::unittests_register
  73. \section PythonTGISExamples Examples
  74. \subsection PythonTGISExamplesSimple Simple example
  75. This simple example shows how to open a space time raster dataset
  76. to access its registered maps.
  77. \code
  78. # Lets import the temporal framework and
  79. # the script framework
  80. import grass.temporal as tgis
  81. import grass.script as grass
  82. # Make sure the temporal database exists
  83. # and set the temporal GIS environment
  84. tgis.init()
  85. # We create the temporal database interface for fast processing
  86. dbif = tgis.SQLDatabaseInterfaceConnection()
  87. dbif.connect()
  88. # The id of a space time raster dataset is build from its name and its mapset
  89. id = "test@PERMANENT"
  90. # We create a space time raster dataset object
  91. strds = tgis.SpaceTimeRasterDataset(id)
  92. # Check if the space time raster dataset is in the temporal database
  93. if strds.is_in_db(dbif=dbif) == False:
  94. dbif.close()
  95. grass.fatal(_("Space time %s dataset <%s> not found") % (
  96. strds.get_new_map_instance(None).get_type(), id))
  97. # Fill the object with the content from the temporal database
  98. strds.select(dbif=dbif)
  99. # Print informations about the space time raster dataset to stdout
  100. strds.print_info()
  101. # Get all maps that are registered in the strds and print
  102. # informations about the maps to stdout
  103. maps = strds.get_registered_maps_as_objects(dbif=dbif)
  104. # We iterate over the temporal sorted map list
  105. for map in maps:
  106. # We fill the map object with the content
  107. # from the temporal database. We use the existing
  108. # database connection, otherwise a new connection
  109. # will be established for each map object
  110. # which slows the processing down
  111. map.select(dbif=dbif)
  112. map.print_info()
  113. # Close the database connection
  114. dbif.close()
  115. \endcode
  116. \subsection PythonTGISExamplesSTDSCreation Creation of a space time dataset
  117. This example shows howto create a space time dataset. The code is generic and works
  118. for different space time datasets (raster, 3D raster and vector):
  119. \code
  120. # Lets import the temporal framework and
  121. # the script framework
  122. import grass.temporal as tgis
  123. import grass.script as grass
  124. # The id of the new space time dataset
  125. id="test@PERMANENT"
  126. # The title of the new space time dataset
  127. title="This is a test dataset"
  128. # The description of the space time dataset
  129. description="The description"
  130. # The type of the space time dataset (strds, str3ds or stvds)
  131. type="strds"
  132. # The temporal type of the space time dataset (absolute or relative)
  133. temporal_type="absolute"
  134. # Make sure the temporal database exists
  135. # and set the temporal GIS environment
  136. tgis.init()
  137. # We use the dataset factory to create an new space time dataset instance of a specific type
  138. stds = tgis.dataset_factory(type, id)
  139. # We need a dtabase connection to insert the content of the space time dataset
  140. dbif = tgis.SQLDatabaseInterfaceConnection()
  141. dbif.connect()
  142. # First we check if the dataset is already in the database
  143. if stds.is_in_db(dbif=dbif) and overwrite == False:
  144. dbif.close()
  145. grass.fatal(_("Space time %s dataset <%s> is already in the database. "
  146. "Use the overwrite flag.") %
  147. (stds.get_new_map_instance(None).get_type(), name))
  148. # We delete the exiting dataset and create a new one in case we are allowed to overwrite it
  149. if stds.is_in_db(dbif=dbif) and overwrite == True:
  150. grass.warning(_("Overwrite space time %s dataset <%s> "
  151. "and unregister all maps.") %
  152. (stds.get_new_map_instance(None).get_type(), name))
  153. stds.delete(dbif=dbif)
  154. stds = stds.get_new_instance(id)
  155. # We set the initial values. This function also created the command history.
  156. stds.set_initial_values(temporal_type=temporaltype, semantic_type="mean",
  157. title=title, description=description)
  158. # Now we can insert the new space time dataset in the database
  159. stds.insert(dbif=dbif)
  160. # Close the database connection
  161. dbif.close()
  162. \endcode
  163. \subsection PythonTGISExamplesShifting Temporal shifting
  164. \code
  165. import grass.script as grass
  166. import grass.temporal as tgis
  167. id="test@PERMANENT"
  168. type="strds"
  169. # Make sure the temporal database exists
  170. tgis.init()
  171. dbif = tgis.SQLDatabaseInterfaceConnection()
  172. dbif.connect()
  173. stds = tgis.dataset_factory(type, id)
  174. if stds.is_in_db(dbif) == False:
  175. dbif.close()
  176. grass.fatal(_("Space time dataset <%s> not found in temporal database") % (id))
  177. stds.select(dbif=dbif)
  178. stds.snap(dbif=dbif)
  179. stds.update_command_string(dbif=dbif)
  180. dbif.close()
  181. \endcode
  182. \section PythonTGISAuthors Authors
  183. Soeren Gebbert
  184. TODO: add more documentation
  185. */