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

kmlLines

Create and write a KML file on the basis of a given Lines object


Description

The function is used to create and write a KML file on the basis of a given Lines object (a list of Line objects) for the usage in Google Earth and Google Maps.

Usage

kmlLines(obj=NULL, kmlfile=NULL, 
        name="R Lines", description="", col=NULL, visibility=1, lwd=1,
        kmlname="", kmldescription="")

Arguments

obj

a Lines or SpatialLinesDataFrame object

kmlfile

if not NULL the name as character string of the kml file to be written

name

the name of the KML line

description

the description of the KML line (HTML tags allowed)

col

the stroke color (see also Color Specification) of the KML line

visibility

if set to 1 or TRUE specifies that the KML line should be visible after loading

lwd

the stroke width for the KML line

kmlname

the name of the KML layer

kmldescription

the description of the KML layer (HTML tags allowed)

Details

The function is used to convert a given Lines object (a list of Line objects) or the first Lines object listed in a passed SpatialLinesDataFrame object into KML line(s). If kmlfile is not NULL the result will be written into that file. If kmlfile is NULL the generated KML lines will be returned (see also value). Function no longer uses append greatly improving performance on large objects or lists.

For a passed Lines object the function generates a <Style> tag whereby its id attribute is set to the passed object's ID.

Note that the geometries should be in geographical coordinates with datum WGS84.

The resulting KML line will be embedded in <Placemark><MultiGeometry><LineString>.

Value

x is a list with the elements style and content containing the generated lines of the KML file as character vectors if kmlfile is NULL.

y is a list with the elements header and footer representing the KML file header and footer if obj is NULL.

Color Specification

The following color specifications are allowed: 'red', 2, or as hex code '#RRGGBB' resp. '#RRGGBBAA' for passing the alpha value.

Author(s)

Hans-J. Bibiko, Jon Callahan, Steven Brey

See Also

Examples

# Maptools library required
library(maptools)
# load line object
rivers <- readShapeSpatial(system.file("shapes/fylk-val-ll.shp",
                           package="maptools")[1], proj4string=CRS("+proj=longlat +ellps=WGS84"))
# create kml file
td <- tempdir()
kmlfile <- paste(td, "rivers.kml", sep="/")
kmlLines(rivers, kmlfile = kmlfile, name = "R Lines", 
         description = "Hello!", col = "blue", visibility = 1, lwd = 1, 
         kmlname = "", kmldescription = "")

maptools

Tools for Handling Spatial Objects

v1.1-1
GPL (>= 2)
Authors
Roger Bivand [cre, aut] (<https://orcid.org/0000-0003-2392-6140>), Nicholas Lewin-Koh [aut], Edzer Pebesma [ctb], Eric Archer [ctb], Adrian Baddeley [ctb], Nick Bearman [ctb], Hans-Jörg Bibiko [ctb], Steven Brey [ctb], Jonathan Callahan [ctb], German Carrillo [ctb], Stéphane Dray [ctb], David Forrest [ctb], Michael Friendly [ctb], Patrick Giraudoux [ctb], Duncan Golicher [ctb], Virgilio Gómez Rubio [ctb], Patrick Hausmann [ctb], Karl Ove Hufthammer [ctb], Thomas Jagger [ctb], Kent Johnson [ctb], Matthew Lewis [ctb] (<https://orcid.org/0000-0003-2244-4078>), Sebastian Luque [ctb], Don MacQueen [ctb], Andrew Niccolai [ctb], Edzer Pebesma [ctb], Oscar Perpiñán Lamigueiro [ctb], Ethan Plunkett [ctb], Ege Rubak [ctb] (<https://orcid.org/0000-0002-6675-533X>), Tom Short [ctb], Greg Snow [ctb], Ben Stabler [ctb], Murray Stokely [ctb], Rolf Turner [ctb]
Initial release
2021-03-14

We don't support your browser anymore

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