0

I have a 250 MB, 9 band Cloud Optimized GeoTIFF in an Azure Container which I am trying to retrieve overviews from to display in a browser with CDN OpenLayers, but I keep running in errors with every permutation I've tried.

I've validated the COG using this GDAL referenced script.

My HTML tags for loading the CDN version of OpenLayers look like

 <script src="https://cdn.jsdelivr.net/npm/geotiff"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/ol.css"> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script> 

My JavaScript looks like:

 const tiffLayer = new ol.layer.WebGLTile({ source: new ol.source.GeoTIFF({ sources: [{ url: '/cog/test.tif/', // This URL calls the Django view to serve the COG overviews: true, }], }) }); const map = new ol.Map({ target: 'map', layers: [ baseLayer, tiffLayer ], view: new ol.View({ projection: 'EPSG:3857', center: ol.proj.fromLonLat([-70.2980, 41.7779]), // Adjust the center based on the COG location zoom: 10 }) }); 

How can I quickly load overviews from the COG into the browser?


After @user30184's comments, I reprocessed the COG using:

rio cogeo create --zoom-level 19 --overview-resampling cubic -w -b 5,3,2 test.tif test2.tif 

Note that the COG is now three bands, RGB. Although I used the COG example above, I thought trying the COG Blob option might work and used this example. My code now looks like:

 fetch('/cog/test2.tif') .then((response) => response.blob()) .then((blob) => { const source = new ol.source.GeoTIFF({ sources: [{ blob: blob, overviews: true, }], convertToRGB: true, }); const baseLayer = new ol.layer.Tile({ source: new ol.source.OSM(), }); const map = new ol.Map({ target: 'map', layers: [ baseLayer, new ol.layer.WebGLTile({ source: source, }), ], view: new ol.View({ center: ol.proj.fromLonLat([-70.2980, 41.7779]), zoom: 10 }) }); }); 

While this plots the COG over an OSM baselayer, the COG is a solid black box although I've confirmed, in ArcGIS Pro, that the image isn't entirely black. Also, it seems as if the entire image is being retrieved rater than just the tiled overviews.

How can I get the image to display the colors correctly and read the overviews as tiles?

5
  • Is it possible to show 9 band images with OpenLayers in the first place? What do you suppose to see then? What errors do you get now? Does you code work with an RGB COG from a fixed URL? Does it work with a 9 band COG from a fixed url? This test should eliminate possible errors in the system that calls the Django view. Commented Sep 18, 2024 at 21:01
  • @user30184 I was under the impression that it would at least load the overviews for the first three bands. I'm not even seeing that. Commented Sep 19, 2024 at 15:03
  • Where did you get that impression? It may be correct, but it would be good to see the reference. Did you already made it work with your own RGB imagery like in openlayers.org/en/latest/examples/cog.html? Commented Sep 19, 2024 at 15:12
  • Yes. I got the example to work. Commented Sep 19, 2024 at 15:40
  • I guess you may have satellite images with a datatype like Float32, and data values in the image are close to the black end of that very large range. Chech with gdalinfo gdalinfo test2.tif -stats. If that is the case you must scale the data for the viewer. I don't know how to do that with OpenLayers. Maybe you can get some ideas from this workshop openlayers.org/workshop/en/cog/true-color.html. Commented Sep 19, 2024 at 18:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.