tf_raster_contour_lines; tf_raster_contour_polygons

Process a raster input to derive contour lines or regions and output as LINESTRING or POLYGON for rendering or further processing. Each has two variants:

Use the rasterizing variants if the raster table rows are not already sorted in row-major order (for example, if they represent an arbitrary 2D point cloud), or if filtering or binning is required to reduce the input data to a manageable count (to speed up the contour processing) or to smooth the input data before contour processing. If the input rows do not already form a rectilinear region, the output region will be their 2D bounding box. Many of the parameters of the rasterizing variant are directly equivalent to those of tf_geo_rasterize; see that function for details.

The direct variants require that the input rows represent a rectilinear region of pixels in nonsparse row-major order. The dimensions must also be provided, and (raster_width * raster_height) must match the input row count. The contour processing is then performed directly on the raster values with no preprocessing.

The line variants generate LINESTRING geometries that represent the contour lines of the raster space at the given interval with the optional given offset. For example, a raster space representing a height field with a range of 0.0 to 1000.0 will likely result in 10 or 11 lines, each with a corresponding contour_values value, 0.0, 100.0, 200.0 etc. If contour_offset is set to 50.0, then the lines are generated at 50.0, 150.0, 250.0, and so on. The lines can be open or closed and can form rings or terminate at the edges of the raster space.

The polygon variants generate POLYGON geometries that represent regions between contour lines (for example from 0.0 to 100.0), and from 100.0 to 200.0. If the raster space has multiple regions with that value range, then a POLYGON row is output for each of those regions. The corresponding contour_values value for each is the lower bound of the range for that region.

Rasterizing Variant

SELECT
  contour_[lines|polygons],
  contour_values
FROM TABLE(
  tf_raster_contour_[lines|polygons](
    raster => CURSOR(
      <lon>,
      <lat>,
      <value>
    ),
    agg_type => ‘<agg_type>’,
    bin_dim_meters => <bin_dim_meters>,
    neighborhood_fill_radius => <neighborhood_fill_radius>,
    fill_only_nulls => <fill_only_nulls>,
    fill_agg_type => ‘<fill_agg_type>’,
    flip_latitude => <flip_latitude>,
    contour_interval => <contour_interval>,
    contour_offset => <contour_offset>
  )
);

Direct Variant

SELECT
  contour_[lines|polygons],
  contour_values
FROM TABLE(
  tf_raster_contour_[lines|polygons](
    raster => CURSOR(
      <lon>,
      <lat>,
      <value>
    ),
    raster_width => <raster_width>,
    raster_height => <raster_height>,
    flip_latitude => <flip_latitude>,
    contour_interval => <contour_interval>,
    contour_offset => <contour_offset>
  )
);

Input Arguments

ParameterDescriptionData Types

lon

Longitude value of raster point (degrees, SRID 4326).

Column<FLOAT | DOUBLE>

lat

Latitude value of raster point (degrees, SRID 4326).

Column<FLOAT | DOUBLE> (must be the same as <lon>)

value

Raster band value from which to derive contours.

Column<FLOAT | DOUBLE>

agg_type

bin_dim_meters

neighborhood_fill_radius

fill_only_nulls

fill_agg_type

flip_latitude

Optionally flip resulting geometries in latitude (default FALSE).

(This parameter may be removed in future releases)

BOOLEAN

contour_interval

Desired contour interval. The function will generate a line at each interval, or a polygon region that covers that interval.

FLOAT/DOUBLE (must be same type as value)

contour_offset

Optional offset for resulting intervals.

FLOAT/DOUBLE (must be same type as value)

raster_width

Pixel width (stride) of the raster data.

INTEGER

raster_height

Pixel height of the raster data.

INTEGER

Output Columns

NameDescriptionData Types

contour_[lines|polygons]

Output geometries.

Column<LINESTRING | POLYGON>

contour_values

Raster values associated with each contour geometry.

Column<FLOAT | DOUBLE> (will be the same type as value)

Examples

SELECT
  contour_lines,
  contour_values
FROM TABLE(
  tf_raster_contour_lines(
    raster => CURSOR(
      SELECT
        lon,
        lat,
        elevation
      FROM
        elevation_table
    ),
    agg_type => ‘AVG’,
    bin_dim_meters => 10.0,
    neighborhood_fill_radius => 0,
    fill_only_nulls => FALSE,
    fill_agg_type => ‘AVG’,
    flip_latitude => FALSE,
    contour_interval => 100.0,
    contour_offset => 0.0
  )
);
SELECT
  contour_polygons,
  contour_values
FROM TABLE(
  tf_raster_contour_polygons(
    raster => CURSOR(
      SELECT
        lon,
        lat,
        elevation
      FROM
        elevation_table
    ),
    raster_width => 1024,
    raster_height => 1024,
    flip_latitude => FALSE,
    contour_interval => 100.0,
    contour_offset => 0.0
  )
);