Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.buildvrt.gdal: silence GDAL warning and fix GDAL-GRASS driver check #1216

Open
wants to merge 1 commit into
base: grass8
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/raster/r.buildvrt.gdal/r.buildvrt.gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@


def get_raster_gdalpath(
map_name, check_linked=True, has_grasadriver=False, gis_env=None
map_name, check_linked=True, has_grassdriver=False, gis_env=None
):
"""Get the GDAL-readable path to a GRASS GIS raster map

Expand All @@ -102,7 +102,7 @@ def get_raster_gdalpath(
return str(gdal_path)

# Get native GRASS GIS format header
if not has_grasadriver:
if not has_grassdriver:
gs.fatal(
_(
"The GDAL-GRASS GIS driver is unavailable. "
Expand All @@ -127,6 +127,8 @@ def main():
global gdal
try:
from osgeo import gdal

gdal.UseExceptions()
except ImportError:
gs.fatal(
_(
Expand All @@ -153,7 +155,10 @@ def main():
if len(inputs) < 1:
gs.fatal(_("At least one input map is required".format(inputs[0])))

inputs = [get_raster_gdalpath(raster_map, gis_env=gisenv) for raster_map in inputs]
inputs = [
get_raster_gdalpath(raster_map, has_grassdriver=has_grassdriver, gis_env=gisenv)
for raster_map in inputs
]

# Get output
output = options["output"]
Expand All @@ -170,7 +175,14 @@ def main():
# Create GDAL VRT
vrt_path = str(vrt_dir / f"{output}.vrt")
gs.verbose(_("Creating GDAL VRT '{}'.").format(vrt_path))
gdal.BuildVRT(vrt_path, inputs)
try:
gdal.BuildVRT(vrt_path, inputs)
except OSError:
gs.fatal(
_("Failed to build VRT {vrt} with inputs <{in_files}>").format(
vrt=vrt_path, in_file=", ".join(inputs)
)
)

# Import (link) GDAL VRT
gs.run_command(
Expand Down