georaster-layer-for-leaflet icon indicating copy to clipboard operation
georaster-layer-for-leaflet copied to clipboard

Single value array support

Open scazz010 opened this issue 6 years ago • 1 comments
trafficstars

Hi!

Mega suit of geotiff packages - really helpful, nice code to work with!

I've got a GeoTIFF that has single values, not RGB bands. It looks like you're expecting this line https://github.com/GeoTIFF/georaster-layer-for-leaflet/blob/34cb38957822642be285eff1fd272ea8d02a8020/georaster-layer-for-leaflet.js#L130

to return an array of an array of pixel values so [Unit32Array,Unit32Array,Unit32Array] or whatever - but I end up with just a single array - Unit32Array (not wrapped in an array).

SO this line: https://github.com/GeoTIFF/georaster-layer-for-leaflet/blob/34cb38957822642be285eff1fd272ea8d02a8020/georaster-layer-for-leaflet.js#L233

maps over the height coordinates and I end up with a load of undefined values.

I think it might come from: https://github.com/geotiffjs/geotiff.js/blob/e31dfcc61dff03af5ac9209ad7a9b460c07acfc2/src/geotiffimage.js#L441

But I'm really not sure - I think if interleave is set, it's not an array of values, if that makes sense? But I could be wrong here! I've just looked, haven't ran it or inspected.

I've solved for me:

if (tileRasters.length === numberOfSamplesDown) { values = [tileRasters[h][w]]; } else { // get value from array specific to this tile values = tileRasters.map(raster => raster[h][w]); }

here: https://github.com/GeoTIFF/georaster-layer-for-leaflet/blob/34cb38957822642be285eff1fd272ea8d02a8020/georaster-layer-for-leaflet.js#L231

but this obviously falls down when the height of the tile is the number of bands. (So no PR).

I'm not sure if this problem should be fixed in this library or geotiff library. (My gut probably learns towards a standard return value from the GeoTiff library (so wrapping the array in an array), but that might break the API for others?).

To Reproduce I've got a GeoTIFF file in S3: https://tiff-library.s3.eu-west-2.amazonaws.com/ethiopia/flood-maps/maxDepth1yr-cogeo.tiff

Or you can try and open it in the COG-Explorer (and see the network request to undefined https://geotiffjs.github.io/cog-explorer/#long=45.142&lat=9.136&zoom=13&scene=https://tiff-library.s3.eu-west-2.amazonaws.com/ethiopia/flood-maps/maxDepth1yr-cogeo.tiff&bands=0,1,2&pipeline=

Thanks again for the library, hope this helps. It's been really useful. Let me know if I can help/provide more info.

Cheers S

scazz010 avatar Nov 20 '19 11:11 scazz010

Thank you. And Awesome issue! I'll take a look and have a solution hopefully within a week.

DanielJDufour avatar Nov 20 '19 14:11 DanielJDufour