t.shift.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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-2014 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 G_OPT_T_TYPE
  25. #% guidependency: input
  26. #% guisection: Required
  27. #%end
  28. #%option
  29. #% key: granularity
  30. #% type: string
  31. #% label: Shift granularity
  32. #% description: Format absolute time: "x years, x months, x weeks, x days, x hours, x minutes, x seconds", relative time is of type integer
  33. #% required: yes
  34. #% multiple: no
  35. #%end
  36. import grass.script as grass
  37. import grass.temporal as tgis
  38. ############################################################################
  39. def main():
  40. name = options["input"]
  41. type = options["type"]
  42. gran = options["granularity"]
  43. # Make sure the temporal database exists
  44. tgis.init()
  45. dbif = tgis.SQLDatabaseInterfaceConnection()
  46. dbif.connect()
  47. stds = tgis.open_old_stds(name, type, dbif)
  48. check = stds.shift(gran=gran, dbif=dbif)
  49. if check == False:
  50. dbif.close()
  51. grass.fatal(_("Unable to temporally shift the space time %s dataset <%s>") % \
  52. (stds.get_new_map_instance(None).get_type(), id))
  53. stds.update_command_string(dbif=dbif)
  54. dbif.close()
  55. if __name__ == "__main__":
  56. options, flags = grass.parser()
  57. main()