Find the population-weighted centre of a municipality
ll_find_pop_centre.Rd
Find the population-weighted centre of a municipality
Usage
ll_find_pop_centre(
sf_location,
sf_population_grid,
power = 2,
join = sf::st_intersects,
adjusted = FALSE
)
Arguments
- power
Defaults to 2. To give more weight to cells with higher population density, raise the number of residents by the power of.
- join
Defaults to sf::st_intersects.
- adjusted
If adjusted is set to TRUE, join is ignored. The population of cells along the boundary line are weighted by the share of the cell included within the border.
Examples
ll_set_folder("~/R/")
#> [1] "~/R/"
name <- "Pinzolo"
sf_location <- ll_get_nuts_it(name = name, level = "lau", resolution = "high")
#> ℹ Source: https://www.istat.it/it/archivio/222527
#> ℹ Istat (CC-BY)
#> Warning: URL 'https://www.istat.it/storage/cartografia/confini_amministrativi/non_generalizzati/Limiti01012022.zip': status was 'SSL connect error'
#> Error in download.file(url = source_url, destfile = zip_file): cannot open URL 'https://www.istat.it/storage/cartografia/confini_amministrativi/non_generalizzati/Limiti01012022.zip'
lau_grid_name_temp <- stringr::str_c(name, "_lau_high-st_intersects")
sf_location_grid <- ll_get_population_grid(
match_sf = sf_location,
match_name = lau_grid_name_temp,
match_country = "IT",
join = sf::st_intersects
)
#> ℹ Data source population grid information: Eurostat, EFGS
#> ℹ Source: https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
#> Error in ll_get_population_grid(match_sf = sf_location, match_name = lau_grid_name_temp, match_country = "IT", join = sf::st_intersects): object 'sf_location' not found
pop_centre <- ll_find_pop_centre(
sf_location = sf_location,
sf_population_grid = sf_location_grid,
power = 2
)
#> Error in is.data.frame(x): object 'sf_location_grid' not found