1#!/usr/local/bin/python3.8 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 24#%module 25#% description: Select maps from space time datasets by topological relationships to other space time datasets using temporal algebra. 26#% keyword: temporal 27#% keyword: metadata 28#% keyword: time 29#%end 30 31#%option G_OPT_STDS_TYPE 32#% guidependency: input 33#% guisection: Required 34#%end 35 36#%option 37#% key: expression 38#% type: string 39#% description: The temporal mapcalc expression 40#% key_desc: expression 41#% required : yes 42#%end 43 44#%flag 45#% key: s 46#% description: Check the spatial topology of temporally related maps and select only spatially related maps 47#%end 48 49#%flag 50#% key: d 51#% description: Perform a dry run, compute all dependencies and module calls but don't run them 52#%end 53 54 55import grass.script as grass 56import sys 57 58############################################################################ 59 60def main(): 61 # lazy imports 62 import grass.temporal as tgis 63 64 expression = options['expression'] 65 spatial = flags["s"] 66 dry_run = flags["d"] 67 stdstype = options["type"] 68 69 # Check for PLY istallation 70 try: 71 import ply.lex as lex 72 import ply.yacc as yacc 73 except: 74 grass.fatal(_("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules.")) 75 76 tgis.init(True) 77 p = tgis.TemporalAlgebraParser(run=True, debug=False, spatial=spatial, dry_run=dry_run) 78 pc = p.parse(expression, stdstype, overwrite=grass.overwrite()) 79 80 if dry_run is True: 81 import pprint 82 pprint.pprint(pc) 83 84 85if __name__ == "__main__": 86 options, flags = grass.parser() 87 sys.exit(main()) 88 89 90 91 92