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.
(String)
a string representation of an arithmetic operation to perform
GeoRaster
:
the computed georaster
// 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)');
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.
(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.
(Boolean)
whether or not the resulting output should be flattened into a single array for each band
Object
:
array of pixel values
const pixels = await geoblaze.get(georaster, geometry);
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.
(Object
= undefined
)
a geometry, which we'll use for clipping result
Object
:
array of histograms for each band
// 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" });
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.
// 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]
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.
// 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)");
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the max calculation
Array<Number>
:
array of maxs for each band
// 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]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the min calculation
Array<Number>
:
array of mins for each band
// 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]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the range calculation
Array<Number>
:
array of ranges for each 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]
[231, 234, 229, 0]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the mean calculation
Array<Number>
:
array of means for each band
// 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]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the median calculation
Array<Number>
:
array of medians for each band
// 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]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the mode calculation
Array<Number>
:
array of modes for each band
// 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]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the modes calculation
Array<Array<Number>>
:
array of modes for each band
// 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]]
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.
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);
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
(Function)
a JavaScript function representing an arithmetic operation to perform
GeoRaster
:
georaster - the computed georaster
// 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);
The stats function takes a georaster and an optional geometry. It then uses the calc-stats library to calculate statistics for each band.
(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.
(Object)
options passed to
calc-stats
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the sum calculation
(Object)
Name | Description |
---|---|
extraOptions.vrm ([number, number] |
|
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 |
Array<Object>
:
array of stats for each band
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 }]
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.
(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.
(Function)
a filter function that takes in a pixel value and returns true or false whether it should be included in the sum calculation
(Object)
Name | Description |
---|---|
extraOptions.vrm ([number, number] |
|
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. |
Array<Number>
:
array of sums for each band
// 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]