predict_grid: predict_grid

Description Usage Arguments Value Examples

View source: R/predict_grid.R

Description

predict_grid allows to conveniently use the tessellation output as a model to predict values for arbitrary points. See the bleiglass JOSS paper and vignette("complete_example", "bleiglas") for an example application. attribute_grid_points_to_polygons is a helper function that does the important step of point-to-polygon attribution, which might be useful by itself.

Usage

1
2
3
predict_grid(x, prediction_grid, unit_scaling = c(1, 1, 1), ...)

attribute_grid_points_to_polygons(prediction_grid, polygon_edges)

Arguments

x

List of data.tables/data.frames with the input points that define the tessellation model:

  • id: id number that is passed to the output polygon (integer)

  • x: x-axis coordinate (numeric)

  • y: y-axis coordinate (numeric)

  • z: z-axis coordinate (numeric)

  • ...: arbitrary variables

prediction_grid

data.table/data.frame with the points that should be predicted by the tessellation model:

  • x: x-axis coordinate (numeric)

  • y: y-axis coordinate (numeric)

  • z: z-axis coordinate (numeric)

unit_scaling

passed to tessellate - see the documentation there

...

Further variables passed to pbapply::pblapply (e.g. cl)

polygon_edges

polygon points as returned by bleiglas::read_polygon_edges

Value

list of data.tables with polygon attribution and predictions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
x <- lapply(1:5, function(i) {
  current_iteration <- data.table::data.table(
    id = 1:5,
    x = c(1, 2, 3, 2, 1) + rnorm(5, 0, 0.3),
    y = c(3, 1, 4, 4, 3) + rnorm(5, 0, 0.3),
    z = c(1, 3, 4, 2, 5) + rnorm(5, 0, 0.3),
    value1 = c("Brot", "Kaese", "Wurst", "Gurke", "Brot"),
    value2 = c(5.3, 5.1, 5.8, 1.0, 1.2)
  )
  data.table::setkey(current_iteration, "x", "y", "z")
  unique(current_iteration)
})

all_iterations <- data.table::rbindlist(x)

prediction_grid <- expand.grid(
  x = seq(min(all_iterations$x), max(all_iterations$x), length.out = 10),
  y = seq(min(all_iterations$y), max(all_iterations$y), length.out = 10),
  z = seq(min(all_iterations$z), max(all_iterations$z), length.out = 5)
)

bleiglas::predict_grid(x, prediction_grid, cl = 1)

nevrome/bleiglas documentation built on Sept. 19, 2021, 3:12 p.m.