GeoTIFF / georaster-layer-for-leaflet

Display GeoTIFFs and soon other types of raster on your Leaflet Map
https://geotiff.github.io/georaster-layer-for-leaflet-example/
Apache License 2.0
306 stars 58 forks source link

How can you extract bands from a geotiff? #144

Closed john-a-m closed 7 months ago

john-a-m commented 7 months ago

I noticed when browsing through the issues that issue #67 seems to imply that it is possible to visualize a band by providing a pixelValuesToColorFn which sounds good to me. Is there an example of how to leverage pixelValuesToColorFn to do this?

DanielJDufour commented 7 months ago

Sure thing. Here's a few examples:

Let me know if you have any more questions!

john-a-m commented 7 months ago

If anyone comes across this what is important to know is that if a geotiff has bands then pixelValuesToColorFn will be given an array of values rather than a singular value. The population example highlights this well.

var layer = new GeoRasterLayer({
    attribution: "European Commission: Global Human Settlement",
    georaster: georaster,
    opacity: 0.75,
    resolution: 64,
    pixelValuesToColorFn: function (values) {
      var population = values[0];
      if (population === -200) return;
      if (population < 0) return;
      return scale(population).hex();
    }
});