t.shift.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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: Temporally shift 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. #% description: Shift granularity, format absolute time "x years, x months, x weeks, x days, x hours, x minutes, x seconds" or an integer value for relative time
  38. #% required: yes
  39. #% multiple: no
  40. #%end
  41. import grass.script as grass
  42. import grass.temporal as tgis
  43. ############################################################################
  44. def main():
  45. name = options["input"]
  46. type = options["type"]
  47. gran = options["granularity"]
  48. # Make sure the temporal database exists
  49. tgis.init()
  50. dbif = tgis.SQLDatabaseInterfaceConnection()
  51. dbif.connect()
  52. stds = tgis.open_old_space_time_dataset(name, type, dbif)
  53. check = stds.shift(gran=gran, dbif=dbif)
  54. if check == False:
  55. dbif.close()
  56. grass.fatal(_("Unable to temporally shift the space time %s dataset <%s>") % \
  57. (stds.get_new_map_instance(None).get_type(), id))
  58. stds.update_command_string(dbif=dbif)
  59. dbif.close()
  60. if __name__ == "__main__":
  61. options, flags = grass.parser()
  62. main()