Rasterise a network with all nodes beyond boundaries: give informative error.
This is a common mistake, for example when data contains switched coordinates. However, the error message is unhelpful.
MRE:
library(mapMCDA)
library(raster)
#> Loading required package: sp
r <- raster(nrow = 10, ncol = 10, xmn = 0, xmx = 10, ymn = 0, ymx = 10, vals = 1)
## A geonetwork with all nodes beyond boundaries
## A -> B; A -> C; A -> D
edges <- data.frame(
O = rep("A", 3),
D = LETTERS[2:4],
stringsAsFactors = FALSE
)
nodes <- data.frame(
node = LETTERS[1:4],
x = rep(c(-2, 12), times = 2),
y = c(2, 2, 11, 8)
)
gn <- geonetwork::geonetwork(edges, nodes)
plot(1, xlim = c(-5, 15), ylim = c(-5, 15), type = "n")
plot(r, add = TRUE, legend = FALSE)
plot(gn, add = TRUE)
rasterize(gn, r)
#> Point being added:
#> [1] 2
#> Error in deldir::deldir(xy[, 1], xy[, 2], rw = ext, eps = eps, suppressMsge = TRUE): Cannot find an enclosing triangle. See help for deldir.
Created on 2020-05-29 by the reprex package (v0.3.0)
Expected behaviour: Identify the error and provide an informative message for the user.