Skip to content

Commit

Permalink
silence GDAL warning and fix GDAL-GRASS driver (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninsbl authored Oct 16, 2024
1 parent 3f8250a commit 261b8fa
Showing 1 changed file with 16 additions and 4 deletions.
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

0 comments on commit 261b8fa

Please sign in to comment.