fto_osmtype.R 865 Bytes
Newer Older
Jean-Marie Lepioufle's avatar
first  
Jean-Marie Lepioufle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#' fto_osmtype

#' fto_osmtype
#' @param ft_osmdata ft_osmdata
#' @param osmdir path of osm files
#' @keywords osmosm
#' @export
#' @examples
#' \dontrun{
#' fto_osmtype()
#' }
fto_osmtype <- function(ft_osmdata=NULL,osmdir){

    ft_osmdata_ <- ft_osmdata

    tmp <- lapply(1:length(ft_osmdata),function(x){
     lapply(1:length(ft_osmdata[[x]]),function(y){

         if (!is.null(ft_osmdata[[x]][[y]]$file)) {
           env <- new.env()
           load(normalizePath(file.path(osmdir,ft_osmdata[[x]][[y]]$file),mustWork = TRUE),env)

           tmp <- sapply(c("osm_points", "osm_lines","osm_polygons","osm_multilines","osm_multipolygons"),function(x){
             !is.null(get("osm_features",env)[[x]])
           })
           ft_osmdata_[[x]][[y]]$osm_type <<- names(tmp)[which(tmp)]
           rm(env)
         }
     })
    })
    return(ft_osmdata_)

}