forked from cran/plotKML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotKML.SpatialSamplingPattern.R
More file actions
56 lines (48 loc) · 1.75 KB
/
Copy pathplotKML.SpatialSamplingPattern.R
File metadata and controls
56 lines (48 loc) · 1.75 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Purpose : Generic methods to plot sampling designs
# Maintainer : Tomislav Hengl (tom.hengl@wur.nl);
# Contributions : ;
# Dev Status : Alpha
# Note : it is largely based on the spcosa classes;
setMethod("plotKML", "SpatialSamplingPattern", function(
obj,
folder.name = normalizeFilename(deparse(substitute(obj, env=parent.frame()))),
file.name = paste(folder.name, ".kml", sep=""),
colour,
kmz = get("kmz", envir = plotKML.opts),
open.kml = TRUE,
...
){
# target variable:
if(missing(colour)){
obj@sp.domain@data[,"colour"] <- obj@sp.domain@data[,1]
message("Plotting the first variable on the list")
} else {
if(is.name(colour)|is.call(colour)){
obj@sp.domain@data[,"colour"] <- eval(colour, obj@sp.domain@data)
} else {
obj@sp.domain@data[,"colour"] <- obj@sp.domain@data[,as.character(colour)]
}
}
# open the KML file for writing:
kml_open(folder.name = folder.name, file.name = file.name)
# add a description for the whole folder:
kml.out <- get("kml.out", envir=plotKML.fileIO)
description_txt <- sprintf('<description><![CDATA[%s]]></description>', obj@method)
parseXMLAndAdd(description_txt, parent=kml.out[["Document"]])
assign('kml.out', kml.out, envir=plotKML.fileIO)
# plot strata and points:
kml_layer.SpatialPolygons(obj = obj@sp.domain, colour = colour)
kml_layer.SpatialPoints(obj = obj@pattern, ...)
# close the file:
kml_close(file.name = file.name)
if (kmz == TRUE){
kml_compress(file.name = file.name)
}
# open KML file in the default browser:
if(open.kml==TRUE){
kml_View(file.name)
} else {
message(paste("Object written to:", file.name))
}
})
# end of script;