pythontemporallib.dox 7.8 KB

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