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

KML

Write a KML or KMZ file


Description

Export raster data to a KML file and an accompanying PNG image file. Multi-layer objects can be used to create an animation. The function attempts to combine these into a single (and hence more convenient) KMZ file (a zip file containing the KML and PNG files).

See package plotKML for more advanced functionality

Usage

## S4 method for signature 'RasterLayer'
KML(x, filename, col=rev(terrain.colors(255)), 
     colNA=NA, maxpixels=100000, blur=1, zip='', overwrite=FALSE, ...)

## S4 method for signature 'RasterStackBrick'
KML(x, filename, time=NULL, col=rev(terrain.colors(255)), 
     colNA=NA, maxpixels=100000, blur=1, zip='', overwrite=FALSE, ...)

## S4 method for signature 'Spatial'
KML(x, filename, zip='', overwrite=FALSE, ...)

Arguments

x

Raster* object

filename

output filename

time

character vector with time lables for multilayer objects. The length of this vector should be nlayers(x) to indicate "when" or nlayers(x)+1 to indicate "begin-end"

col

color scheme to be used (see image)

colNA

The color to use for the background (default is transparent)

maxpixels

maximum number of pixels. If ncell(raster) > maxpixels, sampleRegular is used to reduce the number of pixels

blur

Integer (default=1). Higher values help avoid blurring of isolated pixels (at the expense of a png file that is blur^2 times larger)

zip

If there is no zip program on your path (on windows), you can supply the full path to a zip.exe here, in order to make a KMZ file

overwrite

logical. If TRUE, overwrite the file if it exists

...

If x is a Raster* object, additional arguments that can be passed to image

Value

None. Used for the side-effect files written to disk.

Author(s)

This function was adapted for the raster package by Robert J. Hijmans, with ideas from Tony Fischbach, and based on functions in the maptools package by Duncan Golicher, David Forrest and Roger Bivand.

Examples

## Not run: 
# Meuse data from the sp package
data(meuse.grid)
b <- rasterFromXYZ(meuse.grid)
projection(b) <- "+init=epsg:28992" 				  
# transform to longitude/latitude
p <- projectRaster(b, crs="+proj=longlat +datum=WGS84", method='ngb')
KML(p, file='meuse.kml')

## End(Not run)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

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