### Install Node.js Dependencies for GeoBlaze Source: https://github.com/geotiff/geoblaze/blob/master/README.md After cloning the GeoBlaze repository, navigate into the project directory and run this command to install all necessary development dependencies defined in the 'package.json' file. This is required to build and test the project. ```bash cd geoblaze npm install ``` -------------------------------- ### Install GeoBlaze JavaScript Package Source: https://github.com/geotiff/geoblaze/blob/master/README.md This command installs the GeoBlaze library using npm, making it available for use in your Node.js or front-end JavaScript project. Ensure you have Node.js and npm installed. ```bash npm install geoblaze ``` -------------------------------- ### Run Test Suite for GeoBlaze Source: https://github.com/geotiff/geoblaze/blob/master/README.md This command executes the test suite for GeoBlaze using its testing framework. Each test automatically spins up a server using 'srvd' to simulate a testing environment. Ensure 'npm run setup' has been completed first. ```bash npm run test ``` -------------------------------- ### Get Subset of GeoRaster Pixels by Bounding Box (JavaScript) Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The get function extracts pixel data from a GeoRaster within a specified bounding box. It accepts various formats for the bounding box and an optional 'flat' parameter to flatten the output pixel matrix across bands. The function returns an object containing the pixel values. ```javascript const pixels = await geoblaze.get(georaster, geometry); ``` -------------------------------- ### Clone GeoBlaze Repository for Development Source: https://github.com/geotiff/geoblaze/blob/master/README.md This command clones the GeoBlaze project repository from GitHub to your local machine. Replace '[your-username]' with your GitHub username to fork and clone your specific version. This is the first step for contributing to the project. ```bash git clone git@github.com:[your-username]/geoblaze.git ``` -------------------------------- ### Download Test Data for GeoBlaze Source: https://github.com/geotiff/geoblaze/blob/master/README.md This script downloads the necessary test data from an S3 bucket, which is required for running GeoBlaze's test suite. It ensures that all test files have the correct assets before execution. ```bash npm run setup ``` -------------------------------- ### Run Linter for GeoBlaze Code Quality Source: https://github.com/geotiff/geoblaze/blob/master/README.md This command executes ESLint to check the GeoBlaze codebase for potential errors and style violations. It helps maintain code quality and consistency across the project according to the defined linting rules. ```bash npm run lint ``` -------------------------------- ### Generate Histograms with Geoblaze Source: https://context7.com/geotiff/geoblaze/llms.txt Creates frequency distributions (histograms) of pixel values for each band in a GeoTIFF using geoblaze. It supports both nominal (categorical) and ratio (continuous) data, with options for equal-interval and quantile binning strategies. Histograms can be calculated for the entire raster or within a specified geometry. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/naip.tif"; // Calculate raw histogram (nominal scale) const nominalHist = await geoblaze.histogram(url, null, { scaleType: "nominal" }); console.log(nominalHist); /* [ { 0: 5, 1: 12, 2: 45, 3: 89, ..., 255: 23 }, // red band { 0: 3, 1: 8, 2: 34, 3: 67, ..., 255: 19 }, // green band { 0: 7, 1: 15, 2: 52, 3: 94, ..., 255: 31 }, // blue band { 0: 2, 1: 6, 2: 28, 3: 71, ..., 255: 15 } // nir band ] */ // Break into 10 equal-interval bins const equalIntervalHist = await geoblaze.histogram(url, null, { scaleType: "ratio", numClasses: 10, classType: "equal-interval" }); console.log(equalIntervalHist); /* [ { '0-25': 1234, '26-51': 2345, '52-77': 3456, ..., '230-255': 456 }, ... ] */ // Calculate histogram for specific geometry with quantile classification const geometry = { type: "Polygon", coordinates: [[[-120, 38], [-120, 39], [-119, 39], [-119, 38], [-120, 38]]] }; const quantileHist = await geoblaze.histogram(url, geometry, { scaleType: "ratio", numClasses: 5, classType: "quantile" }); console.log(quantileHist); // 5 bins with equal pixel counts per bin ``` -------------------------------- ### Parse GeoTIFF and Calculate Mean in JavaScript Source: https://github.com/geotiff/geoblaze/blob/master/README.md This JavaScript code demonstrates how to load a GeoTIFF file from a URL using GeoBlaze, parse it into a georaster object, and then calculate the mean value of the raster data. It utilizes asynchronous functions for handling file parsing and calculations. ```javascript 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; } ``` -------------------------------- ### Execute Raster Calculator in JavaScript Source: https://context7.com/geotiff/geoblaze/llms.txt Applies a custom JavaScript function to each pixel of a GeoTIFF. This allows for complex conditional logic and multi-band calculations beyond simple arithmetic. It takes a GeoTIFF URL and a callback function as input. The callback function receives pixel values for each band and returns a calculated value for that pixel. Dependencies: geoblaze library. ```javascript import geoblaze from 'geoblaze'; // Create binary mask where red + green equals blue const rgbUrl = "https://example.org/rgb.tif"; const binaryMask = await geoblaze.rasterCalculator(rgbUrl, (r, g, b) => r + g === b ? 1 : 0 ); // Classify NAIP imagery into vegetation categories const naipUrl = "https://example.org/naip.tif"; const vegClassification = await geoblaze.rasterCalculator(naipUrl, (red, green, blue, nir) => { const ndvi = (nir - red) / (nir + red); if (ndvi < 0) return 0; // no vegetation if (ndvi < 0.2) return 1; // sparse vegetation if (ndvi < 0.5) return 2; // moderate vegetation return 3; // dense vegetation } ); // Calculate custom index with conditional logic const customIndex = await geoblaze.rasterCalculator(naipUrl, (red, green, blue, nir) => { if (nir > 200 && red < 50) { return (nir - red) / (nir + red + 1); // healthy vegetation } else if (blue > 150) { return -1; // water } else { return 0; // other } } ); // Create temperature classification const tempUrl = "https://example.org/temperature.tif"; const tempClass = await geoblaze.rasterCalculator(tempUrl, temp => { if (temp < 0) return 1; // freezing if (temp < 10) return 2; // cold if (temp < 20) return 3; // moderate if (temp < 30) return 4; // warm return 5; // hot } ); ``` -------------------------------- ### Load Entire Raster File into Memory with GeoBlaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The load function reads an entire geospatial raster file into memory, returning a GeoRaster object. This is useful for operations requiring the full dataset in memory, such as band arithmetic. For larger files, geoblaze.parse is generally recommended. ```javascript // 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)"); ``` -------------------------------- ### Calculate Raster Statistics with Geoblaze Source: https://context7.com/geotiff/geoblaze/llms.txt Calculates detailed statistical summaries for each band in a GeoTIFF file using the geoblaze library. It supports calculating all standard statistics (min, max, mean, median, mode, sum, count) for the entire raster or within a specified geometry. Options for virtual resampling are also available for accurate pixel counting. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/imagery.tif"; // Calculate all statistics for raster const allStats = await geoblaze.stats(url); console.log(allStats); /* [ { median: 906.7, min: 0, max: 5166.7, sum: 262516.5, mean: 1232.4718309859154, modes: [0], mode: 0, count: 213, valid: 213, invalid: 0, histogram: { 0: 12, 1: 74, 2: 573, ... } } ] */ // Calculate specific statistics within geometry const polygon = { type: "Polygon", coordinates: [[[-100, 40], [-100, 41], [-99, 41], [-99, 40], [-100, 40]]] }; const specificStats = await geoblaze.stats(url, polygon, { stats: ["count", "min", "max", "sum", "mean"] }); console.log(specificStats); /* [ { count: 156, min: 0, max: 5166.7, sum: 192345.2, mean: 1233.11 } ] */ // Use virtual resampling for accurate pixel counting const resampledStats = await geoblaze.stats(url, polygon, { stats: ["count", "min", "max", "sum"] }, undefined, { vrm: [2, 2], rescale: true }); console.log(resampledStats); /* [ { count: 4.25, min: 0, max: 5, sum: 6.75 } ] */ ``` -------------------------------- ### Parse GeoRaster from Multiple Sources (JavaScript) Source: https://context7.com/geotiff/geoblaze/llms.txt Parses raster data from various input formats (URLs, ArrayBuffers, Buffers, Files) into a georaster object. This approach uses lazy loading and is recommended for most use cases. It requires the 'geoblaze' library. ```javascript import geoblaze from 'geoblaze'; // Parse from URL (recommended for remote files) const georaster = await geoblaze.parse("https://example.org/elevation.tif"); // Parse from ArrayBuffer (browser) const response = await fetch("https://example.org/naip.tif"); const arrayBuffer = await response.arrayBuffer(); const georaster = await geoblaze.parse(arrayBuffer); // Parse from Buffer (Node.js) import { readFileSync } from 'fs'; const buffer = readFileSync('./data/naip.tif'); const georaster = await geoblaze.parse(buffer); // Use parsed georaster with other functions const mean = await geoblaze.mean(georaster); console.log(mean); // [42.5, 84.3, 92.1, 94.7] ``` -------------------------------- ### Load Entire GeoRaster into Memory (JavaScript) Source: https://context7.com/geotiff/geoblaze/llms.txt Loads the complete raster file into memory, making all pixel data immediately available. This is suitable for operations requiring full dataset access or for smaller files. Prefer 'parse' for most scenarios. Requires the 'geoblaze' library. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/naip.tif"; const georaster = await geoblaze.load(url); // Now all pixel data is in memory and ready for multiple operations const mins = await geoblaze.min(georaster); console.log(mins); // [1, 4, 9, 4] const maxs = await geoblaze.max(georaster); console.log(maxs); // [231, 242, 254, 255] // Perform band arithmetic on loaded data const ndvi = await geoblaze.bandArithmetic(georaster, "(d - a) / (d + a)"); console.log(ndvi); // Returns new georaster with NDVI values ``` -------------------------------- ### Calculate Minimum Raster Values with Geometry and Filters (JavaScript) Source: https://context7.com/geotiff/geoblaze/llms.txt Finds the minimum pixel value for each band in a raster, with options to constrain the calculation to a specific geometry (polygon, bbox) or apply a custom filter function. Can directly use a raster URL. Requires the 'geoblaze' library. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/elevation.tif"; // Get minimum elevation across entire raster const globalMin = await geoblaze.min(url); console.log(globalMin); // [125] - single band // Get minimum within a specific area const studyArea = [[-105.5, 39.5], [-105.5, 40.0], [-105.0, 40.0], [-105.0, 39.5], [-105.5, 39.5]]; const geometry = { type: "Polygon", coordinates: [studyArea] }; const areaMin = await geoblaze.min(url, geometry); console.log(areaMin); // [1420] // Find minimum non-negative elevation (exclude negative values like ocean depths) const landMin = await geoblaze.min(url, null, value => value >= 0); console.log(landMin); // [0] ``` -------------------------------- ### Perform Band Arithmetic on GeoRaster (JavaScript) Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The bandArithmetic function computes pixel-by-pixel calculations on a multiband GeoRaster according to a provided arithmetic operation string. It requires a multiband raster and returns a single-band computed GeoRaster. Input can be a URL or a preloaded GeoRaster object. ```javascript const ndvi = await geoblaze.bandArithmetic("https://example.org/naip.tif", "(d - a)/(d + a)") const georaster = await geoblaze.load("https://example.org/naip.tif"); const ndvi = await geoblaze.bandArithmetic(georaster, "(c - b)/(c + b)"); ``` -------------------------------- ### Perform Band Arithmetic with Geoblaze Source: https://context7.com/geotiff/geoblaze/llms.txt Performs mathematical operations across raster bands of a GeoTIFF file using geoblaze to derive new single-band rasters. This is commonly used for calculating vegetation indices like NDVI and EVI, or custom band ratios. The library supports performing these operations directly on file URLs or on pre-loaded georaster objects. ```javascript import geoblaze from 'geoblaze'; // Calculate NDVI from 4-band NAIP imagery // Bands: a=red, b=green, c=blue, d=nir const naipUrl = "https://example.org/naip.tif"; const ndvi = await geoblaze.bandArithmetic(naipUrl, '(d - a)/(d + a)'); console.log(ndvi); // Returns new georaster with NDVI values // Calculate custom green-blue ratio const gbRatio = await geoblaze.bandArithmetic(naipUrl, '(b - c)/(b + c)'); // Preload georaster for multiple operations const georaster = await geoblaze.load(naipUrl); const ndviFromLoaded = await geoblaze.bandArithmetic(georaster, '(d - a)/(d + a)'); const greenRatio = await geoblaze.bandArithmetic(georaster, 'b / (a + b + c)'); // Calculate Enhanced Vegetation Index (EVI) const evi = await geoblaze.bandArithmetic(naipUrl, '2.5 * ((d - a) / (d + 6 * a - 7.5 * c + 1))' ); // Simple band difference const rgDiff = await geoblaze.bandArithmetic(naipUrl, 'a - b'); ``` -------------------------------- ### Parse GeoRaster Data with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The parse function loads geospatial raster data from various sources including URLs, ArrayBuffers, Blobs, Buffers, Files, and strings. It returns a promise that resolves to a GeoRaster object, ready for use in other geoblaze functions. ```javascript 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); ``` -------------------------------- ### Calculate Mean Raster Values with Geometry and Filters (JavaScript) Source: https://context7.com/geotiff/geoblaze/llms.txt Computes the arithmetic mean of pixel values per band, optionally within a specified geometry (polygon, bbox) or filtered by a custom function. It can process raster data directly from a URL. Requires the 'geoblaze' library. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/naip.tif"; // 4-band NAIP imagery // Calculate mean for entire raster (all bands) const overallMean = await geoblaze.mean(url); console.log(overallMean); // [42, 84, 92, 94] - red, green, blue, nir // Calculate mean within a polygon const polygon = { type: "Polygon", coordinates: [[ [-122.4, 40.5], [-122.4, 40.6], [-122.3, 40.6], [-122.3, 40.5], [-122.4, 40.5] ]] }; const polygonMean = await geoblaze.mean(url, polygon); console.log(polygonMean); // [38, 79, 88, 91] // Calculate mean within bounding box, filtering out zero values const bbox = [-122.5, 40.4, -122.2, 40.7]; // [xmin, ymin, xmax, ymax] const filteredMean = await geoblaze.mean(url, bbox, value => value > 0); console.log(filteredMean); // [45, 87, 95, 98] ``` -------------------------------- ### Manage Cache Object in JavaScript Source: https://context7.com/geotiff/geoblaze/llms.txt Accesses and manages the internal cache object used by geoblaze to store parsed georasters and intermediate results. Caching significantly improves performance when repeatedly accessing the same data sources. The cache can be accessed directly, entries can be cleared, or the entire cache can be emptied. Dependencies: geoblaze library. ```javascript import geoblaze from 'geoblaze'; // Cache is automatically used by parse function const url = "https://example.org/large-file.tif"; // First call - parses and caches const georaster1 = await geoblaze.parse(url); console.log(Object.keys(geoblaze.cache)); // [url] // Second call - retrieves from cache (much faster) const georaster2 = await geoblaze.parse(url); // Manually access cache console.log(geoblaze.cache[url]); // Cached georaster object // Clear specific entry delete geoblaze.cache[url]; // Clear entire cache Object.keys(geoblaze.cache).forEach(key => delete geoblaze.cache[key]); // Check if URL is cached const isCached = url in geoblaze.cache; console.log(isCached); // false after clearing ``` -------------------------------- ### Calculate Range of Values for Raster Bands Source: https://context7.com/geotiff/geoblaze/llms.txt Computes the range (difference between maximum and minimum values) for each band in a GeoTIFF raster. This function supports global range calculation, range within a bounding box, and range filtering to exclude outliers. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/naip.tif"; // Calculate range for entire raster const ranges = await geoblaze.range(url); console.log(ranges); // [231, 234, 229, 0] - range for red, green, blue, nir // Calculate range within bounding box const bbox = [-122.5, 40.4, -122.2, 40.7]; const boxRange = await geoblaze.range(url, bbox); console.log(boxRange); // [180, 195, 187, 42] // Calculate range excluding outliers const filteredRange = await geoblaze.range(url, null, value => value > 10 && value < 250); console.log(filteredRange); // [220, 225, 215, 35] ``` -------------------------------- ### Calculate Min Pixel Values in GeoTIFF Raster Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The min function calculates the minimum pixel value for each band in a GeoTIFF raster. It supports an optional geometry to restrict the calculation to a defined region. Without a geometry, it computes the minimum across all pixels per band. The function returns an array of numbers, each corresponding to the minimum value of a band. ```javascript const url = "https://example.org/naif.tif"; const mins = await geoblaze.min(url, geometry); // mins is [red, green, blue, nir] // Example output: [1, 4, 9, 4] ``` -------------------------------- ### Calculate Raster Band Statistics with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The stats function computes statistical measures (e.g., median, min, max, sum, mean, modes, histogram) for each band of a georaster. It accepts a georaster, an optional geometry for region of interest, calculation options, a filter function, and extra options for virtual resampling and rescaling. ```javascript const stats = await geoblaze.stats("https://example.org/imagery.tif", geometry); /* Returns: [ { 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, ... } } ] */ ``` ```javascript const stats = await geoblaze.stats("https://example.org/imagery.tif", geometry, { stats: ["count", "min", "max", "sum"] }, undefined, { vrm: [2, 2], rescale: true }); /* Returns: [ { count: 4.25, min: 0, max: 5, sum: 6.75 } ] */ ``` -------------------------------- ### Perform Pixel-wise Raster Calculations with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The rasterCalculator function applies a user-defined JavaScript function to each pixel of a georaster. The function receives pixel values from specified bands as arguments and returns a new GeoRaster with the computed results. ```javascript // 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); ``` -------------------------------- ### Calculate Maximum Values for Raster Bands Source: https://context7.com/geotiff/geoblaze/llms.txt Determines the maximum pixel value for each band in a GeoTIFF raster. Supports calculating the global maximum or within a specified bounding box. The function can also process multi-band imagery. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/temperature.tif"; // Get maximum temperature across entire raster const globalMax = await geoblaze.max(url); console.log(globalMax); // [42.5] // Get maximum within bounding box const bbox = [-120, 35, -115, 40]; const regionMax = await geoblaze.max(url, bbox); console.log(regionMax); // [38.2] // Multi-band example with NAIP imagery const naipUrl = "https://example.org/naip.tif"; const maxValues = await geoblaze.max(naipUrl); console.log(maxValues); // [231, 242, 254, 255] - max for each band ``` -------------------------------- ### Identify Pixel Value at a Point with GeoBlaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The identify function retrieves the pixel value(s) from a georaster at a given point geometry. The georaster and the point must share the same Spatial Reference System. The geometry can be provided as an array, GeoJSON object, or string. ```javascript // 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] ``` -------------------------------- ### Identify Pixel Values at Point with Geoblaze Source: https://context7.com/geotiff/geoblaze/llms.txt Retrieves pixel values from a GeoTIFF at a specific geographic coordinate using the geoblaze library. It accepts coordinates as an array [longitude, latitude] or a GeoJSON Point object. This function is useful for extracting data at discrete locations. ```javascript import geoblaze from 'geoblaze'; const url = "https://s3.amazonaws.com/geoblaze/wildfires.tiff"; // Identify using coordinate array [longitude, latitude] const cityOfRedding = [-122.366667, 40.583333]; const values = await geoblaze.identify(url, cityOfRedding); console.log(values); // [76, 76, 68] - red, green, blue values // Identify using GeoJSON Point const point = { type: "Point", coordinates: [-122.366667, 40.583333] }; const pointValues = await geoblaze.identify(url, point); console.log(pointValues); // [76, 76, 68] // Identify elevation at specific location const elevUrl = "https://example.org/elevation.tif"; const mountainPeak = [-105.6444, 39.1178]; // Pikes Peak coordinates const elevation = await geoblaze.identify(elevUrl, mountainPeak); console.log(elevation); // [4302] - elevation in meters ``` -------------------------------- ### Calculate Raster Range with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The range function calculates the minimum and maximum pixel values for each band in a georaster. It accepts a georaster input and an optional geometry to limit the calculation to a specific area. A filter function can also be provided to include/exclude pixels based on their values. It returns an array of ranges, one for each band. ```javascript const url = "https://example.org/naif.tif"; const ranges = await geoblaze.range(url, geometry); // ranges is [red, green, blue, nir] // Example output: [231, 234, 229, 0] ``` -------------------------------- ### Calculate Sum of Pixel Values for Raster Bands Source: https://context7.com/geotiff/geoblaze/llms.txt Computes the sum of all pixel values for each band in a GeoTIFF raster. This function supports geometry-based filtering, value filtering, and advanced options like virtual resampling and rescaling for accurate area-based calculations. ```javascript import geoblaze from 'geoblaze'; // Basic sum calculation const url = "https://example.org/naip.tif"; const sums = await geoblaze.sum(url); console.log(sums); // [217461, 21375, 57312, 457125] // Sum with geometry filtering const polygon = { type: "Polygon", coordinates: [[[-122.4, 40.5], [-122.4, 40.6], [-122.3, 40.6], [-122.3, 40.5], [-122.4, 40.5]]] }; const polygonSum = await geoblaze.sum(url, polygon); console.log(polygonSum); // [12456, 8234, 9456, 15678] // Sum only positive elevation values const elevUrl = "https://example.org/elevation.tif"; const aboveSeaLevel = await geoblaze.sum(elevUrl, null, value => value >= 0); console.log(aboveSeaLevel); // [2131] // Population density calculation with virtual resampling // Divide each pixel into 100x100 subpixels for accurate population estimates const popUrl = "https://example.org/population.tif"; const totalPop = await geoblaze.sum(popUrl, polygon, undefined, { vrm: [100, 100], rescale: true }); console.log(totalPop); // [3154.25425] - estimated population in geometry ``` -------------------------------- ### Calculate Median Values for Raster Bands Source: https://context7.com/geotiff/geoblaze/llms.txt Computes the median pixel value for each band in a GeoTIFF raster. This function provides a robust measure of central tendency, unaffected by outliers. It supports calculations over the entire raster, within a polygon, or with specific value filtering. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/landsat.tif"; // Calculate median for all bands const medians = await geoblaze.median(url); console.log(medians); // [2156, 2834, 3142, 4567, 3892, 2341, 1456] // Calculate median within a polygon (e.g., agricultural field) const field = { type: "Polygon", coordinates: [[ [-95.5, 41.2], [-95.5, 41.3], [-95.4, 41.3], [-95.4, 41.2], [-95.5, 41.2] ]] }; const fieldMedian = await geoblaze.median(url, field); console.log(fieldMedian); // [2234, 2901, 3256, 4712, 3998, 2401, 1523] // Filter to exclude cloud-covered pixels (assuming band 0 values > 5000 indicate clouds) const clearSkyMedian = await geoblaze.median(url, null, value => value < 5000); console.log(clearSkyMedian); // [2023, 2756, 3089, 4401, 3765, 2298, 1401] ``` -------------------------------- ### Calculate Histogram of Raster Data with GeoBlaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The histogram function computes pixel value distributions for a georaster. It can operate on the entire raster or a specified geometry. Options allow for defining the measurement scale and binning strategies for ratio data. ```javascript 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" }); ``` -------------------------------- ### Calculate Median from Raster Data with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The median function computes the median value of pixels in a raster. It can operate on the entire raster or within a specified geometry. The function accepts raster data in multiple formats and returns an array of median values, one for each band. ```javascript const url = "https://example.org/naif.tif"; const medians = await geoblaze.median(url, geometry); // medians is [red, green, blue, nir] // Example output: [42, 84, 92, 94] ``` -------------------------------- ### Extract Pixel Values in JavaScript Source: https://context7.com/geotiff/geoblaze/llms.txt Retrieves raw pixel value arrays from a raster within a specified bounding box or geometry. The output can be optionally flattened into 1D arrays. This function requires a parsed georaster object and either a bounding box array or a GeoJSON polygon. Dependencies: geoblaze library, georaster object. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/naip.tif"; const georaster = await geoblaze.parse(url); // Get pixels within bounding box (returns 2D arrays) const bbox = [-122.5, 40.4, -122.2, 40.7]; const pixels = await geoblaze.get(georaster, bbox); console.log(pixels); /* [ [[125, 128, 132, ...], [130, 135, 138, ...], ...], // red band 2D array [[98, 102, 105, ...], [101, 106, 109, ...], ...], // green band 2D array [[87, 91, 94, ...], [90, 95, 98, ...], ...], // blue band 2D array [[145, 148, 152, ...], [150, 155, 158, ...], ...] // nir band 2D array ] */ // Get flattened pixel arrays const flatPixels = await geoblaze.get(georaster, bbox, true); console.log(flatPixels); /* [ [125, 128, 132, 130, 135, 138, ...], // red band flattened [98, 102, 105, 101, 106, 109, ...], // green band flattened [87, 91, 94, 90, 95, 98, ...], // blue band flattened [145, 148, 152, 150, 155, 158, ...] // nir band flattened ] */ // Get pixels within polygon const polygon = { type: "Polygon", coordinates: [[ [-122.4, 40.5], [-122.4, 40.6], [-122.3, 40.6], [-122.3, 40.5], [-122.4, 40.5] ]] }; const polygonPixels = await geoblaze.get(georaster, polygon, true); ``` -------------------------------- ### Calculate Sum of Georaster Pixels (JavaScript) Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html Calculates the sum of all pixels in a georaster, optionally within a specified geometry. This function is useful for aggregating raster data, such as calculating total population or elevation within a region. It accepts a georaster source, an optional geometry, an optional filter function, and extra options for virtual resampling. ```javascript const url = "https://example.org/naip.tif"; const results = await geoblaze.sum(url, geometry); // results is [red, green, blue, nir] // Example output: [217461, 21375, 57312, 457125] ``` ```javascript const elevation_url = "https://example.org/elevation.tif"; const results = await geoblaze.sum(elevation_url, geometry, value => value >= 0); // results is sum of all intersecting pixels at or above sea level // Example output: [2131] ``` ```javascript 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) // Example output: [3154.25425] ``` -------------------------------- ### Calculate Max Pixel Values in GeoTIFF Raster Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The max function computes the maximum pixel value for each band in a GeoTIFF raster. It accepts an optional geometry to limit the calculation to a specific area. If no geometry is provided, the maximum is calculated across all pixels for each band. The function returns an array of numbers representing the maximums for each band. ```javascript const url = "https://example.org/naif.tif"; const maxs = await geoblaze.max(url, geometry); // maxs is [red, green, blue, nir] // Example output: [231, 242, 254, 255] ``` -------------------------------- ### Calculate Raster Mean with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The mean function calculates the average pixel value for each band in a georaster. Similar to the range function, it accepts a georaster input and an optional geometry. A filter function can be applied to selectively include pixels in the mean calculation. The function returns an array containing the mean value for each band. ```javascript const url = "https://example.org/naif.tif"; const means = await geoblaze.mean(url, geometry); // means is [red, green, blue, nir] // Example output: [42, 84, 92, 94] ``` -------------------------------- ### Calculate Mode Values for Raster Bands Source: https://context7.com/geotiff/geoblaze/llms.txt Finds the most frequently occurring pixel value for each band in a GeoTIFF raster. If multiple modes exist, the function returns their mean. Calculations can be performed globally or within a specified region. ```javascript import geoblaze from 'geoblaze'; const url = "https://example.org/landcover.tif"; // Calculate mode for land cover classification const modes = await geoblaze.mode(url); console.log(modes); // [42] - class 42 is most common // Calculate mode within specific region const bbox = [-100, 35, -95, 40]; const regionMode = await geoblaze.mode(url, bbox); console.log(regionMode); // [31] - different dominant class in this region // Multi-band imagery mode const rgbUrl = "https://example.org/rgb.tif"; const rgbModes = await geoblaze.mode(rgbUrl); console.log(rgbModes); // [128, 142, 156] - most common RGB values ``` -------------------------------- ### Calculate Mode from Raster Data with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The mode function calculates the most frequent pixel value (mode) within a raster. Similar to the median function, it supports calculations over the entire raster or a defined geometry. It handles multiple raster input types and outputs an array containing the mode for each band. ```javascript const url = "https://example.org/naif.tif"; const results = await geoblaze.mode(url, geometry); // results is [red, green, blue, nir] // Example output: [42, 84, 92, 94] ``` -------------------------------- ### Calculate Raster Modes with Geoblaze Source: https://github.com/geotiff/geoblaze/blob/master/docs/index.html The modes function computes the most frequent pixel values for each band in a georaster. It can optionally filter pixels based on a provided geometry or a test function. It returns an array of arrays, where each inner array contains the mode(s) for a corresponding band. ```javascript 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]] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.