Published
Edited
Oct 12, 2021
Insert cell
# Convert GeoTIFF to PNG using GeoRaster
Insert cell
import {file} from "@jashkenas/inputs"
Insert cell
parseGeoRaster = require("georaster")
Insert cell
viewof geotiff = file({
title : "file.tif",
description : "upload a GeoTIFF",
multiple : false,
})
Insert cell
arrayBuffer = await Files.buffer(geotiff)
Insert cell
georaster = parseGeoRaster(arrayBuffer)
Insert cell
height_over_width = georaster.height / georaster.width
Insert cell
height = height_over_width >= 1 ? 512 : Math.round(512 / height_over_width);
Insert cell
width = height_over_width <= 1 ? 512 : Math.round(512 / height_over_width);
Insert cell
canvas = georaster.toCanvas({ height, width })
Insert cell
saveFile = require("easy-file-saver").catch(() => window['saveFile'])
Insert cell
saveFile({ data: canvas, filename: "overview.png" })
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