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
284 stars 57 forks source link

Question: Original band data types #55

Open Nightsphere opened 3 years ago

Nightsphere commented 3 years ago

Hello, it's once again question time! I would like to be able to display the raster's original data types for each band for users. For example, being able to know for sure that in band X, number A is an integer and number B is floating point. JavaScript converts everything to number, which I'm sure you know, and it doesn't help if the original data type was uint16, float32, etc.

Is there a way to determine this already in the georaster object somewhere that I've missed?

DanielJDufour commented 3 years ago

Hi, @Nightsphere . This is a great question. I don't have a great answer. The current version of georaster doesn't technically support it, but I'll make sure the next version does (I'm actively working on it).

In the interim, there are two ways to get the information: 1) For georasters that you load via url you can do:

// inside an async function
const geotiff = georaster._geotiff;
const image = await geotiff.getImage();
const bitsPerSample = image.fileDirectory.BitsPerSample;
// bitsPerSample is [16]

2) For georasters that have been loaded by a file or array buffer, you will have to use the geotiff-js library to get at the values and can do something like this:

import { fromArrayBuffer } from 'geotiff';

// inside async function
const geotiff = await fromArrayBuffer(arrayBuffer);
const image = await geotiff.getImage();
const bitsPerSample = image.fileDirectory.BitsPerSample;
// bitsPerSample is [16]

However, I can't guarantee that the next major version of georaster will support georaster._geotiff, so use with caution.

Thanks for bringing this up and let's keep this issue open, so I can track it and include this info in the next version of georaster.

Nightsphere commented 3 years ago

Awesome, thank you for the quick response as always. We are using georasters from a file and were already looking into geotiff-js, so it's good to hear it was the right direction.

It's also great to hear another version is being worked on! Looking forward to it.