Skip to content

Instantly share code, notes, and snippets.

@postspectacular
Created August 8, 2026 07:33
Show Gist options
  • Select an option

  • Save postspectacular/10e2940c4bb3fd706f77c3e65f1b4427 to your computer and use it in GitHub Desktop.

Select an option

Save postspectacular/10e2940c4bb3fd706f77c3e65f1b4427 to your computer and use it in GitHub Desktop.
import { output, processImage } from "@thi.ng/imago";
import { GRAY8 } from "@thi.ng/pixel";
import { readGeoTiff } from "@thi.ng/pixel-io-geotiff";
import { range2d } from "@thi.ng/transducers";
import { readFileSync } from "node:fs";
// a 44155 x 25153 pixel GeoTIFF file
const path = "DOM_Tirol_5m_epsg31254/DOM_Tirol_5m_epsg31254_2017-2023.tif";
// load GeoTIFF
const { img } = await readGeoTiff(readFileSync(path), { clamp: [0, 4000], pool: 8 });
const { width, height } = img;
const size = 4096;
// extract tiles and export as PNG images
for (let [x, y] of range2d(0, width, 0, height, size, size)) {
const tile = img.getRegion(x, y, size, size);
await processImage(tile!.as(GRAY8), [
output({ id: "main", path: `tile-${x}-${y}.png` }),
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment