EVOLUTION-MANAGER
Edit File: st_nearest_feature.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: get index of nearest feature</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 st_nearest_feature {sf}"><tr><td>st_nearest_feature {sf}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>get index of nearest feature</h2> <h3>Description</h3> <p>get index of nearest feature </p> <h3>Usage</h3> <pre> st_nearest_feature(x, y) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object of class <code>sfg</code>, <code>sfc</code> or <code>sf</code></p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>object of class <code>sfg</code>, <code>sfc</code> or <code>sf</code></p> </td></tr> </table> <h3>Value</h3> <p>for each feature (geometry) in <code>x</code> the index of the nearest feature (geometry) in set <code>y</code>; empty geometries result in <code>NA</code> indexes </p> <h3>See Also</h3> <p><a href="st_nearest_points.html">st_nearest_points</a> for finding the nearest points for pairs of feature geometries </p> <h3>Examples</h3> <pre> ls1 = st_linestring(rbind(c(0,0), c(1,0))) ls2 = st_linestring(rbind(c(0,0.1), c(1,0.1))) ls3 = st_linestring(rbind(c(0,1), c(1,1))) (l = st_sfc(ls1, ls2, ls3)) p1 = st_point(c(0.1, -0.1)) p2 = st_point(c(0.1, 0.11)) p3 = st_point(c(0.1, 0.09)) p4 = st_point(c(0.1, 0.9)) (p = st_sfc(p1, p2, p3, p4)) try(st_nearest_feature(p, l)) try(st_nearest_points(p, l[st_nearest_feature(p,l)], pairwise = TRUE)) r = sqrt(2)/10 b1 = st_buffer(st_point(c(.1,.1)), r) b2 = st_buffer(st_point(c(.9,.9)), r) b3 = st_buffer(st_point(c(.9,.1)), r) circles = st_sfc(b1, b2, b3) plot(circles, col = NA, border = 2:4) pts = st_sfc(st_point(c(.3,.1)), st_point(c(.6,.2)), st_point(c(.6,.6)), st_point(c(.4,.8))) plot(pts, add = TRUE, col = 1) # draw points to nearest circle: nearest = try(st_nearest_feature(pts, circles)) if (inherits(nearest, "try-error")) # GEOS 3.6.1 not available nearest = c(1, 3, 2, 2) ls = st_nearest_points(pts, circles[nearest], pairwise = TRUE) plot(ls, col = 5:8, add = TRUE) </pre> <hr /><div style="text-align: center;">[Package <em>sf</em> version 0.9-5 <a href="00Index.html">Index</a>]</div> </body></html>