Convert population counts per census block (polygons)
into population density grid (raster) for subsequent analyses.
Each polygon's count is divided by its area, such that the integrated
density over each census block should equal the original count.
Census data for multiple years can be processed to output a list of rasters (one raster per year).
The column name for the 'year'
in sf
must be specified, even if data does not contain multiple years
(combined data across multiple years must be in the 'long' format).
rasterise_pop(
sf,
res = 10,
census_block = NULL,
pop_count = NULL,
year = "year",
dir_processing = tempdir()
)
sf
polygons containing the population census data.
Data should be in a projected coordinate reference system (for calculation of pixel resolution).
number. Specify the pixel resolution for rasterisation (in metres). Defaults to 10
.
character. Specify column name of the census block unique identifier (e.g. name).
character. Specify column name of the population counts per census block.
character. Specify column name of the census year. Defaults to 'year'
.
character. Directory to store intermediate files. Defaults to tempdir()
.
Set to NULL
if you do not wish to export intermediate (temporary) files for subsequent processing.
List containing (1) rasterised population count per census block,
(2) rasterised population density per census block, and (3) processed polygons used to generate
these rasters. Named pop_count_rasters
, pop_density_rasters
and pop_polygons
, respectively.
List is nested if multiple years are present (one sub-list for each census year).
Zero values for population counts/density are converted to NA
. Intermediate (raster) files are exported to tempdir()
for further processing.
if (FALSE) {
data(pop_sgp)
# transform to projected crs
pop_sgp <- sf::st_transform(pop_sgp, sf::st_crs(32648))
# run function
pop_rasters <- rasterise_pop(pop_sgp,
res = 10,
census_block = "subzone_n",
pop_count = "pop_count",
year = "year")
}