Check the writeOGR function in the rgdal package. Here is a simple example:
library("sp") library("rgdal") data(meuse) coordinates(meuse) <- c("x", "y") proj4string(meuse) <- CRS("+init=epsg:28992") meuse_ll <- spTransform(meuse, CRS("+proj=longlat +datum=WGS84")) writeOGR(meuse_ll["zinc"], "meuse.kml", layer="zinc", driver="KML")
Exported objects: SpatialPointsDataFrame , SpatialLinesDataFrame or SpatialPolygonsDataFrame objects defined in the sp package.
R> class(meuse) [1] "SpatialPointsDataFrame" attr(,"package") [1] "sp"
To record using the KML driver, note that the geometry must be in geographic coordinates with a WGS84 reference.
rcs
source share