Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

calcLength

Calculate the Length of Polylines


Description

Calculate the length of polylines found in a PolySet.

Usage

calcLength (polys, rollup = 3, close = FALSE)

Arguments

polys

PolySet to use.

rollup

level of detail in the results; 1 = PIDs only, summing the lengths of each SID within each PID, and 3 = no roll-up. Note: rollup 2 has no meaning in this function and, if specified, will be reset to 3.

close

Boolean value; if TRUE, include the distance between each polygon's last and first vertex, if necessary.

Details

If rollup equals 1, the results contain an entry for each unique PID only. Setting it to 3 prevents roll-up, and they contain an entry for each unique (PID, SID).

If the projection attribute equals "LL", this routine uses Great Circle distances to compute the surface length of each polyline. In doing so, the algorithm simplifies Earth to a sphere.

If the projection attribute equals "UTM" or 1, this routine uses Pythagoras' Theorem to calculate lengths.

Value

PolyData with columns PID, SID (may be missing), and length. If projection equals "UTM" or "LL", lengths are in kilometres. Otherwise, lengths are in the same unit as the input PolySet.

Author(s)

Nicholas M. Boers, Associate Professor – Computer Science
MacEwan University, Edmonton AB
Last modified Rd: 2013-04-10

See Also

Examples

local(envir=.PBSmapEnv,expr={
  #--- load the data (if using R)
  if (!is.null(version$language) && (version$language=="R"))
    data(nepacLL,envir=.PBSmapEnv)
  #--- calculate the perimeter of Vancouver Island
  print(calcLength(nepacLL[nepacLL$PID==33, ]))
})

PBSmapping

Mapping Fisheries Data and Spatial Analysis Tools

v2.73.0
GPL (>= 2)
Authors
Jon T. Schnute [aut], Nicholas Boers [aut], Rowan Haigh [aut, cre], Alex Couture-Beil [ctb], Denis Chabot [ctb], Chris Grandin [ctb], Angus Johnson [ctb], Paul Wessel [ctb], Franklin Antonio [ctb], Nicholas J. Lewin-Koh [ctb], Roger Bivand [ctb]
Initial release
2021-01-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.