Skip to content

How to read or import a kml file in R

5 messages · Manuel Spínola, Hodgess, Erin, Alex Mandel

#
Hello Manuel:

Not sure what you're trying to do.  KML files display in Google Earth & Google Maps.

You can create KML files in R but not display them.

Hope this helps!

Sincerely,
Erin
#
Well that hardly seems the whole story.
rgdal package's readOGR should be able to import kml into an sp object,
which can be analyzed or plotted.

https://stat.ethz.ch/pipermail/r-sig-geo/2010-May/008370.html

I think Erin was confusing it with KMZ files which are a bundle of kml +
images(sometimes) that are hard to use anywhere but Google Earth. Though
the trick is to just unzip them and use the components individually.

Thanks,
Alex
On 03/24/2014 11:16 AM, Hodgess, Erin wrote:
#
I didn't realize that readOGR could do that.  Very cool!  Thanks for the good info.
#
Ya, there are some exceptions. ie Styling is not really supported,
though work on the OGR side is in progress on that. Also there are some
kml files that merely have urls to some web server where the kml really
is (ie exports from Google maps). These notoriously don't work with OGR
or other kml engines.

The hack is to use google earth to open them and then save them back out
to yet another kml that actually has the data (I'm oversimplifying the
steps).

http://gdal.org/ogr/ogr_formats.html

FYI, if you use the Libkml driver you might get more details than the
traditional OGR kml drivers. Libkml behaves more like google earth,
since it's also written by google.

Thanks,
Alex
On 03/24/2014 11:38 AM, Hodgess, Erin wrote: