# Create a polygon and a mesh
obj <- sf::st_sfc(
sf::st_polygon(
list(rbind(
c(0, 0),
c(50, 0),
c(50, 50),
c(0, 50),
c(0, 0)
))
),
crs = fm_crs("longlat_globe")
)
mesh <- fm_rcdt_2d_inla(globe = 2, crs = fm_crs("sphere"))
## 2 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"))
)
Run the code above in your browser using DataLab