From c6757ef6f2e0ef22dbd9309685e548b190aef61c Mon Sep 17 00:00:00 2001 From: Jordan S Read Date: Sun, 29 Oct 2017 15:38:24 -0500 Subject: [PATCH] precip cells for #11 --- scripts/process/grid_from_mask.R | 19 +++++++++++++++++++ viz.yaml | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 scripts/process/grid_from_mask.R diff --git a/scripts/process/grid_from_mask.R b/scripts/process/grid_from_mask.R new file mode 100644 index 0000000..acfe58d --- /dev/null +++ b/scripts/process/grid_from_mask.R @@ -0,0 +1,19 @@ +#' take an sf object polygon and make a grid out of it +#' +#' +process.grid_from_mask <- function(viz){ + deps <- readDepends(viz) + checkRequired(viz, c("cell_size")) + + clip_poly <- deps[['clip_poly']] + crs <- sf::st_crs(clip_poly) + cell_size <- viz[["cell_size"]] + + # this is a simple way to dissolve multiple polygons into a single mask + clip_mask <- clip_poly %>% + mutate(group=1) %>% group_by(group) %>% summarise() + cell_grid <- sf::st_make_grid(clip_mask, cellsize = cell_size, crs = crs) + cell_grid_clipped <- sf::st_intersection(cell_grid, clip_mask) + + saveRDS(cell_grid_clipped, file = viz[['location']]) +} \ No newline at end of file diff --git a/viz.yaml b/viz.yaml index 7184665..cce038d 100644 --- a/viz.yaml +++ b/viz.yaml @@ -73,5 +73,14 @@ fetch: scripts: [scripts/fetch/map_data.R , scripts/fetch/utils.R] depends: viewbox_limits process: + - + id: precip_grid + location: cache/precip_grid.rds + reader: rds + cell_size: 80000 + processor: grid_from_mask + scripts: [scripts/process/precip_cells.R] + depends: + clip_poly: "state_map_data" visualize: publish: