t.shift.py 1.9 KB

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