Published
Edited
Oct 20, 2021
1 star
Insert cell
Insert cell
Insert cell
geotiff = require("geotiff.js@1.0.1/dist/geotiff.bundle.min.js")
Insert cell
Insert cell
viewof f = html`<input type='file' />`
Insert cell
f
Insert cell
Insert cell
Insert cell
example = geotiff.fromUrl(url)
Insert cell
Insert cell
image = example.getImage()
Insert cell
Insert cell
image.getBoundingBox()
Insert cell
image.getWidth()
Insert cell
Insert cell
example.getImageCount()
Insert cell
thumbnail = example.getImage(4)
Insert cell
Insert cell
thumbnail.readRasters()
Insert cell
md`That’s much more manageable. Let’s load it:`
Insert cell
{
let data = await readImageData(thumbnail);
let c = DOM.context2d(data.width, data.height, 1);
c.putImageData(data, 0, 0);
return c.canvas;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
readImageData = async (image, options = {}) => {
const rasters = await image.readRasters(options);
let [r] = rasters;
let { width, height } = rasters;
const data = new Uint8ClampedArray(width * height * 4);
for (let i = 0; i < r.length; i++) {
let rs = r[i]*50;
data[i * 4] = rs;
data[i * 4 + 1] = rs;
data[i * 4 + 2] = rs;
data[i * 4 + 3] = rs[i] == 0 ? 0 : 255;
}
return new ImageData(data, width, height);
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more