You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think interpolating to grids is a frequent enough use case to warrant its own function. Below is a reprex of what I'm imagining.
# Helper Function to make grid from shape# Requires that data is projected and that units are knownvars<- c("B02001_001E","B02001_003E")
test<-tidycensus::get_acs("tract", vars, output="wide", state="MO", county=510, geometry=TRUE) %>%
dplyr::transmute(black_pop=B02001_003E/B02001_001E,
tid= row_number()) %>%
sf::st_transform(102696)
make_grid<-function(.data){
# find units of objectunits<- st_crs(.data, parameters=TRUE)$units_gdal# error if not projectedif(units=="degree"){
stop("Data must be projected to interpolate to grid squares")
}
cellsize<-switch (units,
"Foot_US"= c(3280.84,3280.84), # Feet to Sq KM"Meter"= c(1000, 1000)
) # Will return NULL if no matches, need to implement more possible GDAL Units# make grid and clip to full boundary of datagrid<-sf::st_make_grid(.data, cellsize, square=TRUE) %>%
sf::st_intersection(sf::st_union(.data))
# coerce to sf/df and add unique IDgrid %<>% sf::st_sf() %>% dplyr::mutate(gid=dplyr::row_number())
return(grid)
}
grid<- make_grid(test)
out<-areal::aw_interpolate(grid, "gid", test, "tid", weight="sum", output="sf", intensive="black_pop")
Definitely needs refinement to implement, and the reason aw_interpolate is external to the function is because I could not get NSE to play nicely from within the function. Very neat too is that you can change from square to hexagons by setting square = FALSE
The text was updated successfully, but these errors were encountered:
I think I'd prefer to keep these separate, but I'd be open to included some wrapped tessellation tools - pass in a county shape file and convert it to a grid or hexagons, and then the end user could pipe that into areal::aw_interpolate(). How would that be @bransonf ?
I think interpolating to grids is a frequent enough use case to warrant its own function. Below is a reprex of what I'm imagining.
Definitely needs refinement to implement, and the reason aw_interpolate is external to the function is because I could not get NSE to play nicely from within the function. Very neat too is that you can change from square to hexagons by setting
square = FALSE
The text was updated successfully, but these errors were encountered: