Gross disposable household income (gdhi) per head at 1km
Rasterise gdhi using UK grid at 1 km resolution.
Load packages, read data and source custom scripts
rm(list = ls())
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
path_proj <- day2day::git_path()
path_data <- file.path(path_proj, "data")
path_cleaned <- file.path(path_data, "cleaned")
path_processed <- file.path(path_data, "processed")
uk <- st_read(file.path(path_cleaned, "uk_simple.gpkg"), "union_buffer")
#> Reading layer `union_buffer' from data source `/home/rstudio/Documents/Projects/land-suitability/data/cleaned/uk_simple.gpkg' using driver `GPKG'
#> Simple feature collection with 1 feature and 0 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -5115.571 ymin: 2055.298 xmax: 660644.8 ymax: 1223625
#> projected CRS: OSGB 1936 / British National Grid
uk_bbox_1km <- read_stars(file.path(path_processed, "uk_bbox_1km.tif"))
gdhi <- st_read(file.path(path_cleaned, "gdhi_per_head.gpkg"))
#> Reading layer `gdhi_per_head' from data source `/home/rstudio/Documents/Projects/land-suitability/data/cleaned/gdhi_per_head.gpkg' using driver `GPKG'
#> Simple feature collection with 391 features and 32 fields
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -962999.8 ymin: 6422993 xmax: 196109.3 ymax: 8593782
#> projected CRS: WGS 84 / Pseudo-Mercator
Reproject to UK 1km grid
gdhi_aux <- st_transform(gdhi["gdhi_2016"], st_crs(uk_bbox_1km))
gdhi_1km <- st_rasterize(gdhi_aux, uk_bbox_1km, options = "ALL_TOUCHED=TRUE")
write_stars(gdhi_1km, file.path(path_processed, "uk_1km_gdhi.tif"))
Visualize gdhi per head
gdhi_1km <- read_stars(file.path(path_processed, "uk_1km_gdhi.tif"))
plot(gdhi_1km, reset = FALSE, main = "Gross disposable household income per head")
plot(st_transform(uk, st_crs(gdhi_1km)), add = TRUE, border = 2)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 16.008 0.573 16.599