Skip to contents

Utility functions for accessing coordinates from a geometry.

Usage

coord_n(x, n)

n_coords(x)

coord_first(x)

coord_last(x)

Arguments

x

an object of class rsgeo

n

the index position of the coordinate

Value

an object of class rs_POINT. Whereas n_coords() returns an integer vector of the same length as x.

Details

  • n_coords returns the total number of coordinates in a geometry

  • coord_first() returns the first coordinate in a geometry

  • coord_last() returns the last coordinate in a geometry

  • coord_n() returns the nth coordinate in a geometry

Examples

lines <- geom_linestring(1:10, 1:10)
n_coords(lines)
#> [1] 10
coord_first(lines)
#> <rs_LINESTRING[1]>
#> [1] Point(Coord { x: 1.0, y: 1.0 }))
coord_last(lines)
#> <rs_LINESTRING[1]>
#> [1] Point(Coord { x: 10.0, y: 10.0 }))
coord_n(lines, 5)
#> <rs_LINESTRING[1]>
#> [1] Point(Coord { x: 5.0, y: 5.0 }))