Skip to content

Commit

Permalink
GUI changes for import module (#69)
Browse files Browse the repository at this point in the history
* remove default answers for type

* change dtm_resolution from multiple to single

* split parameter dtm_file into dtm_file and dtm_dir

* add info about automatic dtm download

* spell Open.NRW correctly, add rule for dtm_dir and dtm_resolution

* black
  • Loading branch information
juleshaas authored Mar 21, 2024
1 parent dece3e2 commit 420855c
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions grass-gis-addons/m.import.rvr/m.import.rvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# % multiple: yes
# % label: Type of processing for which the data should be imported
# % options: gebaeudedetektion,dachbegruenung,einzelbaumerkennung
# % answer: gebaeudedetektion,dachbegruenung,einzelbaumerkennung
# % guisection: General input
# %end

Expand Down Expand Up @@ -73,33 +72,42 @@
# % guisection: General input
# %end

# %option
# % key: dtm_file
# %option G_OPT_M_DIR
# % key: dtm_dir
# % required: no
# % multiple: no
# % label: Raster file or directory where XYZ files of the digital terrain model (DTM)
# % label: Directory where XYZ files of the digital terrain model (DTM) are stored (leave empty to automatically download DTM from Open.NRW)
# % description: The DTM is required for the processing of gebaeudedetektion, dachbegruenung and einzelbaumerkennung
# % guisection: General input
# %end

# %option G_OPT_F_INPUT
# % key: dtm_tindex
# % key: dtm_file
# % required: no
# % multiple: no
# % label: Name of the DTM tindex which should be used or created (optional)
# % description: If this is set the tindex needs a column <location> with the absolute path to the DTM files
# % label: Raster file (e.g. TIF) of the digital terrain model (DTM) (leave empty to automatically download DTM from Open.NRW)
# % description: The DTM is required for the processing of gebaeudedetektion, dachbegruenung and einzelbaumerkennung
# % guisection: General input
# %end

# %option
# % key: dtm_resolution
# % type: double
# % required: no
# % multiple: yes
# % multiple: no
# % label: Resolution of the source DTM XYZ file
# % guisection: General input
# %end

# %option G_OPT_F_INPUT
# % key: dtm_tindex
# % required: no
# % multiple: no
# % label: Name of the DTM tindex which should be used or created (optional)
# % description: If this is set the tindex needs a column <location> with the absolute path to the DTM files
# % guisection: General input
# %end

# %option G_OPT_F_INPUT
# % key: fnk_file
# % required: no
Expand Down Expand Up @@ -190,10 +198,15 @@

# %flag
# % key: b
# % label: Download buildings for reference buildings or building outlines from openNRW if files are not set
# % label: Download buildings for reference buildings or building outlines from Open.NRW if files are not set
# % guisection: General input
# %end

# %rules
# % exclusive: dtm_dir, dtm_file
# % requires: dtm_dir, dtm_resolution
# %end

import atexit
import os
import psutil
Expand Down Expand Up @@ -253,8 +266,8 @@
"dop": ([0.5], "output,ndvi", True, "dop_dir", "rasterdir"),
"ndvi": ([0.5], "output", True, "", "dop_ndvi_scaled"),
"dsm": ([0.5], "ndsm", True, "dsm_dir", "lazdir"),
"ndsm": ([0.5], "output", True, "", "ndsm"),
"dtm": ([0.5], "ndsm", False, "dtm_file", "rasterORxyz"),
"ndsm": ([0.5], "output", True, "", "ndsm"),
},
"einzelbaumerkennung": {
# vector
Expand All @@ -268,8 +281,8 @@
# raster
"top": ([0.2], "output,ndvi", True, "top_dir", "rasterdir"),
"ndvi": ([0.2], "output", True, "", "top_ndvi_scaled"),
"dtm": ([0.2], "ndsm", False, "dtm_file", "rasterORxyz"),
"dsm": ([0.2], "ndsm", True, "dsm_dir", "lazdir"),
"dtm": ([0.2], "ndsm", False, "dtm_file", "rasterORxyz"),
"ndsm": ([0.2], "output", True, "", "ndsm"),
},
}
Expand Down Expand Up @@ -498,7 +511,7 @@ def compute_ndsm(dsm, output_name, dtm=None):
dsm (str): the name of the digital surface model (DSM) raster
output_name (str): the name for the output nDSM raster
dtm (str): the name of the digital terrain model (DTM) raster; if not
set the DTM is downloaded from openNRW
set the DTM is downloaded from Open.NRW
"""
grass.message(f"Computing nDSM {output_name} ...")
# g.region
Expand Down Expand Up @@ -593,7 +606,7 @@ def check_data(ptype, data, val):
_(
f"For the processing type <{ptype}> the option <{val[3]}> "
f"has to be set or the data can be downloaded from "
"openNRW for this set the flag '-b'. Please set the "
"Open.NRW for this set the flag '-b'. Please set the "
f"option <{val[3]}> or the flag '-b'."
)
)
Expand All @@ -603,26 +616,15 @@ def check_data(ptype, data, val):
"https://github.com/mundialis/v.alkis.buildings.import",
)
grass.message(
_(f"The data <{data}> will be downloaded from openNRW.")
_(f"The data <{data}> will be downloaded from Open.NRW.")
)
else:
grass.message(_(f"The {data} data are not used."))
elif data == "dtm":
if options[val[3]]:
check_data_exists(options[val[3]], val[3])
if (
options[val[3]].endswith(".xyz")
or os.path.isdir(options[val[3]])
and not options["dtm_resolution"]
):
grass.fatal(
_(
f"The <{data}> XYZ file is used but no <dtm_resolution> "
"is set."
)
)
else:
grass.message(_(f"The {data} data are downloaded from OpenNRW."))
grass.message(_(f"The {data} data are downloaded from Open.NRW."))
elif val[2] and val[3] == "":
pass
elif "," in val[3]:
Expand Down Expand Up @@ -909,15 +911,15 @@ def import_vector(file, output_name, extent="region", area=None, column=None):

@decorator_check_grass_data("vector")
def import_buildings_from_opennrw(output_name, area):
"""Download buildings from openNRW and import them
"""Download buildings from Open.NRW and import them
Args:
output_name (str): the name for the output buildings vector map
area (str): The area vector map
"""
grass.message(
_(
f"Downloading and importing {output_name} building data "
"from OpenNRW ..."
"from Open.NRW ..."
)
)
buildings = grass.tempname(12)
Expand All @@ -938,7 +940,9 @@ def import_buildings_from_opennrw(output_name, area):
quiet=True,
)
grass.message(
_(f"The building vector map from openNRW <{output_name}> is imported.")
_(
f"The building vector map from Open.NRW <{output_name}> is imported."
)
)


Expand Down Expand Up @@ -1559,6 +1563,9 @@ def main():
global rm_regions, nprocs

types = options["type"].split(",")
if options["dtm_dir"]:
options["dtm_file"] = options["dtm_dir"]

nprocs = set_nprocs(int(options["nprocs"]))

if nprocs > 1:
Expand Down

0 comments on commit 420855c

Please sign in to comment.