From aa35ca227b2e391e433c80c80455dedbc0cca4e8 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 8 Jun 2023 10:55:21 -0400 Subject: [PATCH] Add populated levels information to geospatial sources --- CHANGELOG.md | 2 +- sources/gdal/large_image_source_gdal/__init__.py | 8 ++++++++ .../rasterio/large_image_source_rasterio/__init__.py | 12 ++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ae960b0d..72b195fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Improvements - Better DICOM multi-level detection ([#1196](../../pull/1196)) -- Added an internal field to report populated tile levels in some sources ([#1197](../../pull/1197)) +- Added an internal field to report populated tile levels in some sources ([#1197](../../pull/1197), [#1199](../../pull/1199)) ### Changes - Change how extensions and fallback priorities interact ([#1192](../../pull/1192)) diff --git a/sources/gdal/large_image_source_gdal/__init__.py b/sources/gdal/large_image_source_gdal/__init__.py index 93fff4be1..3d412e697 100644 --- a/sources/gdal/large_image_source_gdal/__init__.py +++ b/sources/gdal/large_image_source_gdal/__init__.py @@ -136,6 +136,7 @@ def __init__(self, path, projection=None, unitsPerPixel=None, **kwargs): self._unitsPerPixel = unitsPerPixel if self.projection: self._initWithProjection(unitsPerPixel) + self._getPopulatedLevels() self._getTileLock = threading.Lock() self._setDefaultStyle() @@ -158,6 +159,13 @@ def _checkNetCDF(self): raise TileSourceError('netCDF file will not be read via GDAL source') return False + def _getPopulatedLevels(self): + try: + with self._getDatasetLock: + self._populatedLevels = 1 + self.dataset.GetRasterBand(1).GetOverviewCount() + except Exception: + pass + def _scanForMinMax(self, dtype, frame=None, analysisSize=1024, onlyMinMax=True): frame = frame or 0 bandInfo = self.getBandInformation() diff --git a/sources/rasterio/large_image_source_rasterio/__init__.py b/sources/rasterio/large_image_source_rasterio/__init__.py index 236a46e44..1160f4955 100644 --- a/sources/rasterio/large_image_source_rasterio/__init__.py +++ b/sources/rasterio/large_image_source_rasterio/__init__.py @@ -152,9 +152,17 @@ def __init__(self, path, projection=None, unitsPerPixel=None, **kwargs): self._unitsPerPixel = unitsPerPixel self.projection is None or self._initWithProjection(unitsPerPixel) + self._getPopulatedLevels() self._getTileLock = threading.Lock() self._setDefaultStyle() + def _getPopulatedLevels(self): + try: + with self._getDatasetLock: + self._populatedLevels = 1 + len(self.dataset.overviews(1)) + except Exception: + pass + def _scanForMinMax(self, dtype, frame=0, analysisSize=1024, onlyMinMax=True): """Update the band range of the data type to the end of the range list. @@ -240,8 +248,8 @@ def _initWithProjection(self, unitsPerPixel=None): # If unitsPerPixel is not specified, the horizontal distance # between -180,0 and +180,0 is used. Some projections (such as # stereographic) will fail in this case; they must have a unitsPerPixel specified. - east, _ = warp.transform(srcCrs, dstCrs, [-180,], [0,]) - west, _ = warp.transform(srcCrs, dstCrs, [180,], [0,]) + east, _ = warp.transform(srcCrs, dstCrs, [-180], [0]) + west, _ = warp.transform(srcCrs, dstCrs, [180], [0]) self.unitsAcrossLevel0 = abs(east[0] - west[0]) if not self.unitsAcrossLevel0: raise TileSourceError(