t.shift.py 1.9 KB

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