t.create.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: create
  20. #%end
  21. #%option G_OPT_STDS_OUTPUT
  22. #%end
  23. #%option G_OPT_STDS_TYPE
  24. #%end
  25. #%option G_OPT_T_TYPE
  26. #%end
  27. #%option
  28. #% key: semantictype
  29. #% type: string
  30. #% description: Semantic type of the space time dataset
  31. #% required: yes
  32. #% multiple: no
  33. #% options: min,max,sum,mean
  34. #% answer: mean
  35. #%end
  36. #%option
  37. #% key: title
  38. #% type: string
  39. #% description: Title of the new space time dataset
  40. #% required: yes
  41. #% multiple: no
  42. #%end
  43. #%option
  44. #% key: description
  45. #% type: string
  46. #% description: Description of the new space time dataset
  47. #% required: yes
  48. #% multiple: no
  49. #%end
  50. import grass.temporal as tgis
  51. import grass.script as grass
  52. ############################################################################
  53. def main():
  54. # Get the options
  55. name = options["output"]
  56. type = options["type"]
  57. temporaltype = options["temporaltype"]
  58. title = options["title"]
  59. descr = options["description"]
  60. semantic = options["semantictype"]
  61. # Make sure the temporal database exists
  62. tgis.create_temporal_database()
  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.sql_database_interface_connection()
  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. Use the overwrite flag.") % (sp.get_new_map_instance(None).get_type(), name))
  72. if sp.is_in_db(dbif) and grass.overwrite() == True:
  73. grass.info(_("Overwrite space time %s dataset <%s> and unregister all maps.") % (sp.get_new_map_instance(None).get_type(), name))
  74. sp.delete(dbif)
  75. sp = sp.get_new_instance(id)
  76. grass.verbose(_("Create space time %s dataset.") % sp.get_new_map_instance(None).get_type())
  77. sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic, title=title, description=descr)
  78. sp.insert(dbif)
  79. dbif.close()
  80. if __name__ == "__main__":
  81. options, flags = grass.parser()
  82. main()