diff --git a/large_image/tilesource/base.py b/large_image/tilesource/base.py index 6717234d6..81ae459f1 100644 --- a/large_image/tilesource/base.py +++ b/large_image/tilesource/base.py @@ -2771,7 +2771,7 @@ def getPixel(self, includeTileRecord=False, **kwargs): pixel.update(dict(zip(img.mode.lower(), img.load()[0, 0]))) else: pixel.update(dict(zip([img.mode.lower()], [img.load()[0, 0]]))) - return pixel + return JSONDict(pixel) @property def frames(self): diff --git a/sources/gdal/large_image_source_gdal/__init__.py b/sources/gdal/large_image_source_gdal/__init__.py index 5730990b8..93fff4be1 100644 --- a/sources/gdal/large_image_source_gdal/__init__.py +++ b/sources/gdal/large_image_source_gdal/__init__.py @@ -513,7 +513,7 @@ def getBandInformation(self, statistics=True, dataset=None, **kwargs): cache = not dataset if not dataset: dataset = self.dataset - infoSet = {} + infoSet = JSONDict({}) for i in range(dataset.RasterCount): band = dataset.GetRasterBand(i + 1) info = {} @@ -609,7 +609,7 @@ def getInternalMetadata(self, **kwargs): :returns: a dictionary of data or None. """ - result = {} + result = JSONDict({}) with self._getDatasetLock: result['driverShortName'] = self.dataset.GetDriver().ShortName result['driverLongName'] = self.dataset.GetDriver().LongName diff --git a/sources/rasterio/large_image_source_rasterio/__init__.py b/sources/rasterio/large_image_source_rasterio/__init__.py index f04812635..236a46e44 100644 --- a/sources/rasterio/large_image_source_rasterio/__init__.py +++ b/sources/rasterio/large_image_source_rasterio/__init__.py @@ -41,6 +41,7 @@ from large_image.tilesource.geo import (GDALBaseFileTileSource, ProjUnitsAcrossLevel0, ProjUnitsAcrossLevel0_MaxSize) +from large_image.tilesource.utilities import JSONDict try: from importlib.metadata import PackageNotFoundError @@ -448,7 +449,7 @@ def getBandInformation(self, statistics=True, dataset=None, **kwargs): dataset = dataset or self.dataset # loop in the bands to get the indicidative stats (bands are 1 indexed) - infoSet = {} + infoSet = JSONDict({}) for i in dataset.indexes: # 1 indexed # get the stats @@ -490,7 +491,7 @@ def getMetadata(self): has_gcps = len(self.dataset.gcps[0]) != 0 and self.dataset.gcps[1] has_affine = self.dataset.transform - metadata = { + metadata = JSONDict({ 'geospatial': bool(has_projection or has_gcps or has_affine), 'levels': self.levels, 'sizeX': self.sizeX, @@ -503,7 +504,7 @@ def getMetadata(self): 'bounds': self.getBounds(self.projection), 'sourceBounds': self.getBounds(), 'bands': self.getBandInformation(), - } + }) # magnification is computed elswhere metadata.update(self.getNativeMagnification()) @@ -518,7 +519,7 @@ def getInternalMetadata(self, **kwargs): :returns: a dictionary of data or None. """ - result = {} + result = JSONDict({}) with self._getDatasetLock: result['driverShortName'] = self.dataset.driver result['driverLongName'] = self.dataset.driver diff --git a/test/source_geo_base.py b/test/source_geo_base.py index f2f33485b..17fc49a1c 100644 --- a/test/source_geo_base.py +++ b/test/source_geo_base.py @@ -218,6 +218,9 @@ def testPixel(self): assert pixel == { 'r': 94, 'g': 98, 'b': 99, 'a': 255, 'bands': {1: 77.0, 2: 82.0, 3: 84.0}} + # Make sure pixel return value is JSON serializable + assert json.dumps(pixel) + def testSourceErrors(self): testDir = os.path.dirname(os.path.realpath(__file__)) imagePath = os.path.join(testDir, 'test_files', 'rgb_geotiff.tiff')