t.shift.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.shift
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Temporally shift the maps of a space time dataset.
  9. # COPYRIGHT: (C) 2013 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: Shifts temporally the maps of a space time dataset.
  18. #% keywords: temporal
  19. #% keywords: shift
  20. #%end
  21. #%option G_OPT_STDS_INPUT
  22. #% description: Name of an existing space time dataset
  23. #%end
  24. #%option
  25. #% key: type
  26. #% type: string
  27. #% description: Type of the dataset, default is strds (space time raster dataset)
  28. #% required: no
  29. #% guidependency: input
  30. #% guisection: Required
  31. #% options: strds, str3ds, stvds
  32. #% answer: strds
  33. #%end
  34. #%option
  35. #% key: granularity
  36. #% type: string
  37. #% label: Shift granularity
  38. #% description: Format absolute time: "x years, x months, x weeks, x days, x hours, x minutes, x seconds", relative time is of type integer
  39. #% required: yes
  40. #% multiple: no
  41. #%end
  42. import grass.script as grass
  43. import grass.temporal as tgis
  44. ############################################################################
  45. def main():
  46. name = options["input"]
  47. type = options["type"]
  48. gran = options["granularity"]
  49. # Make sure the temporal database exists
  50. tgis.init()
  51. dbif = tgis.SQLDatabaseInterfaceConnection()
  52. dbif.connect()
  53. stds = tgis.open_old_stds(name, type, dbif)
  54. check = stds.shift(gran=gran, dbif=dbif)
  55. if check == False:
  56. dbif.close()
  57. grass.fatal(_("Unable to temporally shift the space time %s dataset <%s>") % \
  58. (stds.get_new_map_instance(None).get_type(), id))
  59. stds.update_command_string(dbif=dbif)
  60. dbif.close()
  61. if __name__ == "__main__":
  62. options, flags = grass.parser()
  63. main()