t.select.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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-2014 by the GRASS Development Team
  11. #
  12. # This program is free software under the GNU General Public
  13. # License (version 2). Read the file COPYING that comes with GRASS
  14. # for details.
  15. #
  16. #############################################################################
  17. #%module
  18. #% description: Select maps from space time datasets by topological relationships to other space time datasets using temporal algebra.
  19. #% keyword: temporal
  20. #% keyword: metadata
  21. #% keyword: time
  22. #%end
  23. #%option G_OPT_STDS_TYPE
  24. #% guidependency: input
  25. #% guisection: Required
  26. #%end
  27. #%option
  28. #% key: expression
  29. #% type: string
  30. #% description: The temporal mapcalc expression
  31. #% key_desc: expression
  32. #% required : yes
  33. #%end
  34. #%flag
  35. #% key: s
  36. #% description: Check the spatial topology of temporally related maps and select only spatially related maps
  37. #%end
  38. #%flag
  39. #% key: d
  40. #% description: Perform a dry run, compute all dependencies and module calls but don't run them
  41. #%end
  42. import grass.script as grass
  43. import sys
  44. ############################################################################
  45. def main():
  46. # lazy imports
  47. import grass.temporal as tgis
  48. expression = options['expression']
  49. spatial = flags["s"]
  50. dry_run = flags["d"]
  51. stdstype = options["type"]
  52. # Check for PLY istallation
  53. try:
  54. import ply.lex as lex
  55. import ply.yacc as yacc
  56. except:
  57. grass.fatal(_("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules."))
  58. tgis.init(True)
  59. p = tgis.TemporalAlgebraParser(run=True, debug=False, spatial=spatial, dry_run=dry_run)
  60. pc = p.parse(expression, stdstype, overwrite=grass.overwrite())
  61. if dry_run is True:
  62. import pprint
  63. pprint.pprint(pc)
  64. if __name__ == "__main__":
  65. options, flags = grass.parser()
  66. sys.exit(main())