pythontemporallib.dox 8.3 KB

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