create.py 2.6 KB

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