Learn R Programming

SDraw (version 2.1.13)

lineLength: Line length

Description

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

Usage

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).

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.

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).

See Also

sp::SpatialLines-class

Examples

Run this code
# NOT RUN {
# Length of Hawaii coastline, in kilometers
l <- lineLength( HI.coast ) / 1000

# }

Run the code above in your browser using DataLab