EVOLUTION-MANAGER
Edit File: spDistsN1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Euclidean or Great Circle distance between points</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for spDistsN1 {sp}"><tr><td>spDistsN1 {sp}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Euclidean or Great Circle distance between points</h2> <h3>Description</h3> <p>The function returns a vector of distances between a matrix of 2D points, first column longitude, second column latitude, and a single 2D point, using Euclidean or Great Circle distance (WGS84 ellipsoid) methods. </p> <h3>Usage</h3> <pre> spDistsN1(pts, pt, longlat = FALSE) spDists(x, y = x, longlat = FALSE, segments = FALSE, diagonal = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>pts</code></td> <td> <p>A matrix of 2D points, first column x/longitude, second column y/latitude, or a SpatialPoints or SpatialPointsDataFrame object</p> </td></tr> <tr valign="top"><td><code>pt</code></td> <td> <p>A single 2D point, first value x/longitude, second value y/latitude, or a SpatialPoints or SpatialPointsDataFrame object with one point only</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>A matrix of n-D points with row denoting points, first column x/longitude, second column y/latitude, or a Spatial object that has a <a href="coordinates.html">coordinates</a> method</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>A matrix of n-D points with row denoting points, first column x/longitude, second column y/latitude, or a Spatial object that has a <a href="coordinates.html">coordinates</a> method</p> </td></tr> <tr valign="top"><td><code>longlat</code></td> <td> <p>logical; if FALSE, Euclidean distance, if TRUE Great Circle (WGS84 ellipsoid) distance; if <code>x</code> is a Spatial object, longlat should not be specified but will be derived from <a href="is.projected.html">is.projected</a><code>(x)</code> </p> </td></tr> <tr valign="top"><td><code>segments</code></td> <td> <p>logical; if <code>TRUE</code>, <code>y</code> must be missing; the vector of distances between consecutive points in <code>x</code> is returned. </p> </td></tr> <tr valign="top"><td><code>diagonal</code></td> <td> <p>logical; if <code>TRUE</code>, <code>y</code> must be given and have the same number of points as <code>x</code>; the vector with distances between points with identical index is returned. </p> </td></tr> </table> <h3>Value</h3> <p><code>spDistsN1</code> returns a numeric vector of distances in the metric of the points if longlat=FALSE, or in kilometers if longlat=TRUE. </p> <p><code>spDists</code> returns a full matrix of distances in the metric of the points if longlat=FALSE, or in kilometers if longlat=TRUE; it uses <code>spDistsN1</code> in case points are two-dimensional. In case of <code>spDists(x,x)</code>, it will compute all n x n distances, not the sufficient n x (n-1). </p> <h3>Note</h3> <p>The function can also be used to find a local kilometer equivalent to a plot scaled in decimal degrees in order to draw a scale bar. </p> <h3>Author(s)</h3> <p>Roger Bivand, Edzer Pebesma</p> <h3>References</h3> <p><code>http://www.abecedarical.com/javascript/script_greatcircle.html</code></p> <h3>See Also</h3> <p><code><a href="is.projected.html">is.projected</a></code></p> <h3>Examples</h3> <pre> ll <- matrix(c(5, 6, 60, 60), ncol=2) km <- spDistsN1(ll, ll[1,], longlat=TRUE) zapsmall(km) utm32 <- matrix(c(276.9799, 332.7052, 6658.1572, 6655.2055), ncol=2) spDistsN1(utm32, utm32[1,]) dg <- spDistsN1(ll, ll[1,]) dg dg[2]/km[2] data(meuse) coordinates(meuse) <- c("x", "y") res <- spDistsN1(meuse, meuse[1,]) summary(res) p1 = SpatialPoints(cbind(1:3, 1:3)) spDists(p1) spDists(p1, p1) spDists(p1, p1, diagonal = TRUE) try(spDists(p1, p1, segments = TRUE)) spDists(p1, segments = TRUE) p2 = SpatialPoints(cbind(5:2, 2:5)) spDists(p1, p2) try(spDists(p1, p2, diagonal = TRUE)) # fails try(spDists(p1, p2, segments = TRUE)) # fails # longlat points: proj4string(p1) = "+proj=longlat +ellps=WGS84" proj4string(p2) = "+proj=longlat +ellps=WGS84" is.projected(p1) is.projected(p2) spDists(p1) spDists(p1, p1) spDists(p1, p1, diagonal = TRUE) spDists(p1, p2) try(spDists(p1, p2, diagonal = TRUE)) # fails spDists(p1, p2[1:length(p1),], diagonal = TRUE) spDists(p1, segments = TRUE) spDists(p1[0],p2[0],diagonal=TRUE) spDists(p1[0]) p1 = SpatialPoints(cbind(1:3, 1:3, 1:3)) spDists(p1) spDists(p1, p1) try(spDists(p1, p1, diagonal = TRUE)) try(spDists(p1, p1, segments = TRUE)) try(spDists(p1, segments = TRUE)) p2 = SpatialPoints(cbind(5:2, 2:5, 3:6)) spDists(p1, p2) try(spDists(p1, p2, diagonal = TRUE)) # fails try(spDists(p1, p2, segments = TRUE)) # fails </pre> <hr /><div style="text-align: center;">[Package <em>sp</em> version 1.4-2 <a href="00Index.html">Index</a>]</div> </body></html>