create.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. tgis.register_maps_in_space_time_dataset(type, name, maps)
  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. from space_time_datasets import *
  17. from factory import *
  18. ###############################################################################
  19. def create_space_time_dataset(name, type, temporaltype, title, descr, semantic,
  20. dbif=None, overwrite=False):
  21. """!Create a new space time dataset
  22. This function is sensitive to the settings in grass.core.overwrite to
  23. overwrute existing space time datasets.
  24. @param name The name of the new space time dataset
  25. @param type The type (strds, stvds, str3ds) of the new space time
  26. dataset
  27. @param temporaltype The temporal type (relative or absolute)
  28. @param title The title
  29. @param descr The dataset description
  30. @param semantic Semantical information
  31. @param dbif The temporal database interface to be used
  32. @param overwrite Flag to allow overwriting
  33. @return The new created space time dataset
  34. This function will raise a ScriptError in case of an error.
  35. """
  36. #Get the current mapset to create the id of the space time dataset
  37. mapset = core.gisenv()["MAPSET"]
  38. id = name + "@" + mapset
  39. sp = dataset_factory(type, id)
  40. dbif, connected = init_dbif(dbif)
  41. if sp.is_in_db(dbif) and overwrite == False:
  42. if connected:
  43. dbif.close()
  44. core.fatal(_("Space time %(sp)s dataset <%(name)s> is already in the"
  45. " database. Use the overwrite flag.") % {
  46. 'sp': sp.get_new_map_instance(None).get_type(),
  47. 'name': name})
  48. return None
  49. if sp.is_in_db(dbif) and overwrite == True:
  50. core.warning(_("Overwrite space time %(sp)s dataset <%(name)s> and "
  51. "unregister all maps.") % {
  52. 'sp': sp.get_new_map_instance(None).get_type(),
  53. 'name': name})
  54. sp.delete(dbif)
  55. sp = sp.get_new_instance(id)
  56. core.verbose(_("Create new space time %s dataset.") %
  57. sp.get_new_map_instance(None).get_type())
  58. sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,
  59. title=title, description=descr)
  60. sp.insert(dbif)
  61. if connected:
  62. dbif.close()
  63. return sp