Overview of geotiff.js
masterfetch or XHR), local ArrayBuffers, and the filesystem (via FileReader in browsers or filesystem functions in Node.js).repository·master·Indexed 21 days ago
https://github.com/geotiffjs/geotiff.jsA JavaScript library for reading geospatial metadata and raw array data from a wide variety of (Geo)TIFF file types. It supports parsing from remote sources via fetch/XHR, local ArrayBuffers, and the filesystem in both browser and Node.js environments. The library provides low-level access to metadata and raster data, including support for various compressions, data types, and BigTIFF, with capabilities to read rasters, convert visual data to RGB, and write uncompressed GeoTIFFs to ArrayBuffers.
fetch or XHR), local ArrayBuffers, and the filesystem (via FileReader in browsers or filesystem functions in Node.js).geotiff.js provides limited support for the BigTIFF format due to JavaScript's handling of 64-bit integers. Users should be aware of the following behaviors:
Array type. This may cause issues with certain compression algorithms if these arrays are used for pixel values.When working with GeoTIFF objects (rather than GeoTIFFImage objects), you can call readRasters() directly on the tiff object. This enables automatic selection of the best image based on your requirements:
width, height, resX, or resY, the library selects the best-fitting image (e.g., an overview).bbox instead of a window, the library uses geographic coordinates to select the appropriate image/overview.// Uses geographic bbox and selects best fitting overview based on resolution
const data = await tiff.readRasters({
bbox: [10.34, 57.28, 13.34, 60.23],
resX: 0.1,
resY: 0.1
});Version 3.0 introduces deferred tag reading for performance. While high-level APIs like getImage() and readRasters() remain compatible, several low-level access patterns have changed:
image.geoKeysimage.getGeoKeys() (Async)getTiePoints() and getGDALMetadata() are now asynchronous and must be awaited.Direct property access on fileDirectory is replaced by the ImageFileDirectory class:
image.fileDirectory.getValue('TagName').await image.fileDirectory.loadValue('TagName') for large arrays or deferred tags.image.fileDirectory.hasTag('TagName') instead of checking for truthiness on the property.await image.fileDirectory.loadValueIndexed('TagName', index) for specific elements in large arrays (e.g., TileOffsets).Decoders now receive parameters during construction. Use addDecoder to register them with a parameter extraction function that can handle deferred values.
GeoTIFF.js can be used in Node.js environments via require or import, or directly in the browser using a <script> tag. The library exposes factory functions like fromUrl, fromUrls, fromArrayBuffer, and fromBlob to create GeoTIFF objects.
// Node.js CommonJS
const GeoTIFF = require('geotiff');
const { fromUrl, fromUrls, fromArrayBuffer, fromBlob } = GeoTIFF;
// ES Modules
import GeoTIFF, { fromUrl, fromUrls, fromArrayBuffer, fromBlob } from 'geotiff';
// Browser CDN
// <script src="https://cdn.jsdelivr.net/npm/geotiff"></script>
// console.log(GeoTIFF);To build the library from source, run the build command. This generates two separate builds: one for the browser and one for Node.js.
Output locations:
dist-browser/main.jsdist-node/main.jsnpm run buildYou can install the geotiff package using npm to include it in your project dependencies.
npm install geotiffFor quick integration without a package manager, you can use the prebuilt version via a CDN by adding a script tag to your HTML.
<script src="https://cdn.jsdelivr.net/npm/geotiff"></script>To run the library's test suite, you must first set up the test data. This requires GDAL and ImageMagick to be installed on your system.
Ubuntu (using ubuntugis-unstable):
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y gdal-bin imagemagickMacOS (using Homebrew):
brew install wget gdal imagemagickOnce the tools are installed, run the setup script located in the test/data directory:
cd test/data
sh setup_data.sh
cd -Run the test suite using npm:
npm testTo run tests directly in a browser environment, start the development server and navigate to the provided local URL.
```bash
npm run devAfter running the command, navigate to http://localhost:8090/test/ in your browser.
To set up the repository for development, clone the repository and install the dependencies using npm.
# clone repo
git clone https://github.com/constantinius/geotiff.js.git
cd geotiff.js/
# install development dependencies
npm install