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
| Parameter | Type | Description |
|---|---|---|
rast | raster | The raster object to update. |
band | integer | The band index, starting from 0. |
histogram | cstring | The 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
| Field | Type | Description |
|---|---|---|
approximate | BOOLEAN | Specifies whether to use data sampling when computing the histogram. |
histsCounts | INTEGER[] | The bin counts. Each element is the number of pixel values that fall into the corresponding bin. |
binFunction | object | Defines how bins are calculated. See binFunction fields. |
binFunction fields
| Field | Type | Applies when | Description |
|---|---|---|---|
binFunction/type | STRING | Always | The binning strategy: linear, logarithm, or explicit. |
binFunction/binTable/binValues | NUMBER[] | type is explicit | The explicit list of bin boundary values. |
binFunction/binRange/minValue | NUMBER | type is linear or logarithm | The lower bound of the bin range. |
binFunction/binRange/maxValue | NUMBER | type is linear or logarithm | The upper bound of the bin range. |
binFunction/binRange/outRange | STRING | type is linear or logarithm | How pixel values outside [minValue, maxValue] are handled. Use "include" to count them in the nearest edge bin, or "exclude" to discard them. |
binFunction/binRange/binValues | NUMBER[] | type is linear or logarithm | The computed bin boundary values within the range. |
Choosing a bin function type
| Type | When to use |
|---|---|
linear | Bins are evenly spaced across a numeric range. Use for uniformly distributed data. |
logarithm | Bins are spaced on a logarithmic scale. Use for data with a wide dynamic range. |
explicit | Bin 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.
该文章对您有帮助吗?