Vectorizes a raster band by pixel value, returning one (geom, id, value) row per contiguous region of identical pixel values.
Syntax
setof record ST_Polygonize(
raster rast,
integer bandnumber,
cstring options,
out geom geometry,
out id integer,
out value float8
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
rast | raster | Yes | The input grid object. |
bandnumber | integer | Yes | The band to vectorize. Band numbering starts at 0. |
options | cstring | No | A JSON string with vectorization options. If omitted, defaults apply. |
Output columns
| Column | Type | Description |
|---|---|---|
geom | geometry | The polygon geometry for a contiguous pixel region. |
id | integer | A sequential identifier for each output row. |
value | float8 | The pixel value shared by all pixels in the region. |
options fields
| Field | Type | Default | Description |
|---|---|---|---|
ingoreValue | float | 0 | A pixel value to exclude from vectorization. Pixels with this value are not converted to polygons. |
ingoreValueand NoData are separate exclusion mechanisms. NoData pixels are always excluded from vectorization regardless of theingoreValuesetting. UseingoreValueto additionally exclude a specific valid pixel value (for example, background pixels with value0).
Example
The following query vectorizes band 1 of the raster in rast_table where id = 1, excluding pixels with value 0:
select ST_Polygonize(rast, 1, '{"ingoreValue":0}') from rast_table where id = 1;Input raster

Output polygons

Each output row contains a polygon geometry (geom), a row identifier (id), and the pixel value (value) for that region.