Read and write kmls to

Dear all,
How can I read kmls from subdirectories and write them into a new single folder? I tried to do that using a loop, but it didn't work.

setwd("old_dir")

ls = list.files()
for(i in ls){
  rs=list.files(paste0(getwd(),"/",i),pattern="kml$",full.names=T)
  my_data = lapply(rs, readOGR) 
  ss = list(my_data, makeUniqueIDs = T) %>% 
    flatten() %>% 
    do.call(rbind, .)
  writeOGR(ss, dsn= "new_dir", layer="polygon", driver="KML")
}

As we can't rerun your example, can you say what does not work exactly ?

After I create a list of polygons from different sub directories and specify new single directory, I use the writeOGR function to copy and paste each single polygon to the new directory, but it is only write one polygon to the new directory.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.