Install GeoBlaze via npm
masterTo add GeoBlaze to your project, install it using npm.
npm install geoblazerepository·master·Indexed 41 days ago
https://github.com/geotiff/geoblazeA high-performance JavaScript raster processing engine for analyzing GeoTIFFs, supporting basic statistics, band arithmetic, and histogram generation. Compatible with web browsers and Node.js, GeoBlaze version 2.8.0 provides tools for data extraction, geometry normalization, and spatial analysis via its standard and Lite APIs.
To add GeoBlaze to your project, install it using npm.
npm install geoblazeThe data/gadm/arcgis/ directory is empty in the source repository. To populate this directory with country data in ArcGIS JSON format, run the following command from the project root:
npm run setup-gadm
npm run setup-gadmThe data/gadm/geojsons/ directory is empty in the source repository by default. To populate this directory with GeoJSON files for all countries in the world, run the following command from the project root:
npm run setup-gadmGeoBlaze allows you to load a GeoTIFF and perform various computations like statistics (min, max, mean, mode), band arithmetic, and histogram generation.
To use it, first parse the GeoTIFF URL using geoblaze.parse(url) to get a georaster object, then pass that object to the desired calculation method (e.g., geoblaze.mean(georaster)).
import geoblaze from 'geoblaze';
const url = 'http://url-to-geotiff';
async function getMean () {
const georaster = await geoblaze.parse(url);
const mean = await geoblaze.mean(georaster);
return mean;
}The sum function calculates the sum of all pixel values within a georaster.
Behavior:
Parameters:
georaster: The geospatial gridded raster data. Accepts GeoRaster, ArrayBuffer, Blob, Buffer, File, or a String (URL).geometry (optional): The area to sum within. Supported formats include:[xmin, ymin, xmax, ymax] for a bounding box.[[[x00,y00],...,[x0n,y0n],[x00,y00]]...].test (optional): A filter function (pixelValue) => boolean. If provided, only pixels that return true are included in the sum.extraOptions (optional): An object containing:vrm: Virtual resampling multiplier [number, number] or `When using GeoBlaze, you may encounter specific error messages indicating why a file could not be processed. Common error scenarios include:
The Lite version of GeoBlaze provides a collection of specialized functions for raster data analysis, including statistical calculations, band arithmetic, and data loading. You can use the library by importing the default geoblaze object or by importing individual functions directly for a smaller bundle size.
In browser environments, the library automatically attaches itself to window.geoblaze. In Web Workers, it attaches to self.geoblaze, and in Node.js, it attaches to global.geoblaze.
import geoblaze from 'geoblaze/lite';
// or
import { stats, get } from 'geoblaze/lite';The geometry conversion API provides functions to transform different types of spatial geometries. You can use the primary convertGeometry function for general conversion or use specific functions for targeted geometry types:
convertGeometry: The default entrypoint for geometry conversion.convertBbox: Converts a bounding box.convertMultiPolygon: Converts a MultiPolygon geometry.convertPoint: Converts a Point geometry.import { convertGeometry, convertBbox, convertMultiPolygon, convertPoint } from 'geoblaze';
// Example usage (conceptual):
// const result = convertGeometry(geometry);
// const point = convertPoint(pointData);
// const multiPolygon = convertMultiPolygon(multiPolygonData);
// const bbox = convertBbox(bboxData);The mode function calculates the most frequent pixel value (the mode) within a georaster.
Behavior:
geometry is provided, it returns the mode of all pixels within that specific area.Parameters:
georaster: The geospatial gridded raster data. Supported types include GeoRaster, ArrayBuffer, Blob, Buffer, File, or a String (URL/path).geometry (optional): Defines the area of interest. Supported formats include:[xmin, ymin, xmax, ymax] for a bounding box.[[[x00,y00],...,[x0n,y0n],[x00,y00]]...].test (optional): A filter function that takes a pixel value and returns true or false to determine if that pixel should be included in the calculation.// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";
const results = await geoblaze.mode(url, geometry);
// results is [red, green, blue, nir]
// e.g., [42, 84, 92, 94]The min function calculates the minimum pixel value for each band in a georaster.
If a geometry is provided, the function returns the minimum values for all pixels within that specific area. If no geometry is provided, it calculates the minimum for all pixels in the entire raster.
You can also provide an optional test function to filter which pixel values are included in the calculation.
// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";
const mins = await geoblaze.min(url, geometry);
// mins is [red, green, blue, nir]
// e.g., [1, 4, 9, 4]min function returns a Number[] (an array of numbers), where each element represents the minimum value found for the corresponding band in the georaster.The range function calculates the range of pixel values for each band in a georaster.
If a geometry is provided, the function calculates the range for all pixels within that specific area. If no geometry is provided, it calculates the range for all pixels in the entire raster.
You can also provide an optional test function to act as a filter; the function will only include pixels in the calculation that satisfy the test condition (where test(pixelValue) returns true).
Returns an array of numbers where each element represents the range for a corresponding band.
// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";
const ranges = await geoblaze.range(url, geometry);
// ranges is [red, green, blue, nir]
// e.g., [231, 234, 229, 0]