bandArithmetic

The band arithmetic function takes a georaster and an arithmetic operation. The function performs pixel-by-pixel calculation according to the arithmetic operation provided. This is only possible for a multiband raster and not for single band rasters. The output is a computed single band raster.

bandArithmetic
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
operation (String) a string representation of an arithmetic operation to perform
Returns
GeoRaster: the computed georaster
Example
// naip.tif has 4-bands: red (a), green (b), blue (c) and near-infrared (d)
const ndvi = await geoblaze.bandArithmetic("https://example.org/naip.tif", '(d - a)/(d + a)')

// or if you want to preload the georaster, so you can use it later, too
const georaster = await geoblaze.load("https://example.org/naip.tif");
const ndvi = await geoblaze.bandArithmetic(georaster, '(c - b)/(c + b)');

get

The get function takes a georaster and a bounding box as input. It returns the subset of pixels in the georaster found within the bounding box. It also takes an optional parameter "flat" which will flatten the returning pixel matrix across bands, so that for each band all the rows will be combined into one long array.

get
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
boundingBox (Object) can be an [xmin, ymin, xmax, ymax] array, a [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
flat (Boolean) whether or not the resulting output should be flattened into a single array for each band
Returns
Object: array of pixel values
Example
const pixels = await geoblaze.get(georaster, geometry);

histogram

The histogram function takes a georaster as an input and an optional geometry. If a geometry is included, the function returns the histogram of all the pixels in that area. If no geometry is included, the function returns the histogram of all the pixels for each band in the georaster.

histogram
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
input (Object = undefined) a geometry, which we'll use for clipping result
options (Object)
Name Description
options.scaleType ("nominal" | "ratio") measurement scale
options.numClasses Number number of classes/bins, only available for ratio data
options.classType ("equal-interval" | "quantile") method of breaking data into classes, only available for ratio data
Returns
Object: array of histograms for each band
Example
// naip.tif has 4-bands: red, green, blue and near-infrared
const url = "https://example.org/naif.tif";

// calculate the raw histogram pixel values
const histograms = await geoblaze.histogram(url, geometry, { scaleType: "nominal" });

// break histograms into 10 bins for each band
const histograms = await geoblaze.histogram(url, geometry, { scaleType: "ratio", numClasses: 10, classType: "equal-interval" });

identify

Given a raster and a point geometry, the identify function returns the pixel value of the raster at the given point. The raster and point must share the same Spatial Reference System.

identify
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry ((string | object | Point)) geometry can be an [x,y] array, a GeoJSON point object, or a string representation of a GeoJSON point object.
Example
// based on https://observablehq.com/@danieljdufour/identify-single-pixel-value-in-geotiff
const url = "https://s3.amazonaws.com/geoblaze/wildfires.tiff";

// point as [longitude, latitude]
const cityOfRedding = [-122.366667, 40.583333];

const results = await geoblaze.identify(url, cityOfRedding);

// results are [red, green, blue]
[76, 76, 68]

load

This function loads a whole file into memory as a georaster. If you pass in a url, it will fetch the whole file. It is the heavy-weight alternative to geoblaze.parse and should only be used if your file is relatively small or you have a really good reason for loading the whole file into memory, like running band arithmetic to create a new file. In general, use geoblaze.parse instead of geoblaze.load.

load
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
Example
// naip.tif has 4-bands: red, green, blue and near-infrared
const url = "https://example.org/naif.tif";

const georaster = await geoblaze.load(url);

const mins = geoblaze.min(georaster);
const maxs = geoblaze.max(georaster);

const ndvi = geoblaze.bandArithmetic(georaster, "(d - a) / (d + a)");

max

The max function takes a georaster and an optional geometry. If a geometry is included, the function returns the max of all the pixels in that area. If no geometry is included, the function returns the max of all the pixels for each band in the raster.

max
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the max calculation
Returns
Array<Number>: array of maxs for each band
Example
// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";

const maxs = await geoblaze.max(url, geometry);
// maxs is [red, green, blue, nir]
[231, 242, 254, 255]

min

The min function takes a georaster as an input and an optional geometry. If a geometry is included, the function returns the min of all the pixels in that area for each band. If no geometry is included, the function returns the min of all the pixels for each band in the raster.

min
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the min calculation
Returns
Array<Number>: array of mins for each band
Example
// 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]
[1, 4, 9, 4]

min

The range function takes a georaster as an input and an optional geometry. If a geometry is included, the function returns the range of all the pixels in that area for each band. If no geometry is included, the function returns the range of all the pixels for each band in the raster.

min
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the range calculation
Returns
Array<Number>: array of ranges for each band
Example
// 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]
[231, 234, 229, 0]

mean

The mean function takes a georaster and an optional geometry. If a geometry is included, the function returns the mean of all the pixels in that area. If no geometry is included, the function returns the mean of all the pixels for each band in the raster.

mean
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the mean calculation
Returns
Array<Number>: array of means for each band
Example
// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";

const means = await geoblaze.mean(url, geometry);
// means is [red, green, blue, nir]
[42, 84, 92, 94]

median

The median function takes a raster and an optional geometry. If a geometry is included, the function returns the median of all the pixels in that area. If no geometry is included, the function returns the median of all the pixels for each band in the raster.

median
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the median calculation
Returns
Array<Number>: array of medians for each band
Example
// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";

const medians = await geoblaze.median(url, geometry);
// medians is [red, green, blue, nir]
[42, 84, 92, 94]

mode

The mode function takes a georaster and an optional geometry. If a geometry is included, the function returns the mode of all the pixels in that area. If no geometry is included, the function returns the mode of all the pixels for each band in the georaster. If there is more than one mode for a band, it computes the mean among those modes.

mode
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the mode calculation
Returns
Array<Number>: array of modes for each band
Example
// 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]
[42, 84, 92, 94]

modes

The modes function takes a georaster and an optional geometry. If a geometry is included, the function returns the modes of all the pixels in that area. If no geometry is included, the function returns the modes of all the pixels for each band in the georaster. Unlike the mode function, it will not compute the mean, but return all the most common values for each band.

modes
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the modes calculation
Returns
Array<Array<Number>>: array of modes for each band
Example
// 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] ]
[[ 42, 43] , [83, 82, 84], [92], [94]]

parse

The parse function takes a georaster (as an object, array buffer, blob, buffer, file or url) and returns a promise. The promise resolves to a georaster, which can be used as input in other geoblaze methods, such as identify, sum, or histogram. This function essentially call's georaster's parseGeoRaster function.

parse
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
Example
import { parse } from "geoblaze";

// parse url
const georaster = await parse("https://example.org/naif.tif");

// parse array buffer
const response = await fetch("https://example.org/naif.tif");
const arrayBuffer = await response.arrayBuffer();
const georaster = await parse(arrayBuffer);

// parse buffer (in NodeJS)
import { readFileSync } from "fs";
const buffer = readFileSync("naip.tif");
const georaster = await parse(buffer);

rasterCalculator

The raster calculator function takes a georaster and a javascript function as input. The function is performed pixel-by-pixel on each cell in the raster. The arguments to the function should reference bands in the order in the raster

rasterCalculator
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
function (Function) a JavaScript function representing an arithmetic operation to perform
Returns
GeoRaster: georaster - the computed georaster
Example
// 3-band GeoTIFF with bands (a) red, (b) green, and (c) blue
const url = "https://example.org/rgb.tif"
const filteredRaster = geoblaze.rasterCalculator(url, (a, b, c) => a + b === c ? 1 : 0);

stats

The stats function takes a georaster and an optional geometry. It then uses the calc-stats library to calculate statistics for each band.

stats
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
calcStatsOptions (Object) options passed to calc-stats
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the sum calculation
extraOptions (Object)
Name Description
extraOptions.vrm ([number, number] | "minimal") virtual resampling multiplier for the horizontal (x) and vertical (y) dimensions. In other words, how many times we divide each pixel horizontally and vertically to increase resolution. If you don't want to pass in the exact number of times to divide the pixels, pass "minimal" and geoblaze will calculate the minimal amount of divisions to make sure at least one pixel is intersected.
extraOptions.rescale Boolean whether we should scale some results (specifically count, histogram, invalid, product, sum, valid) according to how many times the pixels are divided when virtually resampling
Returns
Array<Object>: array of stats for each band
Example
const stats = await geoblaze.stats("https://example.org/imagery.tif", geometry);
[{ median: 906.7, min: 0, max: 5166.7, sum: 262516.5, mean: 1232.4718309859154, modes: [0], mode: 0, histogram: { 0: 12, 1: 74, 2: 573, ... } }]

// with vrm = [2, 2] and rescale = true, divide pixels into quarters (half horizontally and half vertically) and count each pixel as quarter of a pixel
const stats = await geoblaze.stats("https://example.org/imagery.tif", geometry, { stats: ["count", "min", "max", "sum"] }, undefined, { vrm: [2, 2], rescale: true });
[{ count: 4.25, min: 0, max: 5, sum: 6.75 }]

sum

The sum function takes a georaster and an optional geometry. If a geometry is included, the function returns the sum of all the pixels in that area. If no geometry is included, the function returns the sum of all the pixels for each band in the georaster.

sum
Parameters
georaster ((GeoRaster | ArrayBuffer | Blob | Buffer | File | String)) geospatial gridded raster data
geometry (Object) geometry can be an [xmin, ymin, xmax, ymax] array for a bounding box, [[[x00,y00],...,[x0n,y0n],[x00,y00]]...] for a polygon, a GeoJSON polygon object, or a string representation of a GeoJSON polygon object.
test (Function) a filter function that takes in a pixel value and returns true or false whether it should be included in the sum calculation
extraOptions (Object)
Name Description
extraOptions.vrm ([number, number] | "minimal") virtual resampling multiplier for the horizontal (x) and vertical (y) dimensions. In other words, how many times we divide each pixel horizontally and vertically to increase resolution. If you don't want to pass in the exact number of times to divide the pixels, pass "minimal" and geoblaze will calculate the minimal amount of divisions to make sure at least one pixel is intersected.
extraOptions.rescale Boolean whether we should rescale results based on virtual pixel size. It is highly recommended you set rescale to true if you set vrm.
Returns
Array<Number>: array of sums for each band
Example
// naip.tif has 4-bands: red, green, blue and near-infrared (nir)
const url = "https://example.org/naif.tif";

const results = await geoblaze.sum(url, geometry);
// results is [red, green, blue, nir]
[217461, 21375, 57312, 457125]

// elevation.tif has one band with pixel values representing altitude
const elevation_url = "https://example.org/elevation.tif";

const results = await geoblaze.sum(elevation_url, geometry, value => value >= 0);
// results is sum of all interesecting pixels at or above sea level
[2131]

const population_url = "https://example.org/population.tif";
const results = await geoblaze.sum(population_url, geometry, undefined, { vrm: [100, 100], rescale: true });
// results is the estimated number of people living within a geometry after resampling pixels (dividing 100 times horizontally then vertically)
[3154.25425]