ST_SetHistogram

更新时间:
复制 MD 格式

Sets the histogram for a specified band of a raster object. Pass the histogram as a JSON string.

Syntax

raster ST_SetHistogram(raster rast, integer band, cstring histogram);

Parameters

ParameterTypeDescription
rastrasterThe raster object to update.
bandintegerThe band index, starting from 0.
histogramcstringThe histogram definition in JSON format. See Histogram JSON schema.

Histogram JSON schema

The histogram parameter accepts a JSON object with the following fields.

Top-level fields

FieldTypeDescription
approximateBOOLEANSpecifies whether to use data sampling when computing the histogram.
histsCountsINTEGER[]The bin counts. Each element is the number of pixel values that fall into the corresponding bin.
binFunctionobjectDefines how bins are calculated. See binFunction fields.

binFunction fields

FieldTypeApplies whenDescription
binFunction/typeSTRINGAlwaysThe binning strategy: linear, logarithm, or explicit.
binFunction/binTable/binValuesNUMBER[]type is explicitThe explicit list of bin boundary values.
binFunction/binRange/minValueNUMBERtype is linear or logarithmThe lower bound of the bin range.
binFunction/binRange/maxValueNUMBERtype is linear or logarithmThe upper bound of the bin range.
binFunction/binRange/outRangeSTRINGtype is linear or logarithmHow pixel values outside [minValue, maxValue] are handled. Use "include" to count them in the nearest edge bin, or "exclude" to discard them.
binFunction/binRange/binValuesNUMBER[]type is linear or logarithmThe computed bin boundary values within the range.

Choosing a bin function type

TypeWhen to use
linearBins are evenly spaced across a numeric range. Use for uniformly distributed data.
logarithmBins are spaced on a logarithmic scale. Use for data with a wide dynamic range.
explicitBin boundaries are specified directly. Use when you need irregular or custom intervals.

Examples

Example 1: Set a histogram with explicit bin boundaries

UPDATE rat
SET raster = ST_SetHistogram(
    raster,
    0,
    '{"approximate":true,"histsCounts":[1,2,3,4,5],"binFunction":{"type":"explicit","binTable":{"binValues":[1.0,2.0,3.0,4.0,5.0]}}}'
)
WHERE id = 1;

This sets the histogram for band 0 using five explicit bin boundaries. approximate is true, so data sampling is used when the histogram is computed.