Skip to contents
library(CatalanHealthAreas)
library(terra)
#> terra 1.7.78

The package provides an easy way to get the ABS code (“Àrees Bàsiques de Salut”) of a point in longitude-latitude coordinates. The latest division of Catalonia into ABS can be found in the website of the Health Department of the Government of Catalonia.

In this vignette we are going to illustrate a few usages. Take two points in Catalonia and convert it to vector points in {terra} format:

library(CatalanHealthAreas)
library(terra)
#Point with coords  446728.283  4593529.309 has ABS 186
coords_186 <- rbind(c(446728.283,4593529.309))
# This one has ABS 362
coords_362 <- rbind(c(444000,4594000))
example_point_186<-vect(coords_186,type="points")
example_point_362<-vect(coords_362,type="points")

We can subset areas to get specific sets of areas. In order to keep the possibility to do retrospective analysis, we provide the ABS maps of 2018 and 2024:

ABS2018_map<-load_ABS_map(2018)
ABS2024_map<-load_ABS_map(2024)
example_area<-ABS2018_map[ABS2018_map$ABS_code %in% c("186","362")]

and we can plot this using the base plotting

plot(example_area)
example_set_of_points<-rbind(example_point_186,example_point_362)
points(example_set_of_points)

We can combine several areas

# Testing points with ABS(2018)
example_area<-ABS2024_map[ABS2024_map$ABS_code %in% c("186","362")]
#A plot
plot(example_area)
example_set_of_points<-rbind(example_point_186,example_point_362)
points(example_set_of_points)

Comparison of points with respect to areas can be done using the {terra} relate function:

# This should be true/false
relate(example_area,example_point_186,"intersects")
#>       [,1]
#> [1,]  TRUE
#> [2,] FALSE
# This should be false/true
relate(example_area,example_point_362,"intersects")
#>       [,1]
#> [1,] FALSE
#> [2,]  TRUE

We provide the convenience function find_ABS_code which lets the user query the ABS code of a point according to an ABS map:

find_ABS_code(ABS2018_map,example_point_362)
#> [1] "362"
find_ABS_code(ABS2024_map,example_point_362)
#> [1] "362"