Share via


st_pointn function

Applies to: check marked yes Databricks Runtime 17.1 and above

Important

This feature is in Public Preview.

Returns the n-th point from the input linestring GEOGRAPHY or GEOMETRY.

Syntax

st_pointn ( geoExpr, indexExpr )

Arguments

  • geoExpr: A GEOGRAPHY or GEOMETRY value representing a linestring.
  • indexExpr: An INTEGER value indicating the 1-based position in the linestring of the point that should be returned.

Returns

A value of type GEOGRAPHY or GEOMETRY, representing the point at the indexExpr-th position of the input linestring.

The SRID value of the output point is equal to that of the input GEOGRAPHY or GEOMETRY value.

The dimension of the output point is the same as that of the input GEOGRAPHY or GEOMETRY value.

The function returns NULL if any of the inputs is NULL.

Error conditions

  • If the value of geoExpr is not a linestring, the function returns ST_INVALID_ARGUMENT_TYPE.
  • If the value of geoExpr is an empty linestring, the function returns ST_INVALID_ARGUMENT.
  • If the absolute value of the value of indexExpr is 0 or larger than the number of points in the linestring, the function returns ST_INVALID_INDEX_VALUE

Examples

-- Returns the third point of the linestring counting from the left.
> SELECT st_astext(st_pointn(st_geomfromtext('LINESTRING(1 2,3 4,5 6)'), 3))
  POINT(5 6)
-- Returns the third point of the linestring counting from the right.
> SELECT st_astext(st_pointn(st_geogfromtext('LINESTRING(1 2,3 4,5 6)'), -3))
  POINT(1 2)