Skip to content

Commit

Permalink
Allow GDAL to read non-geospatial files.
Browse files Browse the repository at this point in the history
This will be lower priority than non-geospatial sources.

Harden the openjpeg tilesource to not fail when trying to read a GDAL
test file.
  • Loading branch information
manthey committed Sep 20, 2021
1 parent 0e49546 commit cbac7d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion girder/test_girder/test_tiles_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def testTilesFromGreyscale(boundServer, admin, fsAssetstore, girderWorker):
file = utilities.uploadTestFile('grey10kx5k.tif', admin, fsAssetstore)
itemId = str(file['itemId'])
fileId = str(file['_id'])
tileMetadata = _postTileViaHttp(boundServer, admin, itemId, fileId)
boundServer.request(path='/item/%s/tiles' % itemId, method='DELETE', user=admin)
tileMetadata = _postTileViaHttp(boundServer, admin, itemId, fileId, data={'force': True})
assert tileMetadata['tileWidth'] == 256
assert tileMetadata['tileHeight'] == 256
assert tileMetadata['sizeX'] == 10000
Expand Down
6 changes: 4 additions & 2 deletions sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ def __init__(self, path, projection=None, unitsPerPixel=None, **kwargs):
scale = self.getPixelSizeInMeters()
except RuntimeError:
raise TileSourceException('File cannot be opened via GDAL.')
if not scale and not is_netcdf:
if (self.projection or self._getDriver() in {
'PNG',
}) and not scale and not is_netcdf:
raise TileSourceException(
'File does not have a projected scale, so will not be '
'opened via GDAL.')
'opened via GDAL with a projection.')
self.sourceLevels = self.levels = int(max(0, math.ceil(max(
math.log(float(self.sizeX) / self.tileWidth),
math.log(float(self.sizeY) / self.tileHeight)) / math.log(2))) + 1)
Expand Down
3 changes: 2 additions & 1 deletion sources/openjpeg/large_image_source_openjpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import math
import multiprocessing
import queue
import struct
import warnings
from xml.etree import ElementTree

Expand Down Expand Up @@ -90,7 +91,7 @@ def __init__(self, path, **kwargs):
self._pixelInfo = {}
try:
self._openjpeg = glymur.Jp2k(largeImagePath)
except glymur.jp2box.InvalidJp2kError:
except (glymur.jp2box.InvalidJp2kError, struct.error):
raise TileSourceException('File cannot be opened via Glymur and OpenJPEG.')
glymur.set_option('lib.num_threads', multiprocessing.cpu_count())
self._openjpegHandles = queue.LifoQueue()
Expand Down

0 comments on commit cbac7d4

Please sign in to comment.