grass
grass copied to clipboard
Graphical modeler: export variables to Python
Steps to reproduce
- Add variable(s) into model
- Export to Python
Sample model: 06_grass_chm_v3.zip
Current behaviour
No variables exported (as UI options). On the other hand variables are used in command statements (see last row in example below):
#!/usr/bin/env python3
#
##############################################################################
#
# MODULE: model
#
# AUTHOR(S): martin
#
# PURPOSE: Script generated by wxGUI Graphical Modeler.
#
# DATE: Sat May 11 22:38:15 2024
#
##############################################################################
# %module
# % description: Script generated by wxGUI Graphical Modeler.
# %end
import sys
import os
import atexit
from grass.script import parser
from grass.pygrass.modules import Module
def cleanup():
pass
def main(options, flags):
Module("r.in.pdal",
flags='eo',
overwrite=True,
input="%path/dmr5g/%tile.laz",
New behaviour
Variables exported as UI options and used in the Python code correctly:
#!/usr/bin/env python3
#
##############################################################################
#
# MODULE: model
#
# AUTHOR(S): martin
#
# PURPOSE: Script generated by wxGUI Graphical Modeler.
#
# DATE: Sat May 11 22:43:48 2024
#
##############################################################################
# %module
# % description: Script generated by wxGUI Graphical Modeler.
# %end
# %option G_OPT_M_DIR
# % key: path
# % description: Path to input LAZ data
# % required: yes
# % answer: /home/martin/geodata/vyuka/155FGIS/06
# %end
# %option
# % key: tile
# % description: Tile name
# % required: yes
# % type: string
# % answer: KRAV59
# %end
# %option
# % key: resolution
# % description: Target resolution
# % required: yes
# % type: integer
# % answer: 5
# %end
# %option
# % key: fill
# % description: Fill distance (in pixels)
# % required: yes
# % type: integer
# % answer: 10
# %end
import sys
import os
import atexit
from grass.script import parser
from grass.pygrass.modules import Module
def cleanup():
pass
def main(options, flags):
Module("r.in.pdal",
flags='eo',
overwrite=True,
input=f"{options['path']}/dmr5g/{options['tile']}.laz",