GeoBlaze Raster Processing Engine

repository·master·Indexed 41 days ago

https://github.com/geotiff/geoblaze

A 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.

Tokens
8.6K
Snippets
28
Records
35
Agent score
51%

What's inside GeoBlaze

  1. Run raster calculations with GeoBlaze

    master

    GeoBlaze 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;
    }
  2. Calculate the sum of values in a raster with sum()

    master

    The sum function calculates the sum of all pixel values within a georaster.

    Behavior:

    • With geometry: Returns the sum of all pixels contained within the specified area.
    • Without geometry: Returns the sum of all pixels for each band in the georaster.

    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:
      • An array [xmin, ymin, xmax, ymax] for a bounding box.
      • A polygon coordinate array: [[[x00,y00],...,[x0n,y0n],[x00,y00]]...].
      • A GeoJSON polygon object.
      • A string representation of a GeoJSON polygon.
    • 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 `
  3. Troubleshoot GeoBlaze loading and parsing errors

    master

    When using GeoBlaze, you may encounter specific error messages indicating why a file could not be processed. Common error scenarios include:

    • Loading files outside the browser: Direct raster loading is currently not supported in non-browser environments (like Node.js) due to dependency limitations. To resolve this, use a URL to the file or run your code in a browser environment.
    • Invalid URLs or CORS issues: If GeoBlaze cannot load a file, the URL might be incorrect, or the hosting server's security policy (CORS) might be preventing cross-domain requests. You can try using a different URL or downloading the file to load it manually.
    • GeoTIFF parsing failures: If you receive a parsing error, ensure that the file being provided is a valid GeoTIFF format.
  4. Use the GeoBlaze Lite API

    master

    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';
  5. Convert geometries with the Geometry conversion API

    master

    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);
  6. Calculate the mode value in a raster with mode()

    master

    The mode function calculates the most frequent pixel value (the mode) within a georaster.

    Behavior:

    • With Geometry: If a geometry is provided, it returns the mode of all pixels within that specific area.
    • Without Geometry: If no geometry is provided, it returns the mode of all pixels for each band in the georaster.
    • Multiple Modes: If a band has more than one mode, the function computes the mean of those modes.

    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:
      • An array [xmin, ymin, xmax, ymax] for a bounding box.
      • A polygon array: [[[x00,y00],...,[x0n,y0n],[x00,y00]]...].
      • A GeoJSON polygon object.
      • A string representation of a GeoJSON polygon object.
    • 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]
  7. Calculate the minimum value in a raster with min()

    master

    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]
  8. Calculate the range of values in a georaster with range()

    master

    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]