kmlLine.Rd
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 resp. Google Maps.
kmlLine(obj=NULL, kmlfile=NULL,
name="R Line", description="", col=NULL, visibility=1, lwd=1,
kmlname="", kmldescription="")
a Lines
or SpatialLinesDataFrame
object
if not NULL
the name as character string of the kml file to be written
the name of the KML line
the description of the KML line (HTML tags allowed)
the stroke color (see also Color Specification) of the KML line
if set to 1
or TRUE
specifies that the KML line should be visible after loading
the stroke width for the KML line
the name of the KML layer
the description of the KML layer (HTML tags allowed)
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).
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>
.
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 resp. footer if obj
is NULL
.
The following color specifications are allowed: 'red'
, 2
, or as hex code '#RRGGBB'
resp. '#RRGGBBAA'
for passing the alpha value.
xx <- readShapeSpatial(system.file("shapes/fylk-val-ll.shp",
package="maptools")[1], proj4string=CRS("+proj=longlat +ellps=WGS84"))
#> Warning: shapelib support is provided by GDAL through the sf and terra packages among others
#> Warning: shapelib support is provided by GDAL through the sf and terra paackages among others
#> Warning: shapelib support is provided by GDAL through the sf and terra packages among others
out <- sapply(slot(xx, "lines"), function(x) { kmlLine(x,
name=slot(x, "ID"), col="blue", lwd=1.5,
description=paste("river:", slot(x, "ID"))) })
tf <- tempfile()
kmlFile <- file(tf, "w")
tf
#> [1] "/tmp/RtmpY1blZ9/file8a34d62760c61"
cat(kmlLine(kmlname="R Test", kmldescription="<i>Hello</i>")$header,
file=kmlFile, sep="\n")
cat(unlist(out["style",]), file=kmlFile, sep="\n")
cat(unlist(out["content",]), file=kmlFile, sep="\n")
cat(kmlLine()$footer, file=kmlFile, sep="\n")
close(kmlFile)