Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

kml_layer

Write objects to a KML connection


Description

Writes any Spatial* object (from the sp package), sfc_* or sf object (from the sf package), spatio-temporal object (from the ST-class package) or Raster* object (from the raster package) to a KML file (connection) as a separate layer. Various aesthetics, i.e. ways to represent target variables, can be set via colour, transparency, size, width, shape arguments. Their availability depends on the class of the object to plot.

Usage

kml_layer(obj, ...)

Arguments

obj

object inheriting from the Spatial* or the Raster* classes

...

additional aesthetics arguments; see details for each kml_layer function and the kml_aes function

Value

An XML object that can be further parsed to a KML file (via an open connection).

Author(s)

Pierre Roudier, Tomislav Hengl and Dylan Beaudette

See Also

Examples

library(rgdal)
data(eberg_grid)
library(sp)
library(raster)
gridded(eberg_grid) <- ~x+y
proj4string(eberg_grid) <- CRS("+init=epsg:31467")
data(SAGA_pal)
data(R_pal)
## Not run: # Plot two layers one after the other:
kml_open("eberg_grids.kml")
kml_layer(eberg_grid, colour=DEMSRT6, colour_scale=R_pal[["terrain_colors"]])
kml_layer(eberg_grid, colour=TWISRT6, colour_scale=SAGA_pal[[1]])
kml_close("eberg_grids.kml")
# print the result:
library(XML)
xmlRoot(xmlTreeParse("eberg_grids.kml"))[["Document"]]

## End(Not run)

# examples with sf
eberg_grid_sf <- sf::st_as_sf(eberg_grid)

# sfc objects
## Not run: 
kml_open("eberg_grids.kml")
kml_layer(st_geometry(eberg_grid_sf))
kml_close("eberg_grids.kml")

## End(Not run)

# sf objects
## Not run: 
kml_open("eberg_grid_sf.kml")
kml_layer(eberg_grid_sf, colour = DEMSRT6, colour_scale = R_pal[["terrain_colors"]])
kml_layer(eberg_grid_sf, colour = TWISRT6, colour_scale = SAGA_pal[[1]])
kml_close("eberg_grid_sf.kml")

## End(Not run)

plotKML

Visualization of Spatial and Spatio-Temporal Objects in Google Earth

v0.8-1
GPL
Authors
Tomislav Hengl [cre, aut], Andrea Gilardi [ctb], Pierre Roudier [ctb], Dylan Beaudette [ctb], Edzer Pebesma [ctb], Michael Blaschek [ctb]
Initial release
2021-04-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.