t.vect.algebra.py 2.5 KB

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