t.create.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.create
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Create a space time dataset
  9. # COPYRIGHT: (C) 2011 by the GRASS Development Team
  10. #
  11. # This program is free software under the GNU General Public
  12. # License (version 2). Read the file COPYING that comes with GRASS
  13. # for details.
  14. #
  15. #############################################################################
  16. #%module
  17. #% description: Create a space time dataset
  18. #% keywords: spacetime
  19. #% keywords: dataset
  20. #% keywords: create
  21. #%end
  22. #%option
  23. #% key: output
  24. #% type: string
  25. #% description: Name of the new space time dataset
  26. #% required: yes
  27. #% multiple: no
  28. #%end
  29. #%option
  30. #% key: semantictype
  31. #% type: string
  32. #% description: The semantic type of the space time dataset
  33. #% required: yes
  34. #% multiple: no
  35. #% options: event, const, continuous
  36. #% answer: event
  37. #%end
  38. #%option
  39. #% key: type
  40. #% type: string
  41. #% description: Type of the space time dataset, default is strds
  42. #% required: no
  43. #% options: strds, str3ds, stvds
  44. #% answer: strds
  45. #%end
  46. #%option
  47. #% key: temporaltype
  48. #% type: string
  49. #% description: The temporal type of the space time dataset, default is absolute
  50. #% required: no
  51. #% options: absolute,relative
  52. #% answer: absolute
  53. #%end
  54. #%option
  55. #% key: title
  56. #% type: string
  57. #% description: Title of the new space time dataset
  58. #% required: yes
  59. #% multiple: no
  60. #%end
  61. #%option
  62. #% key: description
  63. #% type: string
  64. #% description: Description of the new space time dataset
  65. #% required: yes
  66. #% multiple: no
  67. #%end
  68. import grass.temporal as tgis
  69. import grass.script as grass
  70. ############################################################################
  71. def main():
  72. # Get the options
  73. name = options["output"]
  74. type = options["type"]
  75. temporaltype = options["temporaltype"]
  76. title = options["title"]
  77. descr = options["description"]
  78. semantic = options["semantictype"]
  79. # Make sure the temporal database exists
  80. tgis.create_temporal_database()
  81. #Get the current mapset to create the id of the space time dataset
  82. mapset = grass.gisenv()["MAPSET"]
  83. id = name + "@" + mapset
  84. sp = tgis.dataset_factory(type, id)
  85. dbif = tgis.sql_database_interface()
  86. dbif.connect()
  87. if sp.is_in_db(dbif) and grass.overwrite() == False:
  88. dbif.close()
  89. grass.fatal(_("Space time %s dataset <%s> is already in the database. Use the overwrite flag.") % name)
  90. if sp.is_in_db(dbif) and grass.overwrite() == True:
  91. grass.info(_("Overwrite space time %s dataset <%s> and unregister all maps.") % (sp.get_new_map_instance(None).get_type(), name))
  92. sp.delete(dbif)
  93. sp = sp.get_new_instance(id)
  94. grass.verbose(_("Create space time %s dataset.") % sp.get_new_map_instance(None).get_type())
  95. sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic, title=title, description=descr)
  96. sp.insert(dbif)
  97. dbif.close()
  98. if __name__ == "__main__":
  99. options, flags = grass.parser()
  100. main()