This function is called by the resp_edit module and merges response data from a spreadsheet with boundary data into an sf object

resp_edit(shape, poly, type, logger = NULL)

Arguments

shape

sf. The sf object to be edited

poly

matrix. Containing latitude and longitude columns

type

character. Either inside or outside to determine whether the polygons to keep are those inside or outside of the polygon

logger

Stores all notification messages to be displayed in the Log Window. Insert the logger reactive list here for running in shiny, otherwise leave the default NULL

Value

an sf object

Author

Simon Smart simon.smart@cantab.net

Examples

polygons <- list()
for(i in 1:3) {
  row <- ceiling(i/10)
  col <- ifelse(i %% 10 != 0, i %% 10, 10)
  xmin = 2*(col - 1); xmax = 2*col; ymin = 2*(row - 1); ymax = 2*row
  polygons[[i]] <- list(cbind(c(xmin, xmax, xmax, xmin, xmin),
                             c(ymax, ymax, ymin, ymin, ymax)))
}

polys <- lapply(polygons, sf::st_polygon)
shape <- sf::st_sf(data.frame(area = c("A", "B", "C")), geometry = polys)

x_min <- 3
x_max <- 7
y_min <- -1
y_max <- 3
crop_matrix <- matrix(c(x_min, x_min, x_max, x_max, x_min,
                        y_min, y_max, y_max, y_min, y_min), ncol = 2)

sf::st_crs(shape) <- 4326
outside_shape <- resp_edit(shape, crop_matrix, "outside")
#> although coordinates are longitude/latitude, st_covered_by assumes that they
#> are planar
inside_shape <- resp_edit(shape, crop_matrix, "inside")
#> although coordinates are longitude/latitude, st_covered_by assumes that they
#> are planar