Advertisement
lvalnegri

test_op_poligoni

Mar 19th, 2021 (edited)
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.55 KB | None | 0 0
  1. masterpkgr::load_pkgs(c('data.table', 'dplyr', 'fst', 'rmapshaper', 'sf'))
  2.  
  3. tipo_area <- c(
  4.     'SZN' = 'Sezione', 'ASC' = 'Area SubComunale', 'ACE' = 'Area Censimento', 'LCT' = 'Localita',
  5.     'CMN' = 'Comune', 'PRV' = 'Provincia', 'RGN' = 'Regione', 'RPT' = 'Ripartizione', 'ITA' = 'Italia'
  6. )
  7. # Nota. Non c'e' relazione gerarchica fra ASC, ACE e LCT: SZN => ASC | ACE | LCT  => CMN => PRV => RGN => RPT => ITA
  8.  
  9. # occorre implementare il controllo: inf < mid < sup = loc(y)
  10. dissolvi_poligoni <- function(y, inf, sup, mid = NULL, pct = 20, save_path = file.path(bnd_path, 'rds'), verboso = FALSE){
  11.     inf <- toupper(inf)
  12.     salva = (length(y) > 1)
  13.     # sup puo' essere eliminato usando la tabella localita (anzi, deve essere implementata una funzione apposita in masterpkgr)
  14.     pct <- paste0('s', pct)
  15.     if(!is.null(mid)) lkp <- unique(read_fst(file.path(tpath, 'sezioni'), columns = c(inf, mid), as.data.table = TRUE))
  16.     for(x in y){
  17.         if(verboso) message('Processing ', tipo , ' ', x, '...')
  18.         if(is.null(mid)){
  19.             bnd <- readRDS(file.path(bnd_path, 'rds', inf, pct, x)) %>% ms_dissolve() %>% rename(!!sup := rmapshaperid) %>% mutate(!!sup := x)
  20.         } else {
  21.             bnd <- readRDS(file.path(bnd_path, 'rds', inf, pct, x)) %>% inner_join(lkp) %>% ms_dissolve(mid)
  22.         }
  23.         if(salva) simplify_bnd(bnd, x, file.path(save_path, sup))            # ==> <simplify_bnd> funzione gia' implementata
  24.     }
  25.     if(!salva) bnd
  26. }
  27.  
  28.  
  29.  
  30.  
  31. unisci_poligoni <- function(y, tipo, pct = 20, ritorna = TRUE, salva = NULL, save_path = file.path(bnd_path, 'rds'), verboso = FALSE){
  32.     bnd <- NULL
  33.     for(x in y){
  34.       if(verboso) message('Adding ', tipo , ' ', x, '...')
  35.       bnd <- rbind(bnd, readRDS(file.path(bnd_path, 'rds', tipo, paste0('s', pct), x)))
  36.     }
  37.     if(!is.null(salva)) simplify_bnd(bnd, salva, file.path(save_path, tipo))
  38.     if(ritorna) bnd
  39. }
  40.  
  41.  
  42.  
  43. basemap(bnd = as_Spatial(bind_bnd(asc[grepl('15146', ASC), ASC], 'ACE')))
  44.  
  45.  
  46. # Rinominare ASC le aree subcom che fanno parte della gerarchia (le altre MI-RM le butto ?)
  47. # Aggiungere ASC, ACE, PRV, RGN, RPT a Sezioni
  48. # Aggiungere PRV, RGN, RPT a Localita
  49. # Aggiungere PRV, RGN, RPT a ASC
  50. # ?? Dividere ASC e ACE ?
  51.  
  52.  
  53. unisci_poligoni_tipo <- function(tipo, area = NULL){
  54.     switch(tipo,
  55.         'SZN' = {
  56.            
  57.         },
  58.        
  59.         'ASC' = {
  60.          
  61.         },
  62.        
  63.         'LCT' = {
  64.          
  65.         },
  66.        
  67.         'CMN' = {
  68.          
  69.         },
  70.        
  71.         'PRV' = {
  72.          
  73.         },
  74.        
  75.     )
  76.  
  77. }
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement