Skip to content
Prev 22330 / 29559 Next

writeOGR with 2+ layers in 1 KML file

David Holstius wrote

            

        
        
Since kml is essentially xml, one can create multiple files then combine
them manually, provided each file has the same structure...

... something like... 

mergeKML <- function(filename, x = list() ) { 
	require(XML)
	doc <- xmlRoot(xmlTreeParse(x[[1]], getDTD=F))
	for(i in 2:length(x)){
		y <- xmlRoot(xmlTreeParse(x[[i]]))
		doc[["Document"]][[i+1]] <- y[["Document"]][["Folder"]]
		doc[["Document"]][[i+2]] <- y[["Document"]][["Schema"]]
		}
	saveXML(doc, file= filename)
}
	
writeOGR(bar, driver="KML", dsn="foo.kml", layer="bar")
writeOGR(baz, driver="KML", dsn="baz.kml", layer="baz")
mergeKML('out.kml', list('foo.kml','baz.kml') )


-Steve




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/writeOGR-with-2-layers-in-1-KML-file-tp6243676p7587788.html
Sent from the R-sig-geo mailing list archive at Nabble.com.