t.select.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.select
  6. # AUTHOR(S): Thomas Leppelt, Soeren Gebbert
  7. #
  8. # PURPOSE: Select maps from space time datasets by topological relationships to
  9. # other space time datasets using temporal algebra.
  10. # COPYRIGHT: (C) 2011-2017 by the GRASS Development Team
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. #############################################################################
  23. #%module
  24. #% description: Select maps from space time datasets by topological relationships to other space time datasets using temporal algebra.
  25. #% keyword: temporal
  26. #% keyword: metadata
  27. #% keyword: time
  28. #%end
  29. #%option G_OPT_STDS_TYPE
  30. #% guidependency: input
  31. #% guisection: Required
  32. #%end
  33. #%option
  34. #% key: expression
  35. #% type: string
  36. #% description: The temporal mapcalc expression
  37. #% key_desc: expression
  38. #% required : yes
  39. #%end
  40. #%flag
  41. #% key: s
  42. #% description: Check the spatial topology of temporally related maps and select only spatially related maps
  43. #%end
  44. #%flag
  45. #% key: d
  46. #% description: Perform a dry run, compute all dependencies and module calls but don't run them
  47. #%end
  48. import grass.script as grass
  49. import sys
  50. ############################################################################
  51. def main():
  52. # lazy imports
  53. import grass.temporal as tgis
  54. expression = options['expression']
  55. spatial = flags["s"]
  56. dry_run = flags["d"]
  57. stdstype = options["type"]
  58. # Check for PLY istallation
  59. try:
  60. import ply.lex as lex
  61. import ply.yacc as yacc
  62. except:
  63. grass.fatal(_("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules."))
  64. tgis.init(True)
  65. p = tgis.TemporalAlgebraParser(run=True, debug=False, spatial=spatial, dry_run=dry_run)
  66. pc = p.parse(expression, stdstype, overwrite=grass.overwrite())
  67. if dry_run is True:
  68. import pprint
  69. pprint.pprint(pc)
  70. if __name__ == "__main__":
  71. options, flags = grass.parser()
  72. sys.exit(main())