library(sf)
library(tidyverse)
library(tmap)
GP Practices Classification
Packages
Loading the CAZ boundaries
<- st_read("CAZ_boundaries.gpkg") CAZ_boundaries
Reading layer `CAZ_boundaries' from data source
`C:\Users\ts18jpf\OneDrive - University of Leeds\03_PhD\00_Misc_projects\Eng-Presc-Data\CAZ_boundaries.gpkg'
using driver `GPKG'
Simple feature collection with 7 features and 1 field
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 356346.4 ymin: 99474.13 xmax: 465151.9 ymax: 565398
Projected CRS: OSGB36 / British National Grid
We will produce two buffers for each CAZ: 1 km and 10 km.
<- CAZ_boundaries |>
CAZ_buffer_1k st_buffer(1e3)
<- CAZ_boundaries |>
CAZ_buffer_5k st_buffer(5e3)
tmap_mode("view")
tm_shape(CAZ_buffer_5k)+
tm_fill("dodgerblue",alpha = 0.3)+
tm_shape(CAZ_buffer_1k)+
tm_fill("dodgerblue3",alpha = 0.3)+
tm_shape(CAZ_boundaries)+
tm_fill("darkblue")
Loading all data from previous analysis
load("all_data.RData")
Let’s classify the CAZ based on their location.
$within_CAZ <- st_intersects(all_practices_raw,CAZ_boundaries) |> vapply(length,numeric(1)) > 0
all_practices_raw$within_1km <- st_intersects(all_practices_raw,CAZ_buffer_1k) |> vapply(length,numeric(1)) > 0
all_practices_raw$within_5km <- st_intersects(all_practices_raw,CAZ_buffer_5k) |> vapply(length,numeric(1)) > 0
all_practices_raw
$location_class <- case_when(all_practices_raw$within_CAZ~"within_CAZ",
all_practices_raw$within_1km~"within_1km",
all_practices_raw$within_5km~"within_5km",
all_practices_rawTRUE~"out_CAZ")
$CAZ_index <- st_intersects(all_practices_raw,CAZ_buffer_5k) |> vapply(first,integer(1))
all_practices_raw$CAZ_name <- CAZ_buffer_5k$name[all_practices_raw$CAZ_index] all_practices_raw
Visualising the results for the classification
tmap_mode("plot")
tm_shape(all_practices_raw)+
tm_dots("location_class")
tm_shape(all_practices_raw)+
tm_dots("CAZ_name")
st_write(all_practices_raw,"practices_CAZ.gpkg",append = F)
Deleting layer `practices_CAZ' using driver `GPKG'
Writing layer `practices_CAZ' to data source `practices_CAZ.gpkg' using driver `GPKG'
Writing 11864 features with 10 fields and geometry type Point.
Saving the results as a release of the repo
system("gh release upload v0 practices_CAZ.gpkg --clobber")