Nth point in linestring

Supported in: Batch, Streaming

Returns the nth point in a single linestring in the geometry. Indexing is 1-based, and an index of 0 is out-of-bounds. A negative index is counted backwards from the end of the linestring, so that -1 is the last point. Returns null for any of the following conditions: geometry isn't a single linestring, a feature collection or geometry collection is provided, index is out-of-bounds, or at least one argument is null.

Expression categories: Geospatial

Declared arguments

  • Linestring - Linestring to retrieve the nth point of.
    Expression<Geometry>
  • N - Index of the point to retrieve. Indexing is 1-based, and an index of 0 is out-of-bounds. A negative index is counted backwards from the end of the linestring, so that -1 is the last point.
    Expression<Byte | Integer | Long | Short>

Output type: GeoPoint

Examples

Example 1: Base case

Argument values:

  • Linestring: linestring
  • N: n
linestringnOutput
{"type":"LineString","coordinates":[[30.0,2.0],[35.0,0.0],[50.0,3.0]]}1{
latitude: 2.0,
longitude: 30.0,
}
{"type":"LineString","coordinates":[[30.0,2.0],[35.0,0.0],[50.0,3.0]]}3{
latitude: 3.0,
longitude: 50.0,
}
{"type":"LineString","coordinates":[[45.0,9.0],[90.0,4.0],[40.0,0.0]]}-1{
latitude: 0.0,
longitude: 40.0,
}

Example 2: Null case

Argument values:

  • Linestring: linestring
  • N: n
linestringnOutput
{"type":"LineString","coordinates":[[10.0,4.0],[75.0,0.0]]}nullnull
null1null

Example 3: Edge case

Argument values:

  • Linestring: linestring
  • N: n
linestringnOutput
{"type":"MultiLineString","coordinates":[[[100.0,0.0]], [[102.0,2.0]]]}2null
{"type":"GeometryCollection","geometries":{"type":"LineString","coordinates":[[10.0,4.0]]}}1null
{"type":"LineString","coordinates":[[10.0,4.0],[75.0,0.0],[25.0,3.0]]}0null
{"type":"LineString","coordinates":[[12.0,3.0],[76.0,2.0],[98.0,8.0]]}4null
{"type":"LineString","coordinates":[[90.0,1.0],[34.0,1.0],[19.0,7.0]]}-4null