Learn R Programming

plotKML (version 0.3-2)

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 http://spatialreference.org/ref/epsg/4326/{World Geodetic System of 1984 / WGS84} datum).

Usage

## S3 method for class 'SpatialPoints':
reproject(obj, CRS, \dots)
## S3 method for class 'SpatialPolygons':
reproject(obj, CRS, \dots)
## S3 method for class 'SpatialLines':
reproject(obj, CRS, \dots)
## S3 method for class 'RasterLayer':
reproject(obj, CRS, program = "raster", tmp.file = TRUE, NAflag, show.output.on.console = FALSE, \dots)
## S3 method for class 'SpatialGridDataFrame':
reproject(obj, CRS, tmp.file = TRUE, program = "raster", NAflag, show.output.on.console = FALSE, \dots)
## S3 method for class 'SpatialPixelsDataFrame':
reproject(obj, CRS, tmp.file = TRUE, program = "raster", NAflag, show.output.on.console = FALSE, \dots)
## S3 method for class 'RasterBrick':
reproject(obj, CRS)
## S3 method for class 'RasterStack':
reproject(obj, CRS)

Arguments

obj
Spatial* or Raster* object
CRS
object of class "CRS"; proj4 string
program
reprojection engine; either raster package or FWTools
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
...
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 = "FWTools" gdalwarp functionality will be initiated (otherwise it tries to reproject via the package raster). This requires that http://fwtools.maptools.org{FWTools} are installed and located from R via paths(). FWTools includes OpenEV, GDAL, MapServer, PROJ.4 and OGDI, and can be installed on Windows and Unix-type operating systems.

References

  • Raster package (http://CRAN.R-project.org/package=raster)
  • FWTools (http://fwtools.maptools.org)

See Also

paths, raster::projectRaster, rgdal::spTransform, rgdal::CRS-class

Examples

Run this code
# example with vector data:
data(eberg)
library(sp)
library(rgdal)
coordinates(eberg) <- ~X+Y
proj4string(eberg) <- CRS("+init=epsg:31467")
eberg.geo <- reproject(eberg)
# 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)
# much faster when using FWTools:
eberg_grid_ll2 <- reproject(eberg_grid25, program = "FWTools")
# optional: compare processing times:
system.time(eberg_grid_ll <- reproject(eberg_grid25[1]))
system.time(eberg_grid_ll2 <- reproject(eberg_grid25[1], program="FWTools"))

Run the code above in your browser using DataLab