Skip to content

Commit

Permalink
Merge pull request #1199 from girder/actual-levels-geo
Browse files Browse the repository at this point in the history
Add populated levels information to geospatial sources
  • Loading branch information
manthey authored Jun 8, 2023
2 parents 150ffd3 + aa35ca2 commit 4e03f88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions sources/rasterio/large_image_source_rasterio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4e03f88

Please sign in to comment.