t.create.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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: Creates a space time dataset.
  18. #% keywords: temporal
  19. #% keywords: map management
  20. #% keywords: create
  21. #%end
  22. #%option G_OPT_STDS_OUTPUT
  23. #%end
  24. #%option G_OPT_STDS_TYPE
  25. #%end
  26. #%option G_OPT_T_TYPE
  27. #%end
  28. #%option
  29. #% key: semantictype
  30. #% type: string
  31. #% description: Semantic type of the space time dataset
  32. #% required: yes
  33. #% multiple: no
  34. #% options: min,max,sum,mean
  35. #% answer: mean
  36. #%end
  37. #%option
  38. #% key: title
  39. #% type: string
  40. #% description: Title of the new space time dataset
  41. #% required: yes
  42. #% multiple: no
  43. #%end
  44. #%option
  45. #% key: description
  46. #% type: string
  47. #% description: Description of the new space time dataset
  48. #% required: yes
  49. #% multiple: no
  50. #%end
  51. import grass.temporal as tgis
  52. import grass.script as grass
  53. ############################################################################
  54. def main():
  55. # Get the options
  56. name = options["output"]
  57. type = options["type"]
  58. temporaltype = options["temporaltype"]
  59. title = options["title"]
  60. descr = options["description"]
  61. semantic = options["semantictype"]
  62. tgis.init()
  63. #Get the current mapset to create the id of the space time dataset
  64. mapset = grass.gisenv()["MAPSET"]
  65. id = name + "@" + mapset
  66. sp = tgis.dataset_factory(type, id)
  67. dbif = tgis.SQLDatabaseInterfaceConnection()
  68. dbif.connect()
  69. if sp.is_in_db(dbif) and grass.overwrite() == False:
  70. dbif.close()
  71. grass.fatal(_("Space time %s dataset <%s> is already in the database. "
  72. "Use the overwrite flag.") %
  73. (sp.get_new_map_instance(None).get_type(), name))
  74. if sp.is_in_db(dbif) and grass.overwrite() == True:
  75. grass.info(_("Overwrite space time %s dataset <%s> "
  76. "and unregister all maps.") %
  77. (sp.get_new_map_instance(None).get_type(), name))
  78. sp.delete(dbif)
  79. sp = sp.get_new_instance(id)
  80. grass.verbose(_("Create space time %s dataset.") %
  81. sp.get_new_map_instance(None).get_type())
  82. sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,
  83. title=title, description=descr)
  84. sp.insert(dbif)
  85. dbif.close()
  86. if __name__ == "__main__":
  87. options, flags = grass.parser()
  88. main()