No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
eefcf01
... +4 ...
4b46ae9
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
47 | 47 | #' with column names that correspond to the abundance or occurrence of |
|
48 | 48 | #' different features in each planning unit. Note that this argument |
|
49 | 49 | #' type can only be used to create problems involving a single zone. |
|
50 | - | #' * [`x = Spatial-class`][sp::Spatial-class], or |
|
51 | - | #' [`x = sf::st_sf()`][sf::st_sf()], or |
|
52 | - | #' `x = data.frame`, or |
|
50 | + | #' * `x = data.frame`, or |
|
53 | 51 | #' `x = numeric` vector, or |
|
54 | 52 | #' `x = matrix`: |
|
55 | 53 | #' `y = data.frame` object |
254 | 252 | #' add_binary_decisions() %>% |
|
255 | 253 | #' add_default_solver(verbose = FALSE) |
|
256 | 254 | #' |
|
257 | - | #' # add columns to polygon planning unit data representing the abundance |
|
258 | - | #' # of species inside them |
|
259 | - | #' sim_pu_polygons$spp_1 <- rpois(length(sim_pu_polygons), 5) |
|
260 | - | #' sim_pu_polygons$spp_2 <- rpois(length(sim_pu_polygons), 8) |
|
261 | - | #' sim_pu_polygons$spp_3 <- rpois(length(sim_pu_polygons), 2) |
|
255 | + | #' # since geo-processing can be slow for large spatial vector datasets |
|
256 | + | #' # (e.g. polygons, lines, points), it can be worthwhile to pre-process the |
|
257 | + | #' # planning unit data so that it contains columns indicating the amount of |
|
258 | + | #' # each feature inside each planning unit |
|
259 | + | #' # (i.e. each column corresponds to a different feature) |
|
260 | + | #' |
|
261 | + | #' # calculate the amount of each species within each planning unit |
|
262 | + | #' # (i.e. SpatialPolygonsDataFrame object) |
|
263 | + | #' pre_proc_data <- rij_matrix(sim_pu_polygons, sim_features) |
|
262 | 264 | #' |
|
263 | - | #' # create problem using pre-processed data when feature abundances are |
|
264 | - | #' # stored in the columns of an attribute table for a spatial vector dataset |
|
265 | - | #' p6 <- problem(sim_pu_polygons, features = c("spp_1", "spp_2", "spp_3"), |
|
266 | - | #' "cost") %>% |
|
265 | + | #' # add extra columns to the polygon (Spatial) planning unit data |
|
266 | + | #' # to indicate the amount of each species within each planning unit |
|
267 | + | #' pre_proc_data <- as.data.frame(t(as.matrix(pre_proc_data))) |
|
268 | + | #' names(pre_proc_data) <- names(sim_features) |
|
269 | + | #' sim_pu_polygons@data <- cbind(sim_pu_polygons@data, pre_proc_data) |
|
270 | + | #' |
|
271 | + | #' # create problem using the polygon (Spatial) planning unit data |
|
272 | + | #' # with the pre-processed columns |
|
273 | + | #' p6 <- problem(sim_pu_polygons, features = names(pre_proc_data), "cost") %>% |
|
267 | 274 | #' add_min_set_objective() %>% |
|
268 | 275 | #' add_relative_targets(0.2) %>% |
|
269 | 276 | #' add_binary_decisions() %>% |
|
270 | 277 | #' add_default_solver(verbose = FALSE) |
|
271 | 278 | #' |
|
272 | - | #' # alternatively one can supply pre-processed aspatial data |
|
279 | + | #' # this strategy of pre-processing columns can be used for sf objects too |
|
280 | + | #' pre_proc_data2 <- rij_matrix(sim_pu_sf, sim_features) |
|
281 | + | #' pre_proc_data2 <- as.data.frame(t(as.matrix(pre_proc_data2))) |
|
282 | + | #' names(pre_proc_data2) <- names(sim_features) |
|
283 | + | #' sim_pu_sf <- cbind(sim_pu_sf, pre_proc_data2) |
|
284 | + | #' |
|
285 | + | #' # create problem using the polygon (sf) planning unit data |
|
286 | + | #' # with pre-processed columns |
|
287 | + | #' p7 <- problem(sim_pu_sf, features = names(pre_proc_data2), "cost") %>% |
|
288 | + | #' add_min_set_objective() %>% |
|
289 | + | #' add_relative_targets(0.2) %>% |
|
290 | + | #' add_binary_decisions() %>% |
|
291 | + | #' add_default_solver(verbose = FALSE) |
|
292 | + | #' |
|
293 | + | #' # in addition to spatially explicit data, pre-processed aspatial data |
|
294 | + | #' # can also be used to create a problem |
|
295 | + | #' # (e.g. data created using external spreadsheet software) |
|
273 | 296 | #' costs <- sim_pu_polygons$cost |
|
274 | 297 | #' features <- data.frame(id = seq_len(nlayers(sim_features)), |
|
275 | 298 | #' name = names(sim_features)) |
|
276 | 299 | #' rij_mat <- rij_matrix(sim_pu_polygons, sim_features) |
|
277 | - | #' p7 <- problem(costs, features, rij_matrix = rij_mat) %>% |
|
300 | + | #' p8 <- problem(costs, features, rij_matrix = rij_mat) %>% |
|
278 | 301 | #' add_min_set_objective() %>% |
|
279 | 302 | #' add_relative_targets(0.2) %>% |
|
280 | 303 | #' add_binary_decisions() %>% |
288 | 311 | #' s5 <- solve(p5) |
|
289 | 312 | #' s6 <- solve(p6) |
|
290 | 313 | #' s7 <- solve(p7) |
|
314 | + | #' s8 <- solve(p8) |
|
291 | 315 | #' |
|
292 | 316 | #' # plot solutions for problems associated with spatial data |
|
293 | 317 | #' par(mfrow = c(3, 2), mar = c(0, 0, 4.1, 0)) |
|
294 | - | #' plot(s1, main = "raster data", axes = FALSE, box = FALSE) |
|
318 | + | #' plot(s1, main = "raster data", axes = FALSE, box = FALSE, legend = FALSE) |
|
295 | 319 | #' |
|
296 | 320 | #' plot(s2, main = "polygon data") |
|
297 | - | #' plot(s2[s2$solution_1 == 1, ], col = "darkgreen", add = TRUE) |
|
321 | + | #' plot(s2[s2$solution_1 > 0.5, ], col = "darkgreen", add = TRUE) |
|
298 | 322 | #' |
|
299 | 323 | #' plot(s3, main = "line data") |
|
300 | - | #' lines(s3[s3$solution_1 == 1, ], col = "darkgreen", lwd = 2) |
|
324 | + | #' lines(s3[s3$solution_1 > 0.5, ], col = "darkgreen", lwd = 2) |
|
301 | 325 | #' |
|
302 | 326 | #' plot(s4, main = "point data", pch = 19) |
|
303 | - | #' points(s4[s4$solution_1 == 1, ], col = "darkgreen", cex = 2, pch = 19) |
|
327 | + | #' points(s4[s4$solution_1 > 0.5, ], col = "darkgreen", cex = 2, pch = 19) |
|
304 | 328 | #' |
|
305 | - | #' plot(s5, main = "sf (polygon) data", pch = 19) |
|
306 | - | #' points(s5[s5$solution_1 == 1, ], col = "darkgreen", cex = 2, pch = 19) |
|
329 | + | #' # note that as_Spatial() is for convenience to plot all solutions together |
|
330 | + | #' plot(as_Spatial(s5), main = "sf (polygon) data", pch = 19) |
|
331 | + | #' plot(as_Spatial(s5[s5$solution_1 > 0.5, ]), col = "darkgreen", add = TRUE) |
|
307 | 332 | #' |
|
308 | - | #' plot(s6, main = "preprocessed data", pch = 19) |
|
309 | - | #' plot(s6[s6$solution_1 == 1, ], col = "darkgreen", add = TRUE) |
|
333 | + | #' plot(s6, main = "preprocessed data (polygon data)", pch = 19) |
|
334 | + | #' plot(s6[s6$solution_1 > 0.5, ], col = "darkgreen", add = TRUE) |
|
310 | 335 | #' |
|
311 | 336 | #' # show solutions for problems associated with aspatial data |
|
312 | - | #' str(s7) |
|
337 | + | #' str(s8) |
|
313 | 338 | #' } |
|
314 | 339 | #' # create some problems with multiple zones |
|
315 | 340 | #' |
4b46ae9
15d9e65
179e0a8
7122c59
db1f283
eefcf01