masterpkgr::load_pkgs(c('data.table', 'dplyr', 'fst', 'rmapshaper', 'sf'))
tipo_area <- c(
'SZN' = 'Sezione', 'ASC' = 'Area SubComunale', 'ACE' = 'Area Censimento', 'LCT' = 'Localita',
'CMN' = 'Comune', 'PRV' = 'Provincia', 'RGN' = 'Regione', 'RPT' = 'Ripartizione', 'ITA' = 'Italia'
)
# Nota. Non c'e' relazione gerarchica fra ASC, ACE e LCT: SZN => ASC | ACE | LCT => CMN => PRV => RGN => RPT => ITA
# occorre implementare il controllo: inf < mid < sup = loc(y)
dissolvi_poligoni <- function(y, inf, sup, mid = NULL, pct = 20, save_path = file.path(bnd_path, 'rds'), verboso = FALSE){
inf <- toupper(inf)
salva = (length(y) > 1)
# sup puo' essere eliminato usando la tabella localita (anzi, deve essere implementata una funzione apposita in masterpkgr)
pct <- paste0('s', pct)
if(!is.null(mid)) lkp <- unique(read_fst(file.path(tpath, 'sezioni'), columns = c(inf, mid), as.data.table = TRUE))
for(x in y){
if(verboso) message('Processing ', tipo , ' ', x, '...')
if(is.null(mid)){
bnd <- readRDS(file.path(bnd_path, 'rds', inf, pct, x)) %>% ms_dissolve() %>% rename(!!sup := rmapshaperid) %>% mutate(!!sup := x)
} else {
bnd <- readRDS(file.path(bnd_path, 'rds', inf, pct, x)) %>% inner_join(lkp) %>% ms_dissolve(mid)
}
if(salva) simplify_bnd(bnd, x, file.path(save_path, sup)) # ==> <simplify_bnd> funzione gia' implementata
}
if(!salva) bnd
}
unisci_poligoni <- function(y, tipo, pct = 20, ritorna = TRUE, salva = NULL, save_path = file.path(bnd_path, 'rds'), verboso = FALSE){
bnd <- NULL
for(x in y){
if(verboso) message('Adding ', tipo , ' ', x, '...')
bnd <- rbind(bnd, readRDS(file.path(bnd_path, 'rds', tipo, paste0('s', pct), x)))
}
if(!is.null(salva)) simplify_bnd(bnd, salva, file.path(save_path, tipo))
if(ritorna) bnd
}
basemap(bnd = as_Spatial(bind_bnd(asc[grepl('15146', ASC), ASC], 'ACE')))
# Rinominare ASC le aree subcom che fanno parte della gerarchia (le altre MI-RM le butto ?)
# Aggiungere ASC, ACE, PRV, RGN, RPT a Sezioni
# Aggiungere PRV, RGN, RPT a Localita
# Aggiungere PRV, RGN, RPT a ASC
# ?? Dividere ASC e ACE ?
unisci_poligoni_tipo <- function(tipo, area = NULL){
switch(tipo,
'SZN' = {
},
'ASC' = {
},
'LCT' = {
},
'CMN' = {
},
'PRV' = {
},
)
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎