Learn R Programming

plotKML (version 0.8-3)

kml-methods: Write to a KML file

Description

Writes any Spatial* object (from the sp package) or Raster* object (from the raster package) to a KML file via the plotKML.fileIO environment. Various aesthetics parameters can be set via colour, alpha, size, shape arguments. Their availability depends on the class of the object to plot.

Usage

# S4 method for Raster
kml(obj, folder.name, file.name, kmz, …)
# S4 method for Spatial
kml(obj, folder.name, file.name, kmz, …)
# S4 method for STIDF
kml(obj, folder.name, file.name, kmz, …)
# S4 method for SoilProfileCollection
kml(obj, folder.name, file.name, kmz, …)
# S4 method for SpatialPhotoOverlay
kml(obj, folder.name, file.name, kmz, …)

Arguments

obj

object inheriting from the Spatial* or the Raster* classes

folder.name

character; folder name in the KML file

file.name

character; output KML file name

kmz

logical; specief whether to compress the KML file

additional aesthetics arguments (see details below)

Value

A KML file. By default parses the object name and adds a ".kml" extension.

Details

To kml you can also pass folder.name, file.name (output file name *.kml), overwrite (logical; overwrites the existing file) and kmz (logical; specifies whether to compress the kml file) arguments. Gridded objects (objects of class "SpatialGridDataFrame" or "RasterLayer" require at least one aesthetics parameter to run, usually the colour.)

See Also

kml_open, kml_aes, kml_close, kml_compress

Examples

Run this code
# NOT RUN {
# Plotting a SpatialPointsDataFrame object
library(rgdal)
data(eberg)
eberg <- eberg[runif(nrow(eberg))<.1,]
library(sp)
library(rgdal)
coordinates(eberg) <- ~X+Y
proj4string(eberg) <- CRS("+init=epsg:31467")
# }
# NOT RUN {
# Simple plot
kml(eberg, file = "eberg-0.kml")
# Plot using aesthetics
shape = "http://maps.google.com/mapfiles/kml/pal2/icon18.png"
kml(eberg, colour = SNDMHT_A, size = CLYMHT_A, 
   alpha = 0.75, file = "eberg-1.kml", shape=shape)
# }

Run the code above in your browser using DataLab