diff --git a/large_image/tilesource/__init__.py b/large_image/tilesource/__init__.py index 6a3a43549..1f29a636d 100644 --- a/large_image/tilesource/__init__.py +++ b/large_image/tilesource/__init__.py @@ -31,14 +31,15 @@ def isGeospatial(path): ds = gdal.Open(path, gdalconst.GA_ReadOnly) except Exception: return False - if ds.GetGCPs() and ds.GetGCPProjection(): - return True - if ds.GetProjection(): - return True - if ds.GetGeoTransform(can_return_null=True): - return True - if ds.GetDriver().ShortName in {'NITF', 'netCDF'}: - return True + if ds: + if ds.GetGCPs() and ds.GetGCPProjection(): + return True + if ds.GetProjection(): + return True + if ds.GetGeoTransform(can_return_null=True): + return True + if ds.GetDriver().ShortName in {'NITF', 'netCDF'}: + return True return False @@ -113,6 +114,8 @@ def getTileSourceFromDict(availableSources, pathOrUri, *args, **kwargs): sourceName = getSourceNameFromDict(availableSources, pathOrUri, *args, **kwargs) if sourceName: return availableSources[sourceName](pathOrUri, *args, **kwargs) + if not os.path.exists(pathOrUri) and '://' not in pathOrUri: + raise TileSourceFileNotFoundError(pathOrUri) raise TileSourceError('No available tilesource for %s' % pathOrUri) diff --git a/test/test_source_base.py b/test/test_source_base.py index d1693ccc0..c9025297b 100644 --- a/test/test_source_base.py +++ b/test/test_source_base.py @@ -77,6 +77,13 @@ def testSourcesFileNotFound(source): large_image.tilesource.AvailableTileSources[source]('nosuchfile.ext') +def testBaseFileNotFound(source): + with pytest.raises(large_image.exceptions.TileSourceFileNotFoundError): + large_image.open('nosuchfile') + with pytest.raises(large_image.exceptions.TileSourceFileNotFoundError): + large_image.open('nosuchfile.ext') + + @pytest.mark.parametrize('filename', registry) @pytest.mark.parametrize('source', SourceAndFiles) def testSourcesCanRead(source, filename):