Skip to content

Commit

Permalink
precip cells for USGS-VIZLAB#11
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan S Read committed Oct 29, 2017
1 parent 7d12dc0 commit c6757ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/process/grid_from_mask.R
Original file line number Diff line number Diff line change
@@ -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']])
}
9 changes: 9 additions & 0 deletions viz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

0 comments on commit c6757ef

Please sign in to comment.