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

kmlOverlay

Create and write KML file for PNG image overlay


Description

The function is used to create and write a KML file for a PNG image overlay for Google Earth.

Usage

kmlOverlay(obj, kmlfile = NULL, imagefile = NULL, name = "R image")

Arguments

obj

a GE_SG object from GE_SpatialGrid

kmlfile

if not NULL the name of the kml file to be written

imagefile

the name of the PNG file containing the image - this should be either relative (same directory as kml file) or abosolute (fully qualified)

name

the name used to describe the image overlay in GE

Details

The function is used together with GE_SpatialGrid to wrap around the opening of a PNG graphics device, plotting code, and the closing of the device. The computed values take account of the adjustment of the actual data bounding box to an integer number of rows and columns in the image file.

The approach may be used as an alternative to writing PNG files from SpatialGrid and SpatialPixel objects in rgdal using writeGDAL, and to writing KML files using writeOGR for vector data objects. The output PNG files are likely to be very much smaller than large vector data KML files, and hinder the retrieval of exact positional information.

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

Value

x is a character vector containing the generated lines of the kml file

Author(s)

Duncan Golicher, David Forrest and Roger Bivand

See Also

Examples

opt_exask <- options(example.ask=FALSE)
qk <- SpatialPointsDataFrame(quakes[, c(2:1)], quakes)
proj4string(qk) <- CRS("+proj=longlat +ellps=WGS84")
tf <- tempfile()
SGqk <- GE_SpatialGrid(qk)
png(file=paste(tf, ".png", sep=""), width=SGqk$width, height=SGqk$height,
  bg="transparent")
par(mar=c(0,0,0,0), xaxs="i", yaxs="i")
plot(qk, xlim=SGqk$xlim, ylim=SGqk$ylim, setParUsrBB=TRUE)
dev.off()
kmlOverlay(SGqk, paste(tf, ".kml", sep=""), paste(tf, ".png", sep=""))
## Not run: 
#library(rgdal)
#qk0 <- quakes
#qk0$long <- ifelse(qk0$long <= 180, qk0$long, qk0$long-360)
#qk0a <- SpatialPointsDataFrame(qk0[, c(2:1)], qk0)
#proj4string(qk0a) <- CRS("+proj=longlat +ellps=WGS84")
#writeOGR(qk0a, paste(tf, "v.kml", sep=""), "Quakes", "KML")
#system(paste("googleearth ", tf, ".kml", sep=""))

## End(Not run)
options(example.ask=opt_exask)

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.