#!/usr/bin/env python3
# %module
# % description: Ukazka Python skriptu pro GRASS GIS
# %end
# %option G_OPT_R_INPUT
# % key: elevation
# % description: Vstupni DEM
# % required: yes
# % answer: eu_dem_v11_E40N10
# %end
# %option G_OPT_V_INPUT
# % key: aoi
# % description: Vstupni AOI
# % required: yes
# % answer: NUTS_RG_20M_2021_3035
# %end
# %option G_OPT_F_INPUT
# % key: aoi_where
# % description: Vstupni AOI podminka
# % required: yes
# % answer: LEVL_CODE=3 and CNTR_CODE='IT' and NUTS_NAME='Cosenza'
# %end
# %option G_OPT_F_INPUT
# % key: clc
# % description: Vstupni CLC
# % required: yes
# % answer: S:\K155\Public\155UZPR\01\U2018_CLC2018_V2020_20u1.gpkg
# %end
# %option G_OPT_F_INPUT
# % key: lucas
# % description: Vstupni LUCAS body
# % required: yes
# % answer: S:\K155\Public\155UZPR\01\lucas_points_it.gpkg
# %end
# %option G_OPT_V_OUTPUT
# % key: output
# % description: Vysledna vrsta
# % answer: vysledek
# %end
import os
from grass.script import parser
from grass.pygrass.modules import Module
def main(options, flags):
Module("v.extract",
input=options["aoi"],
where=options["aoi_where"],
output="region")
Module("g.region",
vector="region",
align=options["elevation"])
Module("r.mapcalc",
expression=f"aoi = if({options['elevation']} > 1000, 1, null())")
Module("r.to.vect",
flags='v',
input="aoi",
output="aoi",
type="area")
Module("v.import",
input=options["clc"],
layer="U2018_CLC2018_V2020_20u1",
output="clc",
extent="region")
Module("v.clip",
input="clc",
clip="aoi",
output="clc_aoi")
Module("v.import",
input=options["lucas"],
output="lucas_points",
extent="region")
Module("v.clip",
input="lucas_points",
clip="aoi",
output="lucas_aoi")
Module("v.extract",
input="clc_aoi",
where="Code_18 > 500",
output="clc_aoi_water")
Module("v.extract",
input="lucas_aoi",
where="lc1 like 'G%'",
output="lucas_aoi_water")
Module("v.buffer",
input="clc_aoi_water",
output="clc_aoi_water_100m",
distance=100)
Module("v.select",
ainput="lucas_aoi_water",
binput="clc_aoi_water_100m",
output=options["output"],
operator="within")
if __name__ == "__main__":
options, flags = parser()
os.environ["GRASS_OVERWRITE"] = "1"
main(options, flags)