lineLength: Line length

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/lineLength.r

Description

An all-R routine that computes total length of all lines in a SpatialLines* object.

Usage

1
lineLength(x, byid = FALSE)

Arguments

x

A spatial object inheriting from SpatialLines, SpatialPolygons, or SpatialPoints.

byid

Whether to return lengths of individual spatial objects (TRUE) or the sum of all length (FALSE).

Details

Provides the same answer as rgeos::gLength, but is all-R (does not require rgeos Java library) and does not fire a warning if x is un-projected (i.e., lat-long).

Value

If byid==TRUE, a vector containing the lengths of individual spatial objects (the points, lines, or polygons) is returned. If byid=FALSE, the total length of all spatial objects is returned (a single number).

If x inherits from SpatialPoints, returned value is 0. If x inherits from SpatialLines, returned value contains line lengths or the sum of line lengths in x. If x inherits from SpatialPolygons, returned value contains lengths of the perimeter of all polygons, or the sum of perimeters, in x. When x contains polygons with holes, the perimeter of the holes is included (i.e., perimeter of holes is positive, not negative).

Units of the returned value are same as units of coordinates in x. E.g., meters if coordinates in x are UTM meters, decimal degrees if coordinates in x are lat-long decimal degrees.

Author(s)

Trent McDonald

See Also

sp::SpatialLines-class

Examples

1
2
# Length of Hawaii coastline, in kilometers
l <- lineLength( HI.coast ) / 1000

SDraw documentation built on May 29, 2017, 6:14 p.m.