inla.over_sp_mesh.RdWrapper for the sp::over() method to find triangle centroids
or vertices inside sp polygon objects.
since 23.06.06 in favour of
inlabru::fm_contains() when inlabru
version >= 2.7.0.9011 is installed, and since 23.08.02 in favour of
fmesher::fm_contains() when fmesher.
inla.over_sp_mesh(x, y, type = c("centroid", "vertex"), ignore.CRS = FALSE)geometry (typically a sp::SpatialPolygons() object) for the queries
an inla.mesh() object
the query type; either 'centroid' (default, for triangle centroids),
or 'vertex' (for mesh vertices)
logical; whether to ignore the coordinate system information in x and y
(default FALSE)
A vector of triangle indices (when type is 'centroid') or
vertex indices (when type is 'vertex')
if (require("sp", quietly = TRUE)) {
# 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 = fmesher::fm_CRS("longlat_globe")
)
mesh <- inla.mesh.create(globe = 2, crs = fmesher::fm_CRS("sphere"))
## 3 vertices found in the polygon
inla.over_sp_mesh(obj, mesh, type = "vertex")
## 3 triangles found in the polygon
inla.over_sp_mesh(obj, mesh)
## Multiple transformations can lead to slightly different results due to edge cases
## 4 triangles found in the polygon
inla.over_sp_mesh(
obj,
fmesher::fm_transform(mesh, crs = fmesher::fm_crs("mollweide_norm"))
)
}
#> Warning: `inla.over_sp_mesh()` was deprecated in INLA 23.06.06.
#> ℹ Please use `fmesher::fm_contains()` instead.
#> ℹ fm_contains() is available from fmesher version 0.0.9
#> ℹ For equivalent output, use 'unlist(fm_contains(...))'
#> ℹ For more information, see
#> https://inlabru-org.github.io/fmesher/articles/inla_conversion.html
#> ℹ To silence these deprecation messages in old legacy code, set
#> `inla.setOption(fmesher.evolution.warn = FALSE)`.
#> ℹ To ensure visibility of these messages in package tests, also set
#> `inla.setOption(fmesher.evolution.verbosity = 'warn')`.
#> [1] 7 15 18 35