Converts meshblock data, a meshblock sf object and a grid sf object to grid sf object with density.
gridify_mb_data(data, data_id_var, data_vars_vctr, shp, shp_id_var, grid)
data | A dataframe of meshblock level data. Required input. |
---|---|
data_id_var | An unquoted variable of the the meshblock id of the meshblock data. Required input. |
data_vars_vctr | A quoted character vector of the meshblock columns that you want to gridify. Required input. |
shp | A sf object of the meshblock level shapes. Note for APS data, use a shp year after the APS year for a better join. Required input. |
shp_id_var | An unquoted variable of the the meshblock id of the meshblock shapes. Required input. |
grid | A sf object of a grid. E.g. er.helpers::nz_grid_hex_346. Required input. |
A sf object with estimated grid totals and densities for the var in the input data.
if (FALSE) { agdir <- "~/Network-Shares/U-Drive-SAS-03BAU/IndLabr/Bus Infra & Performance/Agriculture/Ag_Secure/" data <- haven::read_sas(paste0(agdir, "2017/all_linecodes_perturbed_final.sas7bdat")) data <- data %>% select(id = CAR_Meshblock, dairy = APS_TotDairy, beef = APS_TotBeef) shp <- get_feature_class("MB2018_V1_00", epsg = 2193) shp <- shp %>% select(id = mb2018_v1_00) grid <- er.helpers::nz_grid_hex_346 aps_grid_17 <- gridify_mb_data(data = data, data_id_var = id, data_vars_vctr = c("dairy", "beef"), shp = shp, shp_id_var = id, grid = er.helpers::nz_grid_hex_346) leaflet_sf_col(aps_grid_17, dairy_density_per_km2, title = "Dairy density, 2017") leaflet_sf_col(aps_grid_17, beef_density_per_km2, title = "Beef density, 2017") }