sf (version 0.5-2)

geos_measures: Compute distance between pairs of geometries

Description

Compute Euclidian or great circle distance between pairs of geometries

Usage

st_area(x)

st_length(x, dist_fun = geosphere::distGeo)

st_distance(x, y, dist_fun)

Arguments

x

object of class sf, sfc or sfg

dist_fun

function to be used for great circle distances of geographical coordinates; for unprojected (long/lat) data, this should be a distance function of package geosphere, or compatible to that; it defaults to distGeo in that case; for other data metric lengths are computed.

y

object of class sf, sfc or sfg, defaults to x

Value

If the coordinate reference system of x was set, these functions return values with unit of measurement; see units.

st_area returns the area of a geometry, in the coordinate reference system used; in case x is in degrees longitude/latitude, areaPolygon is used for area calculation.

st_length returns the length of a LINESTRING or MULTILINESTRING geometry, using the coordinate reference system. POINT or MULTIPOINT geometries return zero, POLYGON or MULTIPOLYGON are converted into LINESTRING or MULTILINESTRING, respectively.

st_distance returns a dense numeric matrix of dimension length(x) by length(y)

Details

function dist_fun should follow the pattern of the distance function distGeo: the first two arguments must be 2-column point matrices, the third the semi major axis (radius, in m), the third the ellipsoid flattening.

See Also

st_dimension

Examples

Run this code
# NOT RUN {
dist_vincenty = function(p1, p2, a, f) geosphere::distVincentyEllipsoid(p1, p2, a, a * (1-f), f)
line = st_sfc(st_linestring(rbind(c(30,30), c(40,40))), crs = 4326)
st_length(line)
st_length(line, dist_fun = dist_vincenty)
# }

Run the code above in your browser using DataLab