t.support.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.support
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Modify the metadata of 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: Modify the metadata of a space time dataset
  18. #% keywords: spacetime
  19. #% keywords: dataset
  20. #% keywords: create
  21. #%end
  22. #%option
  23. #% key: input
  24. #% type: string
  25. #% description: Name of the space time dataset
  26. #% required: yes
  27. #% multiple: no
  28. #%end
  29. #%option
  30. #% key: granularity
  31. #% type: string
  32. #% description: The granularity of the space time dataset (NNN day, NNN week, NNN month)
  33. #% required: yes
  34. #% multiple: no
  35. #%end
  36. #%option
  37. #% key: semantictype
  38. #% type: string
  39. #% description: The semantic type of the space time dataset
  40. #% required: yes
  41. #% multiple: no
  42. #% options: event, const, continuous
  43. #% answer: event
  44. #%end
  45. #%option
  46. #% key: type
  47. #% type: string
  48. #% description: Type of the space time dataset, default is strds
  49. #% required: no
  50. #% options: strds, str3ds, stvds
  51. #% answer: strds
  52. #%end
  53. #%option
  54. #% key: title
  55. #% type: string
  56. #% description: Title of the space time dataset
  57. #% required: yes
  58. #% multiple: no
  59. #%end
  60. #%option
  61. #% key: description
  62. #% type: string
  63. #% description: Description of the space time dataset
  64. #% required: yes
  65. #% multiple: no
  66. #%end
  67. #%flag
  68. #% key: u
  69. #% description: Update metadata information, temporal and spatial extent from registered maps
  70. #%end
  71. import grass.temporal as tgis
  72. import grass.script as grass
  73. ############################################################################
  74. def main():
  75. # Get the options
  76. name = options["input"]
  77. type = options["type"]
  78. title = options["title"]
  79. descr = options["description"]
  80. semantic = options["semantictype"]
  81. gran = options["granularity"]
  82. update = flags["u"]
  83. # Make sure the temporal database exists
  84. tgis.create_temporal_database()
  85. #Get the current mapset to create the id of the space time dataset
  86. mapset = grass.gisenv()["MAPSET"]
  87. id = name + "@" + mapset
  88. if type == "strds":
  89. sp = tgis.space_time_raster_dataset(id)
  90. if type == "str3ds":
  91. sp = tgis.space_time_raster3d_dataset(id)
  92. if type == "stvds":
  93. sp = tgis.space_time_vector_dataset(id)
  94. if sp.is_in_db() == False:
  95. grass.fatal(_("%s dataset <%s> not found in temporal database") % (ds.get_type(), name))
  96. sp.select()
  97. # Temporal type can not be changed
  98. ttype= sp.get_temporal_type()
  99. sp.set_initial_values(granularity=gran, temporal_type=ttype, semantic_type=semantic, title=title, description=descr)
  100. # Update only non-null entries
  101. sp.update()
  102. if update:
  103. sp.update_from_registered_maps()
  104. if __name__ == "__main__":
  105. options, flags = grass.parser()
  106. main()