[R-sig-Geo] convert KML file into shape file or CSV file

Alex Mandel tech_dev at wildintellect.com
Wed Dec 9 07:38:45 CET 2009

rusers.sh wrote:
> Hi all,
>   Does anybody know how to import a KML file in R and them save it as a
> shape or CSV file. Take the following KML file as an example,
> http://www.nature.com/nature/googleearth/avianflu1.kml
>   I have tried several extentions of
> ARCGIS,e.g.KML2Shape,KMLCSVConverter,KMLCSVConverter and XToolsPro, but
> unfortunately failed to do that. I didnot find a method to solve it in R.
>  If this cannot be done in R, i'd like to see your alternative method to do
> that.
>   Any help or suggestions are greatly appreciated.

The way to do it in R is with the rgdal library (install.packages("rgdal")

-- psuedo code --
writeOGR("pathtooutput",driver="ESRI Shapefile",layer=output.shp)
-- end of fake code example --

but if you have the rgdal library that means you also have GDAL/OGR
installed and could just us the command line on your system:
ogr2ogr -f "ESRI Shapefile" nameof.shp file.kml

In this particular case, I tried with the file you linked. Turns out
it's not a valid KML file, at least according to OGC standards.
After failing to get any of my GIS tools to read it I checked it using
It returns several Errors.

There's a good chance the file still works in Google Earth but nothing
else seems to be able to figure it out.


More information about the R-sig-Geo mailing list