create.py 2.6 KB

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