fm_contains | R Documentation |
Wrapper for the sf::st_contains()
(previously sp::over()
) method to find triangle centroids
or vertices inside sf
or sp
polygon objects
fm_contains(x, y, ...)
## S3 method for class 'Spatial'
fm_contains(x, y, ...)
## S3 method for class 'sf'
fm_contains(x, y, ...)
## S3 method for class 'sfc'
fm_contains(x, y, ..., type = c("centroid", "vertex"))
x |
geometry (typically an |
y |
an |
... |
Passed on to other methods |
type |
the query type; either |
List of vectors of triangle indices (when type
is 'centroid'
) or
vertex indices (when type
is 'vertex'
). The list has one entry per row of the sf
object.
Use unlist(fm_contains(...))
if the combined union is needed.
Haakon Bakka, bakka@r-inla.org, and Finn Lindgren finn.lindgren@gmail.com
if (TRUE &&
fm_safe_sp()) {
# Create a polygon and a mesh
obj <- sp::SpatialPolygons(
list(sp::Polygons(
list(sp::Polygon(rbind(
c(0, 0),
c(50, 0),
c(50, 50),
c(0, 50)
))),
ID = 1
)),
proj4string = fm_CRS("longlat_globe")
)
mesh <- fm_rcdt_2d_inla(globe = 2, crs = fm_crs("sphere"))
## 3 vertices found in the polygon
fm_contains(obj, mesh, type = "vertex")
## 3 triangles found in the polygon
fm_contains(obj, mesh)
## Multiple transformations can lead to slightly different results due to edge cases
## 4 triangles found in the polygon
fm_contains(
obj,
fm_transform(mesh, crs = fm_crs("mollweide_norm"))
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.