epiforecasts / NCoVUtils

Utility functions for the 2019-NCoV outbreak
https://epiforecasts.io/NCoVUtils/
Other
27 stars 13 forks source link

Better UK grabbing #16

Closed layik closed 4 years ago

layik commented 4 years ago

Happy to put in a PR.

df = read.csv("https://www.arcgis.com/sharing/rest/content/items/b684319181f94875a6879bbc833ca3a6/data")
class(df); names(df)
#> [1] "data.frame"
#> [1] "GSS_CD"     "GSS_NM"     "TotalCases"
# get LAs
folder = "/tmp/Counties_and_UA"
if(!dir.exists(folder)) {
  dir.create(folder)
}
url = "https://opendata.arcgis.com/datasets/658297aefddf49e49dcd5fbfc647769e_1.zip"
las_shape = list.files(folder, pattern = "shp")[1]
if(!file.exists(file.path(folder, las_shape))) {
  download.file(url, destfile = file.path(folder, "data.zip"))
  unzip(file.path(folder, "data.zip"), exdir = folder)
  las_shape = list.files(folder, pattern = "shp")[1]
}
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3
las = st_read(file.path(folder, las_shape))
#> Reading layer `Counties_and_Unitary_Authorities_December_2017_Full_Extent_Boundaries_in_UK_WGS84' from data source `/tmp/Counties_and_UA/Counties_and_Unitary_Authorities_December_2017_Full_Extent_Boundaries_in_UK_WGS84.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 217 features and 10 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -8.650007 ymin: 49.86464 xmax: 1.768912 ymax: 60.86077
#> epsg (SRID):    4326
#> proj4string:    +proj=longlat +datum=WGS84 +no_defs
m = match(tolower(df$GSS_NM), 
          tolower(las$ctyua17nm))
df = df[df$GSS_NM %in% las$ctyua17nm, ]
m = m[!is.na(m)]
stopifnot(!any(is.na(m)))
sfc = st_geometry(las[m,])
covid19 = st_as_sf(df, geom=sfc)
plot(covid19[,"TotalCases"])

Created on 2020-03-24 by the reprex package (v0.3.0)

Already in use over at eAtlas

seabbs commented 4 years ago

I think this is total UK cases and not daily estimates so not directly of use to use. Closing for now. Feel free to open if I have misunderstood.