View source: R/rasterise_buildings.R
rasterise_buildings | R Documentation |
Rasterise building polygons (sf_buildings
) with reference to population (sf_pop
) and/or
land use data (sf_landuse
), if supplied. Multiple output (a list of) rasters will be generated if
building data for multiple years are present.
rasterise_buildings(
sf_buildings,
proxy_pop_density = NULL,
year = NULL,
sf_pop = NULL,
sf_landuse = NULL,
match_buildings_pop = "closest",
match_buildings_landuse = "closest",
raster_template = NULL,
dir_processing = tempdir(),
dir_export = NULL,
overwrite = TRUE,
wopt = list(gdal = c("COMPRESS=LZW")),
...
)
sf_buildings |
|
proxy_pop_density |
character. Specify column name of the building attribute that is used as an indicator of population density (e.g. building height, no. of levels). This column will be used to assign values to the output raster. If not provided, population density across all building pixels are assumed to be similar. |
year |
character. Specify column name for the year within |
sf_pop |
(optional) |
sf_landuse |
(optional) |
match_buildings_pop |
character. Type of matching between |
match_buildings_landuse |
character. Type of matching between |
raster_template |
Either a |
dir_processing |
character. Directory to get intermediate files generated in previous steps (e.g. rasterised population/land use data).
Defaults to |
dir_export |
character (optional). File path to directory to export output raster(s) to. |
overwrite |
logical. Argument passed to |
wopt |
list. Argument passed to |
... |
Other arguments passed to |
If population (sf_pop
) and/or land use data (sf_landuse
) are supplied,
their raster(s) must have been previously generated in the tempdir()
using
the functions rasterise_pop()
and rasterise_landuse()
, respectively.
Rasterised buildings will be masked away (i.e., convert pixels to NA
)
at areas with no (zero) population and/or land use data, according to the respective matching year(s).
Custom ways to match the years between datasets can be set via the helper function matchyear()
.
The argument match_buildings_pop
provides ways to match each year in the sf_pop
(if provided)
to a specific year in sf_buildings
. Building raster(s) will then be associated
with a specific population census year, and removed if there are no matching population census years.
If necessary, the argument match_buildings_landuse
provides ways to match each year in sf_buildings
with a specific year in sf_landuse
, but only if sf_pop
is not provided. This is because the main
reference point for all the datasets is sf_pop
(primary focus is the analysis of population data).
List of raster files. Zero values are converted to NA
.
## Not run:
# load data
data(pop_sgp) # population census block polygons
data(landuse_sgp) # land use polygons
# transform to projected crs
pop_sgp <- sf::st_transform(pop_sgp, sf::st_crs(32648))
landuse_sgp <- sf::st_transform(landuse_sgp, sf::st_crs(32648))
# get osm buildings based on census block polygons (year 2020)
city_boundaries <- pop_sgp %>%
dplyr::filter(year == 2020) %>%
sf::st_union() %>%
sf::st_as_sf() %>%
smoothr::fill_holes(threshold = units::set_units(1, 'km^2')) %>% # clean up
smoothr::drop_crumbs(threshold = units::set_units(1, 'km^2')) %>%
sf::st_make_valid()
buildings <- get_buildings_osm(place = city_boundaries,
date = as.Date('2021-01-01')) %>%
mutate(year = 2020)
# run function
buildings_rasters <- rasterise_buildings(buildings,
proxy_pop_density = 'levels',
year = 'year',
sf_pop = pop_sgp,
sf_landuse = landuse_sgp,
match_buildings_pop = 'closest')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.