Learn R Programming

plotKML (version 0.8-3)

reproject: Methods to reproject maps to a referent coordinate system (WGS84)

Description

This wrapper function reprojects any vector or raster spatial data to some referent coordinate system (by default: geographic coordinates on the World Geodetic System of 1984 / WGS84 datum).

Usage

# S4 method for SpatialPoints
reproject(obj, CRS, …)
# S4 method for SpatialPolygons
reproject(obj, CRS, …)
# S4 method for SpatialLines
reproject(obj, CRS, …)
# S4 method for RasterLayer
reproject(obj, CRS, program = "raster", tmp.file = TRUE, 
      NAflag, show.output.on.console = FALSE, method, …)
# S4 method for SpatialGridDataFrame
reproject(obj, CRS, tmp.file = TRUE, program = "raster", 
      NAflag, show.output.on.console = FALSE, …)
# S4 method for SpatialPixelsDataFrame
reproject(obj, CRS, tmp.file = TRUE, program = "raster", 
      NAflag, show.output.on.console = FALSE, …)
# S4 method for RasterBrick
reproject(obj, CRS)
# S4 method for RasterStack
reproject(obj, CRS)

Arguments

obj

Spatial* or Raster* object

CRS

object of class "CRS"; proj4 string

program

reprojection engine; either raster package or GDAL

tmp.file

logical; specifies whether to create a temporary file or not

NAflag

character; missing value flag

show.output.on.console

logical; specifies whether to print the progress

method

character; resampling method e.g."bilinear"

arguments evaluated in the context of function projectRaster from the raster package

Warning

obj needs to have a proper proj4 string (CRS), otherwise reproject will not run.

Details

In the case of raster and/or gridded maps, by selecting program = "GDAL" gdalwarp functionality will be initiated (otherwise it tries to reproject via the package raster). This requires that GDAL are installed and located from R via paths().

References

See Also

paths, projectRaster, spTransform, CRS-class

Examples

Run this code
# NOT RUN {
## example with vector data:
data(eberg)
library(sp)
library(rgdal)
coordinates(eberg) <- ~X+Y
proj4string(eberg) <- CRS("+init=epsg:31467")
eberg.geo <- reproject(eberg)
# }
# NOT RUN {
## example with raster data:
data(eberg_grid25)
gridded(eberg_grid25) <- ~x+y
proj4string(eberg_grid25) <- CRS("+init=epsg:31467")
## reproject to geographical coords (can take few minutes!):
eberg_grid_ll <- reproject(eberg_grid25[1])
## much faster when using GDAL:
eberg_grid_ll2 <- reproject(eberg_grid25[1], program = "GDAL")
## optional: compare processing times:
system.time(eberg_grid_ll <- reproject(eberg_grid25[1]))
system.time(eberg_grid_ll2 <- reproject(eberg_grid25[1], program="GDAL"))
# }

Run the code above in your browser using DataLab