makeKMZArchive: Save the in-memory KML document to a KMZ file

Description Usage Arguments Value Author(s) See Also Examples

Description

This function is used to serialize a KML document to a file. If it is large or has references to local files, we create a KMZ file to create a compressed archive containing all the files. This can then be distributed as a single entity. Alternatively, the single document is serialized to a regular KML file.

Usage

1
2
3
4
makeKMZArchive(doc, file = docName(doc), ...,
               force = TRUE, clone = TRUE, useKMZ = NA,
                baseDir = getwd(), xpathQuery = "//Icon/href|//Icon/text()|//image[@src]",
                fixHTMLRefs = TRUE)

Arguments

doc

the in-memory KML document that is to be serialized

file

the name of the output file. If this is an object of class AsIs, we write directly to that file and do not attempt to determine if we should create a KMZ file.

...

additional parameters currently passed to saveXML.

force

a logical value that controls whether to force the search for images and create a KMZ file.

clone

a logical value controlling whether we should copy (or clone) the XML document before making any changes to it as we create a KMZ archive.

useKMZ

a logical value that controls whether to use KMZ or just KML. If this is left as NA, we determine which format to use based on whether there are external local files or if the KML document is more than 10 KiloBytes.

baseDir

a character vector. This is used when we rename local files as entries in the ZIP archive we create. The idea is possibly simplest to explain with an example. Suppose our KML document refers to an Icon file in the RKML package using the full path, e.g. /Users/duncan/Rpackages/RKML/Icons/reddot.png. We don't want this full path in the KMZ archive, but probably want Icons/reddot.png. So we want to remove the prefix /Users/duncan/Rpackages/RKML/. This parameter baseDir allows us to do this. The contents are the prefixes we want removed from the names of any local files referenced in the KML document. We can specify one or more such prefixes. The trailing / is append to the directories for you, but one can specify the values with a /.

xpathQuery

the xpath query string used to find the nodes of interest that may have references to external files.

fixHTMLRefs

a logical value that controls whether we check for references to local external files within the HTML code within description nodes. This can be quite time consuming. So this parameter allows the caller to avoid doing this search if she knows there are no external references or if she will handle them by herself, e.g. add them to the KMZ file after it is created.

Value

The name of the file that was created, a character vector of length 1.

Author(s)

Duncan Temple Lang

See Also

saveXML

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
styles = list("ball_green" =
                 list("IconStyle" = list("scale" = "0.5",
                                         "Icon" = c("href" = system.file("Icons", "greendot.png", package = "RKML"))),
                                         "BalloonStyle" = "$description"),
              "ball_red" =
                 list("IconStyle" = list("scale" = "0.5",
                                         "Icon" = c("href" = system.file("Icons", "reddot.png", package = "RKML"))),
                                         "BalloonStyle" = "$description"),
              "line_green" = list(LineStyle = list(color = I("ff8adfb2"), width = 4)),
              "line_red" = list(LineStyle = list(color = I("ff999afb"), width = 2)))

data(elephantSeal)
outDays = 44
direction = factor(c(rep("Out", outDays),
                     rep("Return", nrow(elephantSeal) - outDays)))

o = kmlTime(elephantSeal, elephantSeal$date, 
            name = format(elephantSeal$date, "%d-%m"),
            style = c("ball_green", "ball_red")[direction],
            lty = c("line_green", "line_red")[direction],
            "Elephant Seal Travel Path",
            "Elephant seal data <a href='http://www.stat.berkeley.edu/~brill'>Stewart & Brillinger</a>",
            docStyles = styles)


makeKMZArchive(o, "seal.kmz")

duncantl/RKML documentation built on May 15, 2019, 5:31 p.m.