inla.over_sp_mesh: Check which mesh triangles are inside a polygon

Description Usage Arguments Value Author(s) Examples

View source: R/over_sp_mesh.R

Description

Wrapper for the over method to find triangle centroids or vertices inside sp polygon objects

Usage

1
2
inla.over_sp_mesh(x, y, type = c("centroid", "vertex"),
  ignore.CRS = FALSE)

Arguments

x

geometry (typically a SpatialPolygons object) for the queries

y

an inla.mesh object

type

the query type; either 'centroid' (default, for triangle centroids), or 'vertex' (for mesh vertices)

ignore.CRS

logical; whether to ignore the coordinate system information in x and y (default FALSE)

Value

A vector of triangle indices (when type is 'centroid') or vertex indices (when type is 'vertex')

Author(s)

Haakon Bakka, bakka@r-inla.org, and Finn Lindgren finn.lindgren@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Create a polygon and a mesh
obj <- sp::SpatialPolygons(list(Polygons(list(Polygon(rbind(c(0,0),
                                                            c(50,0),
                                                            c(50,50),
                                                            c(0,50)))),
                                         ID=1)),
                           proj4string = inla.CRS("longlat"))
mesh <- inla.mesh.create(globe = 2, crs = inla.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, inla.spTransform(mesh, CRSobj=inla.CRS("mollweide")), ignore.CRS = FALSE)

## Ignoring mismatching coordinate systems is rarely useful
## 20 triangles "found in" the polygon
inla.over_sp_mesh(obj, inla.spTransform(mesh, CRSobj=inla.CRS("mollweide")), ignore.CRS = TRUE)

inbo/INLA documentation built on Dec. 6, 2019, 9:51 a.m.