tgis_base.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. """!@package grass.script.tgis_base
  2. @brief GRASS Python scripting module (temporal GIS functions)
  3. Temporal GIS basic functions and classes to be used in other
  4. Python temporal gis packages.
  5. This packages includes all base classes to stor basic information like id, name,
  6. mapset creation and modification time.
  7. Usage:
  8. @code
  9. from grass.script import tgis_core as grass
  10. rbase = grass.raster_base(ident="soil")
  11. ...
  12. @endcode
  13. (C) 2008-2011 by the GRASS Development Team
  14. This program is free software under the GNU General Public
  15. License (>=v2). Read the file COPYING that comes with GRASS
  16. for details.
  17. @author Soeren Gebbert
  18. """
  19. from tgis_core import *
  20. class dataset_base(sql_database_interface):
  21. """This is the base class for all maps and spacetime datasets storing basic information"""
  22. def __init__(self, table=None, ident=None, name=None, mapset=None, creator=None, ctime=None,\
  23. mtime=None, ttype=None, revision=1):
  24. sql_database_interface.__init__(self, table, ident)
  25. self.set_id(ident)
  26. self.set_name(name)
  27. self.set_mapset(mapset)
  28. self.set_creator(creator)
  29. self.set_ctime(ctime)
  30. self.set_mtime(mtime)
  31. self.set_ttype(ttype)
  32. self.set_revision(revision)
  33. def set_id(self, ident):
  34. """Convenient method to set the unique identifier (primary key)"""
  35. self.ident = ident
  36. self.D["id"] = ident
  37. def set_name(self, name):
  38. """Set the name of the map"""
  39. self.D["name"] = name
  40. def set_mapset(self, mapset):
  41. """Set the mapset of the map"""
  42. self.D["mapset"] = mapset
  43. def set_creator(self, creator):
  44. """Set the creator of the map"""
  45. self.D["creator"] = creator
  46. def set_ctime(self, ctime=None):
  47. """Set the creation time of the map, if nothing set the current time is used"""
  48. if ctime == None:
  49. self.D["creation_time"] = datetime.now()
  50. else:
  51. self.D["creation_time"] = ctime
  52. def set_mtime(self, mtime=None):
  53. """Set the modification time of the map, if nothing set the current time is used"""
  54. if mtime == None:
  55. self.D["modification_time"] = datetime.now()
  56. else:
  57. self.D["modification_time"] = mtime
  58. def set_ttype(self, ttype):
  59. """Set the temporal type of the map: absolute or relative, if nothing set absolute time will assumed"""
  60. if ttype == None or (ttype != "absolute" and ttype != "relative"):
  61. self.D["temporal_type"] = "absolute"
  62. else:
  63. self.D["temporal_type"] = ttype
  64. def set_revision(self, revision=1):
  65. """Set the revision of the map: if nothing set revision 1 will assumed"""
  66. self.D["revision"] = revision
  67. def get_id(self):
  68. """Convenient method to get the unique identifier (primary key)
  69. @return None if not found
  70. """
  71. if self.D.has_key("id"):
  72. return self.D["id"]
  73. else:
  74. return None
  75. def get_name(self):
  76. """Get the name of the map
  77. @return None if not found"""
  78. if self.D.has_key("name"):
  79. return self.D["name"]
  80. else:
  81. return None
  82. def get_mapset(self):
  83. """Get the mapset of the map
  84. @return None if not found"""
  85. if self.D.has_key("mapset"):
  86. return self.D["mapset"]
  87. else:
  88. return None
  89. def get_creator(self):
  90. """Get the creator of the map
  91. @return None if not found"""
  92. if self.D.has_key("creator"):
  93. return self.D["creator"]
  94. else:
  95. return None
  96. def get_ctime(self):
  97. """Get the creation time of the map, datatype is datetime
  98. @return None if not found"""
  99. if self.D.has_key("creation_time"):
  100. return self.D["creation_time"]
  101. else:
  102. return None
  103. def get_mtime(self):
  104. """Get the modification time of the map, datatype is datetime
  105. @return None if not found"""
  106. if self.D.has_key("modification_time"):
  107. return self.D["modification_time"]
  108. else:
  109. return None
  110. def get_ttype(self):
  111. """Get the temporal type of the map
  112. @return None if not found"""
  113. if self.D.has_key("temporal_type"):
  114. return self.D["temporal_type"]
  115. else:
  116. return None
  117. def get_revision(self):
  118. """Get the revision of the map
  119. @return None if not found"""
  120. if self.D.has_key("revision"):
  121. return self.D["revision"]
  122. else:
  123. return None
  124. def print_info(self):
  125. """Print information about this class in human readable style"""
  126. # 0123456789012345678901234567890
  127. print " Id: ........................ " + str(self.get_id())
  128. print " Name: ...................... " + str(self.get_name())
  129. print " Mapset: .................... " + str(self.get_mapset())
  130. print " Creator: ................... " + str(self.get_creator())
  131. print " Creation time: ............. " + str(self.get_ctime())
  132. print " Modification time: ......... " + str(self.get_mtime())
  133. print " Temporal type: ............. " + str(self.get_ttype())
  134. print " Revision in database: ...... " + str(self.get_revision())
  135. def print_shell_info(self):
  136. """Print information about this class in shell style"""
  137. print "id=" + str(self.get_id())
  138. print "name=" + str(self.get_name())
  139. print "mapset=" + str(self.get_mapset())
  140. print "creator=" + str(self.get_creator())
  141. print "creation_time=" + str(self.get_ctime())
  142. print "modification_time=" + str(self.get_mtime())
  143. print "temporal_type=" + str(self.get_ttype())
  144. print "revision=" + str(self.get_revision())
  145. ###############################################################################
  146. class raster_base(dataset_base):
  147. def __init__(self, ident=None, name=None, mapset=None, creator=None, creation_time=None,\
  148. modification_time=None, temporal_type=None, revision=1):
  149. dataset_base.__init__(self, "raster_base", ident, name, mapset, creator, creation_time,\
  150. modification_time, temporal_type, revision)
  151. class raster3d_base(dataset_base):
  152. def __init__(self, ident=None, name=None, mapset=None, creator=None, creation_time=None,\
  153. modification_time=None, temporal_type=None, revision=1):
  154. dataset_base.__init__(self, "raster3d_base", ident, name, mapset, creator, creation_time,\
  155. modification_time, temporal_type, revision)
  156. class vector_base(dataset_base):
  157. def __init__(self, ident=None, name=None, mapset=None, creator=None, creation_time=None,\
  158. modification_time=None, temporal_type=None, revision=1):
  159. dataset_base.__init__(self, "vector_base", ident, name, mapset, creator, creation_time,\
  160. modification_time, temporal_type, revision)
  161. ###############################################################################
  162. class stds_base(dataset_base):
  163. def __init__(self, table=None, ident=None, name=None, mapset=None, semantic_type=None, creator=None, creation_time=None,\
  164. modification_time=None, temporal_type=None, revision=1):
  165. dataset_base.__init__(self, table, ident, name, mapset, creator, creation_time,\
  166. modification_time, temporal_type, revision)
  167. self.set_semantic_type(semantic_type)
  168. def set_semantic_type(self, semantic_type):
  169. """Set the semantic type of the space time dataset"""
  170. self.D["semantic_type"] = semantic_type
  171. def get_semantic_type(self):
  172. """Get the semantic type of the space time dataset
  173. @return None if not found"""
  174. if self.D.has_key("semantic_type"):
  175. return self.D["semantic_type"]
  176. else:
  177. return None
  178. ###############################################################################
  179. class strds_base(stds_base):
  180. def __init__(self, ident=None, name=None, mapset=None, semantic_type=None, creator=None, creation_time=None,\
  181. modification_time=None, temporal_type=None, revision=1):
  182. stds_base.__init__(self, "strds_base", ident, name, mapset, semantic_type, creator, creation_time,\
  183. modification_time, temporal_type, revision)
  184. class str3ds_base(stds_base):
  185. def __init__(self, ident=None, name=None, mapset=None, semantic_type=None, creator=None, creation_time=None,\
  186. modification_time=None, temporal_type=None, revision=1):
  187. stds_base.__init__(self, "str3ds_base", ident, name, mapset, semantic_type, creator, creation_time,\
  188. modification_time, temporal_type, revision)
  189. class stvds_base(stds_base):
  190. def __init__(self, ident=None, name=None, mapset=None, semantic_type=None, creator=None, creation_time=None,\
  191. modification_time=None, temporal_type=None, revision=1):
  192. stds_base.__init__(self, "stvds_base", ident, name, mapset, semantic_type, creator, creation_time,\
  193. modification_time, temporal_type, revision)