I’m trying to apply color mapping to a GeoTIFF layer in OpenLayers 9.2.4, but I’m encountering an issue where the entire GeoTIFF is displayed as a single color instead of applying my color ranges properly.
Issue Description
I have a GeoTIFF file with raster data values that should be mapped to different colors based on value ranges. I’ve created a color mapping array and applied it using WebGLTile styling, but the visualization doesn’t match my color legend.
Expected Behavior
Different areas of the GeoTIFF should display different colors based on pixel values
The colors should match the ranges defined in my colorMappings array
Actual Behavior
The entire GeoTIFF is rendered with a single color
The color mapping doesn’t seem to be applied correctly
Here’s the relevant part of my code:
// Color mapping rules
const colorMappings = [
{ min: 0, max: 2, color: [0, 97, 0] },
{ min: 2, max: 4, color: [50, 128, 27] },
// ... more ranges ...
];
// GeoTIFF source
const source = new ol.source.GeoTIFF({
sources: [{ url: './test.tif' }],
convertToRGB: false
});
// Color expression for styling
const colorExpression = [
'case',
...colorMappings.flatMap((mapping) => [
['all',
['>=', ['band', 1], mapping.min],
['<', ['band', 1], mapping.max]
],
['color', ...mapping.color, 255]
]),
['color', 0, 0, 0, 0]
];
// WebGL tile layer with styling
const tiffLayer = new ol.layer.WebGLTile({
source: source,
style: { color: colorExpression }
});
What I Suspect
I suspect the issue might be related to the band index in the color expression. I’m currently using [‘band’, 1] to reference the data values, but I’m not sure if this is correct for my GeoTIFF file.
Possible issues:
- OpenLayers band indexing might be 0-based instead of 1-based
- My GeoTIFF might have multiple bands and I’m referencing the wrong one
- The data values in my GeoTIFF might be outside the ranges I’ve defined
- There might be a problem with how WebGLTile applies styling to GeoTIFF data
Questions
1、How can I determine which band index I should be using?
Is there a way to debug what values are actually in my GeoTIFF?
2、Are there any common issues with WebGLTile styling for GeoTIFF that I should be aware of?
3、Should I be configuring the source or style differently?
4、Any assistance would be greatly appreciated!
