Skip to content

Commit

Permalink
GeoTIFF: handle case when file is not georeferenced
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Jan 27, 2025
1 parent f763e83 commit 8f939e4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions sourcespec/ssp_plot_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,21 @@ def _add_geotiff(config, ax):
'Basemap will not be plotted.')
return
# pylint: disable=import-outside-toplevel
from rasterio.errors import RasterioError
try:
tif_raster, tif_bbox = _read_geotiff(tif_file, grayscale)
except (RasterioError, OSError) as msg:
logger.warning(
f'Error reading GeoTIFF file "{tif_file}": {msg}. '
'Basemap will not be plotted.')
return
from rasterio.errors import RasterioError, NotGeoreferencedWarning
with warnings.catch_warnings():
warnings.simplefilter('error', NotGeoreferencedWarning)
try:
tif_raster, tif_bbox = _read_geotiff(tif_file, grayscale)
except (RasterioError, OSError) as msg:
logger.warning(
f'Error reading GeoTIFF file "{tif_file}": {msg}. '
'Basemap will not be plotted.')
return
except NotGeoreferencedWarning:
logger.warning(
f'GeoTIFF file "{tif_file}" is not georeferenced. '
'Basemap will not be plotted.')
return
# Plot the raster
if grayscale:
ax.imshow(
Expand Down

0 comments on commit 8f939e4

Please sign in to comment.