space_time_datasets.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. """!@package grass.temporal
  2. @brief GRASS Python scripting module (temporal GIS functions)
  3. Temporal GIS related functions to be used in Python scripts.
  4. Usage:
  5. @code
  6. import grass.temporal as tgis
  7. strds = tgis.space_time_raster_dataset("soils_1950_2010")
  8. ...
  9. @endcode
  10. (C) 2008-2011 by the GRASS Development Team
  11. This program is free software under the GNU General Public
  12. License (>=v2). Read the file COPYING that comes with GRASS
  13. for details.
  14. @author Soeren Gebbert
  15. """
  16. import getpass
  17. from ctypes import *
  18. import grass.lib.gis as libgis
  19. import grass.lib.raster as libraster
  20. import grass.lib.vector as libvector
  21. import grass.lib.raster3d as libraster3d
  22. from datetime_math import *
  23. from abstract_map_dataset import *
  24. from abstract_space_time_dataset import *
  25. ###############################################################################
  26. class raster_dataset(abstract_map_dataset):
  27. """!Raster dataset class
  28. This class provides functions to select, update, insert or delete raster
  29. map information and valid time stamps into the SQL temporal database.
  30. """
  31. def __init__(self, ident):
  32. self.reset(ident)
  33. def get_type(self):
  34. return "raster"
  35. def get_new_instance(self, ident):
  36. """!Return a new instance with the type of this class"""
  37. return raster_dataset(ident)
  38. def get_new_stds_instance(self, ident):
  39. """!Return a new space time dataset instance in which maps are stored with the type of this class"""
  40. return space_time_raster_dataset(ident)
  41. def get_stds_register(self):
  42. """!Return the space time dataset register table name in which stds are listed in which this map is registered"""
  43. return self.metadata.get_strds_register()
  44. def set_stds_register(self, name):
  45. """!Set the space time dataset register table name in which stds are listed in which this map is registered"""
  46. self.metadata.set_strds_register(name)
  47. def spatial_overlapping(self, dataset):
  48. """!Return True if the spatial extents 2d overlap"""
  49. return self.spatial_extent.overlapping_2d(dataset.spatial_extent)
  50. def spatial_relation(self, dataset):
  51. """Return the two dimensional spatial relation"""
  52. return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
  53. def reset(self, ident):
  54. """!Reset the internal structure and set the identifier"""
  55. self.ident = ident
  56. self.base = raster_base(ident=ident)
  57. self.absolute_time = raster_absolute_time(ident=ident)
  58. self.relative_time = raster_relative_time(ident=ident)
  59. self.spatial_extent = raster_spatial_extent(ident=ident)
  60. self.metadata = raster_metadata(ident=ident)
  61. def has_grass_timestamp(self):
  62. """!Check if a grass file bsased time stamp exists for this map.
  63. """
  64. if G_has_raster_timestamp(self.get_name(), self.get_mapset()):
  65. return True
  66. else:
  67. return False
  68. def write_timestamp_to_grass(self):
  69. """!Write the timestamp of this map into the map metadata in the grass file system based spatial
  70. database.
  71. Internally the libgis API functions are used for writing
  72. """
  73. ts = libgis.TimeStamp()
  74. libgis.G_scan_timestamp(byref(ts), self._convert_timestamp())
  75. check = libgis.G_write_raster_timestamp(self.get_name(), byref(ts))
  76. if check == -1:
  77. core.error(_("Unable to create timestamp file for raster map <%s>"%(self.get_map_id())))
  78. if check == -2:
  79. core.error(_("Invalid datetime in timestamp for raster map <%s>"%(self.get_map_id())))
  80. def remove_timestamp_from_grass(self):
  81. """!Remove the timestamp from the grass file system based spatial database
  82. Internally the libgis API functions are used for removal
  83. """
  84. check = libgis.G_remove_raster_timestamp(self.get_name())
  85. if check == -1:
  86. core.error(_("Unable to remove timestamp for raster map <%s>"%(self.get_name())))
  87. def map_exists(self):
  88. """!Return True in case the map exists in the grass spatial database
  89. @return True if map exists, False otherwise
  90. """
  91. mapset = libgis.G_find_raster(self.get_name(), self.get_mapset())
  92. if not mapset:
  93. return False
  94. return True
  95. def read_info(self):
  96. """!Read the raster map info from the file system and store the content
  97. into a dictionary
  98. This method uses the ctypes interface to the gis and raster libraries
  99. to read the map metadata information
  100. """
  101. kvp = {}
  102. name = self.get_name()
  103. mapset = self.get_mapset()
  104. if not self.map_exists():
  105. core.fatal(_("Raster map <%s> not found" % name))
  106. # Read the region information
  107. region = libgis.Cell_head()
  108. libraster.Rast_get_cellhd(name, mapset, byref(region))
  109. kvp["north"] = region.north
  110. kvp["south"] = region.south
  111. kvp["east"] = region.east
  112. kvp["west"] = region.west
  113. kvp["nsres"] = region.ns_res
  114. kvp["ewres"] = region.ew_res
  115. kvp["rows"] = region.cols
  116. kvp["cols"] = region.rows
  117. maptype = libraster.Rast_map_type(name, mapset)
  118. if maptype == libraster.DCELL_TYPE:
  119. kvp["datatype"] = "DCELL"
  120. elif maptype == libraster.FCELL_TYPE:
  121. kvp["datatype"] = "FCELL"
  122. elif maptype == libraster.CELL_TYPE:
  123. kvp["datatype"] = "CELL"
  124. # Read range
  125. if libraster.Rast_map_is_fp(name, mapset):
  126. range = libraster.FPRange()
  127. libraster.Rast_init_fp_range (byref(range))
  128. ret = libraster.Rast_read_fp_range(name, mapset, byref(range))
  129. if ret < 0:
  130. core.fatal(_("Unable to read range file"))
  131. if ret == 2:
  132. kvp["min"] = None
  133. kvp["max"] = None
  134. else:
  135. min = libgis.DCELL()
  136. max = libgis.DCELL()
  137. libraster.Rast_get_fp_range_min_max(byref(range), byref(min), byref(max))
  138. kvp["min"] = min.value
  139. kvp["max"] = max.value
  140. else:
  141. range = libraster.Range()
  142. libraster.Rast_init_range (byref(range))
  143. ret = libraster.Rast_read_range(name, mapset, byref(range))
  144. if ret < 0:
  145. core.fatal(_("Unable to read range file"))
  146. if ret == 2:
  147. kvp["min"] = None
  148. kvp["max"] = None
  149. else:
  150. min = libgis.CELL()
  151. max = libgis.CELL()
  152. libraster.Rast_get_range_min_max(byref(range), byref(min), byref(max))
  153. kvp["min"] = min.value
  154. kvp["max"] = max.value
  155. return kvp
  156. def load(self):
  157. """!Load all info from an existing raster map into the internal structure"""
  158. # Fill base information
  159. self.base.set_name(self.ident.split("@")[0])
  160. self.base.set_mapset(self.ident.split("@")[1])
  161. self.base.set_creator(str(getpass.getuser()))
  162. # Get the data from an existing raster map
  163. kvp = self.read_info()
  164. # Fill spatial extent
  165. self.set_spatial_extent(north=kvp["north"], south=kvp["south"], \
  166. east=kvp["east"], west=kvp["west"])
  167. # Fill metadata
  168. self.metadata.set_nsres(kvp["nsres"])
  169. self.metadata.set_ewres(kvp["ewres"])
  170. self.metadata.set_datatype(kvp["datatype"])
  171. self.metadata.set_min(kvp["min"])
  172. self.metadata.set_max(kvp["max"])
  173. rows = kvp["rows"]
  174. cols = kvp["cols"]
  175. ncells = cols * rows
  176. self.metadata.set_cols(cols)
  177. self.metadata.set_rows(rows)
  178. self.metadata.set_number_of_cells(ncells)
  179. ###############################################################################
  180. class raster3d_dataset(abstract_map_dataset):
  181. """!Raster3d dataset class
  182. This class provides functions to select, update, insert or delete raster3d
  183. map information and valid time stamps into the SQL temporal database.
  184. """
  185. def __init__(self, ident):
  186. self.reset(ident)
  187. def get_type(self):
  188. return "raster3d"
  189. def get_new_instance(self, ident):
  190. """!Return a new instance with the type of this class"""
  191. return raster3d_dataset(ident)
  192. def get_new_stds_instance(self, ident):
  193. """!Return a new space time dataset instance in which maps are stored with the type of this class"""
  194. return space_time_raster3d_dataset(ident)
  195. def get_stds_register(self):
  196. """!Return the space time dataset register table name in which stds are listed in which this map is registered"""
  197. return self.metadata.get_str3ds_register()
  198. def set_stds_register(self, name):
  199. """!Set the space time dataset register table name in which stds are listed in which this map is registered"""
  200. self.metadata.set_str3ds_register(name)
  201. def spatial_overlapping(self, dataset):
  202. """!Return True if the spatial extents overlap"""
  203. if self.get_type() == dataset.get_type() or dataset.get_type() == "str3ds":
  204. return self.spatial_extent.overlapping(dataset.spatial_extent)
  205. else:
  206. return self.spatial_extent.overlapping_2d(dataset.spatial_extent)
  207. def spatial_relation(self, dataset):
  208. """!Return the two or three dimensional spatial relation"""
  209. if self.get_type() == dataset.get_type() or dataset.get_type() == "str3ds":
  210. return self.spatial_extent.spatial_relation(dataset.spatial_extent)
  211. else:
  212. return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
  213. def reset(self, ident):
  214. """!Reset the internal structure and set the identifier"""
  215. self.ident = ident
  216. self.base = raster3d_base(ident=ident)
  217. self.absolute_time = raster3d_absolute_time(ident=ident)
  218. self.relative_time = raster3d_relative_time(ident=ident)
  219. self.spatial_extent = raster3d_spatial_extent(ident=ident)
  220. self.metadata = raster3d_metadata(ident=ident)
  221. def has_grass_timestamp(self):
  222. """!Check if a grass file bsased time stamp exists for this map.
  223. """
  224. if G_has_raster3d_timestamp(self.get_name(), self.get_mapset()):
  225. return True
  226. else:
  227. return False
  228. def write_timestamp_to_grass(self):
  229. """!Write the timestamp of this map into the map metadata in the grass file system based spatial
  230. database.
  231. Internally the libgis API functions are used for writing
  232. """
  233. ts = libgis.TimeStamp()
  234. libgis.G_scan_timestamp(byref(ts), self._convert_timestamp())
  235. check = libgis.G_write_raster3d_timestamp(self.get_name(), byref(ts))
  236. if check == -1:
  237. core.error(_("Unable to create timestamp file for raster3d map <%s>"%(self.get_map_id())))
  238. if check == -2:
  239. core.error(_("Invalid datetime in timestamp for raster3d map <%s>"%(self.get_map_id())))
  240. def remove_timestamp_from_grass(self):
  241. """!Remove the timestamp from the grass file system based spatial database
  242. Internally the libgis API functions are used for removal
  243. """
  244. check = libgis.G_remove_raster3d_timestamp(self.get_name())
  245. if check == -1:
  246. core.error(_("Unable to remove timestamp for raster3d map <%s>"%(self.get_name())))
  247. def map_exists(self):
  248. """!Return True in case the map exists in the grass spatial database
  249. @return True if map exists, False otherwise
  250. """
  251. mapset = libgis.G_find_raster3d(self.get_name(), self.get_mapset())
  252. if not mapset:
  253. return False
  254. return True
  255. def read_info(self):
  256. """!Read the raster3d map info from the file system and store the content
  257. into a dictionary
  258. This method uses the ctypes interface to the gis and raster3d libraries
  259. to read the map metadata information
  260. """
  261. kvp = {}
  262. name = self.get_name()
  263. mapset = self.get_mapset()
  264. if not self.map_exists():
  265. core.fatal(_("Raster3d map <%s> not found" % name))
  266. # Read the region information
  267. region = libraster3d.RASTER3D_Region()
  268. libraster3d.Rast3d_read_region_map(name, mapset, byref(region))
  269. kvp["north"] = region.north
  270. kvp["south"] = region.south
  271. kvp["east"] = region.east
  272. kvp["west"] = region.west
  273. kvp["nsres"] = region.ns_res
  274. kvp["ewres"] = region.ew_res
  275. kvp["tbres"] = region.tb_res
  276. kvp["rows"] = region.cols
  277. kvp["cols"] = region.rows
  278. kvp["depths"] = region.depths
  279. kvp["top"] = region.top
  280. kvp["bottom"] = region.bottom
  281. # We need to open the map, this function returns a void pointer
  282. # but we may need the correct type which is RASTER3D_Map, hence the casting
  283. g3map = cast(libraster3d.Rast3d_open_cell_old(name, mapset, \
  284. libraster3d.RASTER3D_DEFAULT_WINDOW, libraster3d.RASTER3D_TILE_SAME_AS_FILE, \
  285. libraster3d.RASTER3D_NO_CACHE), POINTER(libraster3d.RASTER3D_Map))
  286. if not g3map:
  287. core.fatal(_("Unable to open 3D raster map <%s>"%(name)));
  288. maptype = libraster3d.Rast3d_file_type_map(g3map)
  289. if maptype == libraster.DCELL_TYPE:
  290. kvp["datatype"] = "DCELL"
  291. elif maptype == libraster.FCELL_TYPE:
  292. kvp["datatype"] = "FCELL"
  293. # Read range
  294. min = libgis.DCELL()
  295. max = libgis.DCELL()
  296. ret = libraster3d.Rast3d_range_load(g3map)
  297. if not ret:
  298. core.fatal(_("Unable to load range of 3D raster map <%s>"%(name)));
  299. libraster3d.Rast3d_range_min_max(g3map, byref(min), byref(max))
  300. if min.value != min.value:
  301. kvp["min"] = None
  302. else:
  303. kvp["min"] = float(min.value)
  304. if max.value != max.value:
  305. kvp["max"] = None
  306. else:
  307. kvp["max"] = float(max.value)
  308. if not libraster3d.Rast3d_close(g3map):
  309. G_fatal_error(_("Unable to close 3D raster map <%s>"%(name)))
  310. return kvp
  311. def load(self):
  312. """!Load all info from an existing raster3d map into the internal structure"""
  313. # Fill base information
  314. self.base.set_name(self.ident.split("@")[0])
  315. self.base.set_mapset(self.ident.split("@")[1])
  316. self.base.set_creator(str(getpass.getuser()))
  317. # Fill spatial extent
  318. # Get the data from an existing raster map
  319. kvp = self.read_info()
  320. self.set_spatial_extent(north=kvp["north"], south=kvp["south"], \
  321. east=kvp["east"], west=kvp["west"],\
  322. top=kvp["top"], bottom=kvp["bottom"])
  323. # Fill metadata
  324. self.metadata.set_nsres(kvp["nsres"])
  325. self.metadata.set_ewres(kvp["ewres"])
  326. self.metadata.set_tbres(kvp["tbres"])
  327. self.metadata.set_datatype(kvp["datatype"])
  328. self.metadata.set_min(kvp["min"])
  329. self.metadata.set_max(kvp["max"])
  330. rows = kvp["rows"]
  331. cols = kvp["cols"]
  332. depths = kvp["depths"]
  333. ncells = cols * rows
  334. ncells = cols * rows * depths
  335. self.metadata.set_cols(cols)
  336. self.metadata.set_rows(rows)
  337. self.metadata.set_depths(depths)
  338. self.metadata.set_number_of_cells(ncells)
  339. ###############################################################################
  340. class vector_dataset(abstract_map_dataset):
  341. """!Vector dataset class
  342. This class provides functions to select, update, insert or delete vector
  343. map information and valid time stamps into the SQL temporal database.
  344. """
  345. def __init__(self, ident):
  346. self.reset(ident)
  347. def get_type(self):
  348. return "vector"
  349. def get_new_instance(self, ident):
  350. """!Return a new instance with the type of this class"""
  351. return vector_dataset(ident)
  352. def get_new_stds_instance(self, ident):
  353. """!Return a new space time dataset instance in which maps are stored with the type of this class"""
  354. return space_time_vector_dataset(ident)
  355. def get_stds_register(self):
  356. """!Return the space time dataset register table name in which stds are listed in which this map is registered"""
  357. return self.metadata.get_stvds_register()
  358. def set_stds_register(self, name):
  359. """!Set the space time dataset register table name in which stds are listed in which this map is registered"""
  360. self.metadata.set_stvds_register(name)
  361. def get_layer(self):
  362. """!Return the layer"""
  363. return self.base.get_layer()
  364. def spatial_overlapping(self, dataset):
  365. """!Return True if the spatial extents 2d overlap"""
  366. return self.spatial_extent.overlapping_2d(dataset.spatial_extent)
  367. def spatial_relation(self, dataset):
  368. """!Return the two dimensional spatial relation"""
  369. return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
  370. def reset(self, ident):
  371. """!Reset the internal structure and set the identifier"""
  372. self.ident = ident
  373. self.base = vector_base(ident=ident)
  374. self.absolute_time = vector_absolute_time(ident=ident)
  375. self.relative_time = vector_relative_time(ident=ident)
  376. self.spatial_extent = vector_spatial_extent(ident=ident)
  377. self.metadata = vector_metadata(ident=ident)
  378. def has_grass_timestamp(self):
  379. """!Check if a grass file bsased time stamp exists for this map.
  380. """
  381. if G_has_raster_timestamp(self.get_name(), self.get_layer(), self.get_mapset()):
  382. return True
  383. else:
  384. return False
  385. def write_timestamp_to_grass(self):
  386. """!Write the timestamp of this map into the map metadata in the grass file system based spatial
  387. database.
  388. Internally the libgis API functions are used for writing
  389. """
  390. ts = libgis.TimeStamp()
  391. libgis.G_scan_timestamp(byref(ts), self._convert_timestamp())
  392. check = libgis.G_write_vector_timestamp(self.get_name(), self.get_layer(), byref(ts))
  393. if check == -1:
  394. core.error(_("Unable to create timestamp file for vector map <%s>"%(self.get_map_id())))
  395. if check == -2:
  396. core.error(_("Invalid datetime in timestamp for vector map <%s>"%(self.get_map_id())))
  397. def remove_timestamp_from_grass(self):
  398. """!Remove the timestamp from the grass file system based spatial database
  399. Internally the libgis API functions are used for removal
  400. """
  401. check = libgis.G_remove_vector_timestamp(self.get_name(), self.get_layer())
  402. if check == -1:
  403. core.error(_("Unable to remove timestamp for vector map <%s>"%(self.get_name())))
  404. def map_exists(self):
  405. """!Return True in case the map exists in the grass spatial database
  406. @return True if map exists, False otherwise
  407. """
  408. mapset = libgis.G_find_vector(self.get_name(), self.get_mapset())
  409. if not mapset:
  410. return False
  411. return True
  412. def read_info(self):
  413. """!Read the vector map info from the file system and store the content
  414. into a dictionary
  415. This method uses the ctypes interface to the vector libraries
  416. to read the map metadata information
  417. """
  418. kvp = {}
  419. name = self.get_name()
  420. mapset = self.get_mapset()
  421. if not self.map_exists():
  422. core.fatal(_("Vector map <%s> not found" % name))
  423. # The vector map structure
  424. Map = libvector.Map_info()
  425. # We open the maps always in topology mode first
  426. libvector.Vect_set_open_level(2)
  427. with_topo = True
  428. # Code lend from v.info main.c
  429. if libvector.Vect_open_old_head2(byref(Map), name, mapset, "1") < 2:
  430. # force level 1, open fully
  431. # NOTE: number of points, lines, boundaries, centroids, faces, kernels is still available
  432. libvector.Vect_close(byref(Map))
  433. libvector.Vect_set_open_level(1) # no topology
  434. with_topo = False
  435. if libvector.Vect_open_old2(byref(Map), name, mapset, "1") < 1:
  436. core.fatal(_("Unable to open vector map <%s>"%(libvector.Vect_get_full_name(byref(Map)))))
  437. # Read the extent information
  438. bbox = libvector.bound_box()
  439. libvector.Vect_get_map_box(byref(Map), byref(bbox));
  440. kvp["north"] = bbox.N
  441. kvp["south"] = bbox.S
  442. kvp["east"] = bbox.E
  443. kvp["west"] = bbox.W
  444. kvp["top"] = bbox.T
  445. kvp["bottom"] = bbox.B
  446. kvp["is_3d"] = bool(libvector.Vect_is_3d(byref(Map)))
  447. # Read number of features
  448. kvp["points"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_POINT)
  449. kvp["lines"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_LINE)
  450. kvp["boundaries"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_BOUNDARY)
  451. kvp["centroids"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_CENTROID)
  452. kvp["faces"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_FACE)
  453. kvp["kernels"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_KERNEL)
  454. # Summarize the primitives
  455. kvp["primitives"] = kvp["points"] + kvp["lines"] + kvp["boundaries"] + kvp["centroids"]
  456. if kvp["is_3d"]:
  457. kvp["primitives"] += kvp["faces"] + kvp["kernels"]
  458. # Read topology information
  459. if with_topo:
  460. kvp["nodes"] = libvector.Vect_get_num_nodes(byref(Map))
  461. kvp["areas"] = libvector.Vect_get_num_areas(byref(Map))
  462. kvp["islands"] = libvector.Vect_get_num_islands(byref(Map))
  463. kvp["holes"] = libvector.Vect_get_num_holes(byref(Map))
  464. kvp["volumes"] = libvector.Vect_get_num_primitives(byref(Map), libvector.GV_VOLUME)
  465. else:
  466. kvp["nodes"] = None
  467. kvp["areas"] = None
  468. kvp["islands"] = None
  469. kvp["holes"] = None
  470. kvp["volumes"] = None
  471. libvector.Vect_close(byref(Map))
  472. return kvp
  473. def load(self):
  474. """!Load all info from an existing vector map into the internal structure"""
  475. # Fill base information
  476. if self.ident.find(":") >= 0:
  477. self.base.set_name(self.ident.split("@")[0].split(":")[0])
  478. self.base.set_layer(self.ident.split("@")[0].split(":")[1])
  479. else:
  480. self.base.set_name(self.ident.split("@")[0])
  481. self.base.set_mapset(self.ident.split("@")[1])
  482. self.base.set_creator(str(getpass.getuser()))
  483. # Get the data from an existing raster map
  484. kvp = self.read_info()
  485. # Fill spatial extent
  486. self.set_spatial_extent(north=kvp["north"], south=kvp["south"], \
  487. east=kvp["east"], west=kvp["west"],\
  488. top=kvp["top"], bottom=kvp["bottom"])
  489. # Fill metadata
  490. self.metadata.set_3d_info(kvp["is_3d"])
  491. self.metadata.set_points(kvp["points"])
  492. self.metadata.set_lines(kvp["lines"])
  493. self.metadata.set_boundaries(kvp["boundaries"])
  494. self.metadata.set_centroids(kvp["centroids"])
  495. self.metadata.set_faces(kvp["faces"])
  496. self.metadata.set_kernels(kvp["kernels"])
  497. self.metadata.set_primitives(kvp["primitives"])
  498. self.metadata.set_nodes(kvp["nodes"])
  499. self.metadata.set_areas(kvp["areas"])
  500. self.metadata.set_islands(kvp["islands"])
  501. self.metadata.set_holes(kvp["holes"])
  502. self.metadata.set_volumes(kvp["volumes"])
  503. ###############################################################################
  504. class space_time_raster_dataset(abstract_space_time_dataset):
  505. """!Space time raster dataset class
  506. """
  507. def __init__(self, ident):
  508. abstract_space_time_dataset.__init__(self, ident)
  509. def get_type(self):
  510. return "strds"
  511. def get_new_instance(self, ident):
  512. """!Return a new instance with the type of this class"""
  513. return space_time_raster_dataset(ident)
  514. def get_new_map_instance(self, ident):
  515. """!Return a new instance of a map dataset which is associated with the type of this class"""
  516. return raster_dataset(ident)
  517. def get_map_register(self):
  518. """!Return the name of the map register table"""
  519. return self.metadata.get_raster_register()
  520. def set_map_register(self, name):
  521. """!Set the name of the map register table"""
  522. self.metadata.set_raster_register(name)
  523. def spatial_overlapping(self, dataset):
  524. """!Return True if the spatial extents 2d overlap"""
  525. return self.spatial_extent.overlapping_2d(dataset.spatial_extent)
  526. def spatial_relation(self, dataset):
  527. """!Return the two dimensional spatial relation"""
  528. return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
  529. def reset(self, ident):
  530. """!Reset the internal structure and set the identifier"""
  531. self.ident = ident
  532. self.base = strds_base(ident=ident)
  533. if ident != None:
  534. self.base.set_name(self.ident.split("@")[0])
  535. self.base.set_mapset(self.ident.split("@")[1])
  536. self.base.set_creator(str(getpass.getuser()))
  537. self.absolute_time = strds_absolute_time(ident=ident)
  538. self.relative_time = strds_relative_time(ident=ident)
  539. self.spatial_extent = strds_spatial_extent(ident=ident)
  540. self.metadata = strds_metadata(ident=ident)
  541. ###############################################################################
  542. class space_time_raster3d_dataset(abstract_space_time_dataset):
  543. """!Space time raster3d dataset class
  544. """
  545. def __init__(self, ident):
  546. abstract_space_time_dataset.__init__(self, ident)
  547. def get_type(self):
  548. return "str3ds"
  549. def get_new_instance(self, ident):
  550. """!Return a new instance with the type of this class"""
  551. return space_time_raster3d_dataset(ident)
  552. def get_new_map_instance(self, ident):
  553. """!Return a new instance of a map dataset which is associated with the type of this class"""
  554. return raster3d_dataset(ident)
  555. def get_map_register(self):
  556. """!Return the name of the map register table"""
  557. return self.metadata.get_raster3d_register()
  558. def set_map_register(self, name):
  559. """!Set the name of the map register table"""
  560. self.metadata.set_raster3d_register(name)
  561. def spatial_overlapping(self, dataset):
  562. """!Return True if the spatial extents overlap"""
  563. if self.get_type() == dataset.get_type() or dataset.get_type() == "str3ds":
  564. return self.spatial_extent.overlapping(dataset.spatial_extent)
  565. else:
  566. return self.spatial_extent.overlapping_2d(dataset.spatial_extent)
  567. def spatial_relation(self, dataset):
  568. """!Return the two or three dimensional spatial relation"""
  569. if self.get_type() == dataset.get_type() or dataset.get_type() == "str3ds":
  570. return self.spatial_extent.spatial_relation(dataset.spatial_extent)
  571. else:
  572. return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
  573. def reset(self, ident):
  574. """!Reset the internal structure and set the identifier"""
  575. self.ident = ident
  576. self.base = str3ds_base(ident=ident)
  577. if ident != None:
  578. self.base.set_name(self.ident.split("@")[0])
  579. self.base.set_mapset(self.ident.split("@")[1])
  580. self.base.set_creator(str(getpass.getuser()))
  581. self.absolute_time = str3ds_absolute_time(ident=ident)
  582. self.relative_time = str3ds_relative_time(ident=ident)
  583. self.spatial_extent = str3ds_spatial_extent(ident=ident)
  584. self.metadata = str3ds_metadata(ident=ident)
  585. ###############################################################################
  586. class space_time_vector_dataset(abstract_space_time_dataset):
  587. """!Space time vector dataset class
  588. """
  589. def __init__(self, ident):
  590. abstract_space_time_dataset.__init__(self, ident)
  591. def get_type(self):
  592. return "stvds"
  593. def get_new_instance(self, ident):
  594. """!Return a new instance with the type of this class"""
  595. return space_time_vector_dataset(ident)
  596. def get_new_map_instance(self, ident):
  597. """!Return a new instance of a map dataset which is associated with the type of this class"""
  598. return vector_dataset(ident)
  599. def get_map_register(self):
  600. """!Return the name of the map register table"""
  601. return self.metadata.get_vector_register()
  602. def set_map_register(self, name):
  603. """!Set the name of the map register table"""
  604. self.metadata.set_vector_register(name)
  605. def spatial_overlapping(self, dataset):
  606. """!Return True if the spatial extents 2d overlap"""
  607. return self.spatial_extent.overlapping_2d(dataset.spatial_extent)
  608. def spatial_relation(self, dataset):
  609. """!Return the two dimensional spatial relation"""
  610. return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
  611. def reset(self, ident):
  612. """!Reset the internal structure and set the identifier"""
  613. self.ident = ident
  614. self.base = stvds_base(ident=ident)
  615. if ident != None:
  616. self.base.set_name(self.ident.split("@")[0])
  617. self.base.set_mapset(self.ident.split("@")[1])
  618. self.base.set_creator(str(getpass.getuser()))
  619. self.absolute_time = stvds_absolute_time(ident=ident)
  620. self.relative_time = stvds_relative_time(ident=ident)
  621. self.spatial_extent = stvds_spatial_extent(ident=ident)
  622. self.metadata = stvds_metadata(ident=ident)