t.shift.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python3
  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-2017 by the GRASS Development Team
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. #############################################################################
  22. #%module
  23. #% description: Shifts temporally the maps of a space time dataset.
  24. #% keyword: temporal
  25. #% keyword: time management
  26. #% keyword: shift
  27. #% keyword: time
  28. #%end
  29. #%option G_OPT_STDS_INPUT
  30. #% description: Name of an existing space time dataset
  31. #%end
  32. #%option G_OPT_STDS_TYPE
  33. #% guidependency: input
  34. #% guisection: Required
  35. #%end
  36. #%option
  37. #% key: granularity
  38. #% type: string
  39. #% label: Shift granularity
  40. #% description: Format absolute time: "x years, x months, x weeks, x days, x hours, x minutes, x seconds", relative time is of type integer
  41. #% required: yes
  42. #% multiple: no
  43. #%end
  44. import grass.script as grass
  45. ############################################################################
  46. def main():
  47. # lazy imports
  48. import grass.temporal as tgis
  49. name = options["input"]
  50. type = options["type"]
  51. gran = options["granularity"]
  52. # Make sure the temporal database exists
  53. tgis.init()
  54. dbif = tgis.SQLDatabaseInterfaceConnection()
  55. dbif.connect()
  56. stds = tgis.open_old_stds(name, type, dbif)
  57. check = stds.shift(gran=gran, dbif=dbif)
  58. if check is False:
  59. dbif.close()
  60. grass.fatal(_("Unable to temporally shift the space time %s dataset <%s>") % \
  61. (stds.get_new_map_instance(None).get_type(), id))
  62. stds.update_command_string(dbif=dbif)
  63. dbif.close()
  64. if __name__ == "__main__":
  65. options, flags = grass.parser()
  66. main()