Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #######################################################
- # SHINY Explorer - boundaries conversion to rds format
- #######################################################
- # load packages
- pkg <- c('rgdal', 'RMySQL', 'sp')
- invisible( lapply(pkg, require, character.only = TRUE) )
- loca.map <- c('CCG', 'LAT', 'NHSR', 'CCR', 'CTRY')
- # load additional datasets
- db_conn <- dbConnect(MySQL(), group = 'shiny', dbname = 'common')
- areas <- suppressWarnings(data.table(dbReadTable(db_conn, 'locations') ) )
- centres <- suppressWarnings(data.table(dbReadTable(db_conn, 'centres'), key = 'HSP_id') )
- dbDisconnect(db_conn)
- # load boundaries and build unique list
- boundaries <- lapply(loca.map, function(x) readOGR(shp.path, x))
- names(boundaries) <- loca.map
- for(m in loca.map){
- boundaries[[m]] <- merge(boundaries[[m]], areas[, .(ons_id, nhs_id, name)], by.x = 'id', by.y = 'ons_id')
- # boundaries[[m]] <- merge(boundaries[[m]], centres[, .(H = .N), .(ons_id = get(paste0(m, '_ons')))], by.x = 'id', by.y = 'ons_id')
- }
- # save boundaries as RDS object
- saveRDS(boundaries, paste0(data.path, 'boundaries.rds'))
- # clean and exit
- rm(list = ls())
- gc()
Advertisement
Add Comment
Please, Sign In to add comment