Handle NaN nodata
This commit is contained in:
@@ -476,8 +476,7 @@ class GeoTIFFSource extends DataTile {
|
|||||||
const image = images[imageIndex];
|
const image = images[imageIndex];
|
||||||
const nodataValue = image.getGDALNoData();
|
const nodataValue = image.getGDALNoData();
|
||||||
metadata[sourceIndex][imageIndex] = image.getGDALMetadata(0);
|
metadata[sourceIndex][imageIndex] = image.getGDALMetadata(0);
|
||||||
nodataValues[sourceIndex][imageIndex] =
|
nodataValues[sourceIndex][imageIndex] = nodataValue;
|
||||||
nodataValue === null ? NaN : nodataValue;
|
|
||||||
|
|
||||||
const wantedSamples = this.sourceInfo_[sourceIndex].bands;
|
const wantedSamples = this.sourceInfo_[sourceIndex].bands;
|
||||||
samplesPerPixel[sourceIndex] = wantedSamples
|
samplesPerPixel[sourceIndex] = wantedSamples
|
||||||
@@ -607,7 +606,7 @@ class GeoTIFFSource extends DataTile {
|
|||||||
const bands = this.sourceInfo_[sourceIndex].bands;
|
const bands = this.sourceInfo_[sourceIndex].bands;
|
||||||
if (bands) {
|
if (bands) {
|
||||||
for (let i = 0; i < bands.length; ++i) {
|
for (let i = 0; i < bands.length; ++i) {
|
||||||
if (!isNaN(values[bands[i] - 1])) {
|
if (values[bands[i] - 1] !== null) {
|
||||||
this.addAlpha_ = true;
|
this.addAlpha_ = true;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
@@ -617,7 +616,7 @@ class GeoTIFFSource extends DataTile {
|
|||||||
|
|
||||||
// option 3: check image metadata for all bands
|
// option 3: check image metadata for all bands
|
||||||
for (let imageIndex = 0; imageIndex < values.length; ++imageIndex) {
|
for (let imageIndex = 0; imageIndex < values.length; ++imageIndex) {
|
||||||
if (!isNaN(values[imageIndex])) {
|
if (values[imageIndex] !== null) {
|
||||||
this.addAlpha_ = true;
|
this.addAlpha_ = true;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
@@ -681,7 +680,7 @@ class GeoTIFFSource extends DataTile {
|
|||||||
|
|
||||||
/** @type {number|Array<number>} */
|
/** @type {number|Array<number>} */
|
||||||
let fillValue;
|
let fillValue;
|
||||||
if (!isNaN(source.nodata)) {
|
if ('nodata' in source && source.nodata !== null) {
|
||||||
fillValue = source.nodata;
|
fillValue = source.nodata;
|
||||||
} else {
|
} else {
|
||||||
if (!samples) {
|
if (!samples) {
|
||||||
@@ -778,7 +777,11 @@ class GeoTIFFSource extends DataTile {
|
|||||||
nodata = nodataValues[sourceIndex][bandIndex];
|
nodata = nodataValues[sourceIndex][bandIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceValue !== nodata) {
|
const nodataIsNaN = isNaN(nodata);
|
||||||
|
if (
|
||||||
|
(!nodataIsNaN && sourceValue !== nodata) ||
|
||||||
|
(nodataIsNaN && !isNaN(sourceValue))
|
||||||
|
) {
|
||||||
transparent = false;
|
transparent = false;
|
||||||
data[dataIndex] = value;
|
data[dataIndex] = value;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
test/rendering/cases/cog-f32-nodata-explicit-nan/expected.png
Normal file
BIN
test/rendering/cases/cog-f32-nodata-explicit-nan/expected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
21
test/rendering/cases/cog-f32-nodata-explicit-nan/main.js
Normal file
21
test/rendering/cases/cog-f32-nodata-explicit-nan/main.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import GeoTIFF from '../../../../src/ol/source/GeoTIFF.js';
|
||||||
|
import Map from '../../../../src/ol/Map.js';
|
||||||
|
import TileLayer from '../../../../src/ol/layer/WebGLTile.js';
|
||||||
|
|
||||||
|
const source = new GeoTIFF({
|
||||||
|
sources: [{url: '/data/raster/elevation-f32.tif', nodata: NaN}],
|
||||||
|
});
|
||||||
|
|
||||||
|
new Map({
|
||||||
|
layers: [
|
||||||
|
new TileLayer({
|
||||||
|
source: source,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
target: 'map',
|
||||||
|
view: source.getView(),
|
||||||
|
});
|
||||||
|
|
||||||
|
render({
|
||||||
|
message: 'normalize i16 data with nan nodata based on GDAL stats',
|
||||||
|
});
|
||||||
BIN
test/rendering/cases/cog-f32-nodata/expected.png
Normal file
BIN
test/rendering/cases/cog-f32-nodata/expected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
21
test/rendering/cases/cog-f32-nodata/main.js
Normal file
21
test/rendering/cases/cog-f32-nodata/main.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import GeoTIFF from '../../../../src/ol/source/GeoTIFF.js';
|
||||||
|
import Map from '../../../../src/ol/Map.js';
|
||||||
|
import TileLayer from '../../../../src/ol/layer/WebGLTile.js';
|
||||||
|
|
||||||
|
const source = new GeoTIFF({
|
||||||
|
sources: [{url: '/data/raster/elevation-f32.tif'}],
|
||||||
|
});
|
||||||
|
|
||||||
|
new Map({
|
||||||
|
layers: [
|
||||||
|
new TileLayer({
|
||||||
|
source: source,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
target: 'map',
|
||||||
|
view: source.getView(),
|
||||||
|
});
|
||||||
|
|
||||||
|
render({
|
||||||
|
message: 'normalize i16 data with nan nodata based on GDAL stats',
|
||||||
|
});
|
||||||
BIN
test/rendering/cases/cog-i16-nodata/expected.png
Normal file
BIN
test/rendering/cases/cog-i16-nodata/expected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
21
test/rendering/cases/cog-i16-nodata/main.js
Normal file
21
test/rendering/cases/cog-i16-nodata/main.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import GeoTIFF from '../../../../src/ol/source/GeoTIFF.js';
|
||||||
|
import Map from '../../../../src/ol/Map.js';
|
||||||
|
import TileLayer from '../../../../src/ol/layer/WebGLTile.js';
|
||||||
|
|
||||||
|
const source = new GeoTIFF({
|
||||||
|
sources: [{url: '/data/raster/elevation-i16.tif'}],
|
||||||
|
});
|
||||||
|
|
||||||
|
new Map({
|
||||||
|
layers: [
|
||||||
|
new TileLayer({
|
||||||
|
source: source,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
target: 'map',
|
||||||
|
view: source.getView(),
|
||||||
|
});
|
||||||
|
|
||||||
|
render({
|
||||||
|
message: 'normalize i16 data with -9999 nodata based on GDAL stats',
|
||||||
|
});
|
||||||
BIN
test/rendering/data/raster/elevation-f32.tif
Normal file
BIN
test/rendering/data/raster/elevation-f32.tif
Normal file
Binary file not shown.
BIN
test/rendering/data/raster/elevation-i16.tif
Normal file
BIN
test/rendering/data/raster/elevation-i16.tif
Normal file
Binary file not shown.
Reference in New Issue
Block a user