[R-sig-Geo] writeOGR with 2+ layers in 1 KML file
Alex Mandel
tech_dev at wildintellect.com
Tue Apr 5 23:00:12 CEST 2011
On 04/05/2011 01:14 PM, David Holstius wrote:
> Hi, I would like to write two different Spatial* objects, as two different layers, to the same KML file using rgdal::writeOGR().
>
> If I do something like:
>
> > writeOGR(bar, driver="KML", dsn="foo.kml", layer="bar")
>
> ... I get a KML Document with a Folder element inside named "bar". So far, so good.
>
> But if I follow that with:
>
> > writeOGR(baz, driver="KML", dsn="foo.kml", layer="baz")
>
> ... the contents of foo.kml are obliterated and replaced with new contents. I would prefer that another Folder, named "baz", be created in "foo.kml" without erasing any other Folder elements.
>
> Is this possible? Is there a flag I didn't find? Am I doing it wrong? Many thanks in advance,
>
> Very best,
> David
>
> --
> David Holstius
> PhD Student in Environmental Health Sciences
> UC Berkeley School of Public Health
>
Are you sure you don't mean 2 kml files in one kmz?
A kmz is a zip of multiple kml files and is the common format for Google
Earth.
It sounds like you're describing the behavior that the OGR shapefile
writer has which creates a folder and writes the shp, shx, dbf, prj all
to that folder. I'm not sure that model works from kml, in particular
the dsn would need to be a folder path not a path to a specific file.
I think you need to write 2 different kml files and then zip them into a
kmz. I have no idea if there's an R package to create Zip files.
Enjoy,
Alex
More information about the R-sig-Geo
mailing list