tin2grid: Interpolate TIN-based mesh values to grid

Description Usage Arguments Value Note Examples

View source: R/mesh.R

Description

Linearly interpolates the values of a mesh based on irregular triangles to a regular grid.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
tin2grid(x, s, output, ...)

## S3 method for class 'data.frame'
tin2grid(
  x,
  s,
  output = c("data.frame", "list", "raster"),
  ...,
  col_x = "x",
  col_y = "y",
  col_z = "z",
  tinmat
)

## S3 method for class 't2d_geo'
tin2grid(
  x,
  s,
  output = c("data.frame", "list", "raster"),
  ...,
  v = "elevation"
)

## S3 method for class 't2d_res'
tin2grid(
  x,
  s,
  output = c("data.frame", "list", "raster"),
  ...,
  v = NULL,
  t = NULL
)

Arguments

x

Either: a data.frame with mesh coordinates and elevations; an object of class t2d_geo or t2d_res.

s

numeric value defining the resolution of the output grid.

output

character, either: "data.frame" (default), "list", or "raster" to return a raster object. If multiple variables v or timesteps t are given, a data.frame will be returned in any case.

...

Arguments passed to or from other methods.

col_x

If x is a data.frame: column with the x coordinates.

col_y

If x is a data.frame: column with the y coordinates.

col_z

If x is a data.frame: column with the mesh values.

tinmat

integer matrix of point indices (referring to x and y coordinates) defining the mesh elements (such as element triangles of a t2d_tin object).

v

character, name of the variable(s) that is/are to be extracted and interpolated (default all variables that can be found). If x is of class t2d_geo elevation will be taken by default.

t

integer, timestep(s) that is/are to be extracted and interpolated (default: all timesteps).

Value

If output == "data.frame": A data.frame with:

x or col_x

X coordinates of the output grid

y or col_y

Y coordinates of the output grid

z or col_z

Interpolated values

variable

OPTIONAL (more than one given): imported variable the current values refer to

timestep

OPTIONAL (more than one given): simulation timestep the current values refer to

If output == "list": A list with:

x

X coordinates of the output grid

y

Y coordinates of the output grid

z

Matrix with interpolated values, where z[i,j] points to coordinates x[i] and y[j]

If output == "raster": An object of class raster.

Note

If you import many variables or timesteps or the mesh is huge or s very small the resulting dataset might become excessively large (especially if output is a data.frame)!

If x is a data.frame, all input arguments referring to columns of x support quasiquotation, i.e. they can be specified by their names, quoted or unquoted, or as column position.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# plot model bathymetry with ggplot
library(raster)
library(sf)
library(tidyverse)
# t2d_geo object
bnd <- st_read(system.file("dem/boundary_lagos.gpkg", package = "telemac"))
tin_obj <- tin(list(boundary = bnd), s = 90, a = 100^2, q = 30)
dem_rast <- raster(system.file("dem/dem_merit_lagos.tif", package = "telemac"))
geo_obj <- geo(tin_obj, dem = dem_rast)
# interpolate to regular grid as df and plot
geo_df <- tin2grid(geo_obj, s = 90, output = "data.frame")
ggplot(geo_df, aes(x = x, y = y, fill = value)) +
  geom_raster() +
  coord_equal() +
  scale_fill_viridis_c()

telemac documentation built on Feb. 7, 2022, 5:06 p.m.