EVOLUTION-MANAGER
Edit File: st_join.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: spatial join, spatial filter</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_join {sf}"><tr><td>st_join {sf}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>spatial join, spatial filter</h2> <h3>Description</h3> <p>spatial join, spatial filter </p> <h3>Usage</h3> <pre> st_join(x, y, join, ...) ## S3 method for class 'sf' st_join( x, y, join = st_intersects, ..., suffix = c(".x", ".y"), left = TRUE, largest = FALSE ) st_filter(x, y, ...) ## S3 method for class 'sf' st_filter(x, y, ..., .predicate = st_intersects) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object of class <code>sf</code></p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>object of class <code>sf</code></p> </td></tr> <tr valign="top"><td><code>join</code></td> <td> <p>geometry predicate function with the same profile as <a href="geos_binary_pred.html">st_intersects</a>; see details</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments passed on to the <code>join</code> or <code>.predicate</code> function, e.g. <code>prepared</code>, or a pattern for <a href="st_relate.html">st_relate</a></p> </td></tr> <tr valign="top"><td><code>suffix</code></td> <td> <p>length 2 character vector; see <a href="../../base/html/merge.html">merge</a></p> </td></tr> <tr valign="top"><td><code>left</code></td> <td> <p>logical; if <code>TRUE</code> return the left join, otherwise an inner join; see details. see also <a href="../../dplyr/html/mutate-joins.html">left_join</a></p> </td></tr> <tr valign="top"><td><code>largest</code></td> <td> <p>logical; if <code>TRUE</code>, return <code>x</code> features augmented with the fields of <code>y</code> that have the largest overlap with each of the features of <code>x</code>; see https://github.com/r-spatial/sf/issues/578</p> </td></tr> <tr valign="top"><td><code>.predicate</code></td> <td> <p>geometry predicate function with the same profile as <a href="geos_binary_pred.html">st_intersects</a>; see details</p> </td></tr> </table> <h3>Details</h3> <p>alternative values for argument <code>join</code> are: </p> <ul> <li> <p><a href="geos_binary_pred.html">st_contains_properly</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_contains</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_covered_by</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_covers</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_crosses</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_disjoint</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_equals_exact</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_equals</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_is_within_distance</a> </p> </li> <li> <p><a href="st_nearest_feature.html">st_nearest_feature</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_overlaps</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_touches</a> </p> </li> <li> <p><a href="geos_binary_pred.html">st_within</a> </p> </li> <li><p> any user-defined function of the same profile as the above </p> </li></ul> <p>A left join returns all records of the <code>x</code> object with <code>y</code> fields for non-matched records filled with <code>NA</code> values; an inner join returns only records that spatially match. </p> <h3>Value</h3> <p>an object of class <code>sf</code>, joined based on geometry </p> <h3>Examples</h3> <pre> a = st_sf(a = 1:3, geom = st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3)))) b = st_sf(a = 11:14, geom = st_sfc(st_point(c(10,10)), st_point(c(2,2)), st_point(c(2,2)), st_point(c(3,3)))) st_join(a, b) st_join(a, b, left = FALSE) # two ways to aggregate y's attribute values outcome over x's geometries: st_join(a, b) %>% aggregate(list(.$a.x), mean) library(dplyr) st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y)) # example of largest = TRUE: nc <- st_transform(st_read(system.file("shape/nc.shp", package="sf")), 2264) gr = st_sf( label = apply(expand.grid(1:10, LETTERS[10:1])[,2:1], 1, paste0, collapse = " "), geom = st_make_grid(st_as_sfc(st_bbox(nc)))) gr$col = sf.colors(10, categorical = TRUE, alpha = .3) # cut, to check, NA's work out: gr = gr[-(1:30),] nc_j <- st_join(nc, gr, largest = TRUE) # the two datasets: opar = par(mfrow = c(2,1), mar = rep(0,4)) plot(st_geometry(nc_j)) plot(st_geometry(gr), add = TRUE, col = gr$col) text(st_coordinates(st_centroid(gr)), labels = gr$label) # the joined dataset: plot(st_geometry(nc_j), border = 'black', col = nc_j$col) text(st_coordinates(st_centroid(nc_j)), labels = nc_j$label, cex = .8) plot(st_geometry(gr), border = 'green', add = TRUE) par(opar) </pre> <hr /><div style="text-align: center;">[Package <em>sf</em> version 0.9-5 <a href="00Index.html">Index</a>]</div> </body></html>