| grid2poly {plotKML} | R Documentation | 
Converts a "SpatialGridDataFrame" object to a polygon map with each available grid node represented with a polygon. To allow further export to KML, grid2poly will, by default, convert any projected coordinates to the lat-lon system (geographic coordinates in the WGS84 system).
grid2poly(obj, var.name = names(obj)[1], reproject = TRUE, 
    method = c("sp", "raster", "RSAGA")[1], tmp.file = TRUE, 
    saga_lib = "shapes_grid", saga_module = 3, silent = FALSE, ...)
| obj | 
 | 
| var.name | target variable column name | 
| reproject | logical; reproject coordinates to lat lon system? | 
| method | decide to convert grids to polygons either using  | 
| tmp.file | logical; specify whether to create a temporary file, or to actually write to the workding directory (in the case of SAGA GIS is used to convert grids) | 
| saga_lib | string; SAGA GIS library name | 
| saga_module | SAGA GIS module number; see  | 
| silent | logical; specifies whether to print the SAGA GIS output | 
| ... | additional arguments that can be parsed to the  | 
grid2poly is not recommended for large grids (>>10e4 pixels). Consider splitting large input grids into tiles before running grid2poly. For converting large grids to polygons consider using SAGA GIS (method = "RSAGA") instead of using the default sp method.
Tomislav Hengl
vect2rast, raster::rasterToPolygons
data(eberg_grid)
library(sp)
coordinates(eberg_grid) <- ~x+y
gridded(eberg_grid) <- TRUE
proj4string(eberg_grid) <- CRS("+init=epsg:31467")
data(SAGA_pal)
## Not run: # compare various methods:
system.time(dem_poly <- grid2poly(eberg_grid, "DEMSRT6", method = "raster"))
system.time(dem_poly <- grid2poly(eberg_grid, "DEMSRT6", method = "sp"))
system.time(dem_poly <- grid2poly(eberg_grid, "DEMSRT6", method = "RSAGA"))
## plotting large polygons in R -> not a good idea
# spplot(dem_poly, col.regions = SAGA_pal[[1]])
## visualize the data in Google Earth:
kml(dem_poly, colour_scale = SAGA_pal[[1]], colour = DEMSRT6, kmz = TRUE)
## End(Not run)