knitr::opts_chunk$set(echo = TRUE) # load libraries library(tidyverse) library(sf) library(raster) library(mapview) library(here)
Below, I show the location of the 30 points in the SBSwk1. As you pointed out, quite a few of them lie near the booundary of the BGC unit, which I don't think is ideal.
SBSwk1<- st_read(here("data-raw","dailyData_prelim","Extraction shapes","SBS wk 1_sampled.shp")) pts<- st_read(here("data-raw","dailyData_prelim","Extraction shapes","SBS_wk1_pts.shp")) SBSwk1 %>% ggplot()+ geom_sf()+ geom_sf(data=pts,aes(color="red"))+ theme(legend.position = "none")
ppt_grid<- raster(here("data-raw","dailyData_prelim","Extraction shapes","PCIC_Precipitation_grids.tif")) %>% projectRaster(crs=crs("+init=epsg:3005")) %>% crop(SBSwk1) # Plot ppt grids plot(ppt_grid) plot(SBSwk1,add=T,col=alpha("white",alpha=0.1))
As a solution, we can use the raster::extract function to extract all of the pixels
grids<- raster::extract(ppt_grid,SBSwk1,weight=TRUE,normalizeWeights=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.