EVOLUTION-MANAGER
Edit File: projectRaster.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Project a Raster object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for projectRaster {raster}"><tr><td>projectRaster {raster}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Project a Raster object</h2> <h3>Description</h3> <p>Project the values of a Raster* object to a new Raster* object with another projection (coordinate reference system, (CRS)). You can do this by providing the new projection as a single argument in which case the function sets the extent and resolution of the new object. To have more control over the transformation, and, for example, to assure that the new object lines up with other datasets, you can provide a Raster* object with the properties that the input data should be projected to. </p> <p><code>projectExtent</code> returns a RasterLayer with a projected extent, but without any values. This RasterLayer can then be adjusted (e.g. by setting its resolution) and used as a template <code>'to'</code> in <code>projectRaster</code>. </p> <h3>Usage</h3> <pre> projectRaster(from, to, res, crs, method="bilinear", alignOnly=FALSE, over=FALSE, filename="", ...) projectExtent(object, crs) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>from</code></td> <td> <p>Raster* object</p> </td></tr> <tr valign="top"><td><code>to</code></td> <td> <p>Raster* object with the parameters to which 'from' should be projected</p> </td></tr> <tr valign="top"><td><code>res</code></td> <td> <p>single or (vector of) two numerics. To, optionally, set the output resolution if 'to' is missing</p> </td></tr> <tr valign="top"><td><code>crs</code></td> <td> <p>character or object of class 'CRS'. PROJ.4 description of the coordinate reference system. In projectRaster this is used to set the output CRS if 'to' is missing, or if 'to' has no valid CRS</p> </td></tr> <tr valign="top"><td><code>method</code></td> <td> <p>method used to compute values for the new RasterLayer. Either 'ngb' (nearest neighbor), which is useful for categorical variables, or 'bilinear' (bilinear interpolation; the default value), which is appropriate for continuous variables.</p> </td></tr> <tr valign="top"><td><code>alignOnly</code></td> <td> <p>logical. Use <code>to</code> or other parameters only to align the output (i.e. same origin and resolution), but use the projected extent from <code>from</code></p> </td></tr> <tr valign="top"><td><code>over</code></td> <td> <p>logical. If <code>TRUE</code> wrapping around the date-line is turned off. This can be desirable for global data (to avoid mapping the same areas twice) but it is not desireable in other cases</p> </td></tr> <tr valign="top"><td><code>filename</code></td> <td> <p>character. Output filename</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>additional arguments as for <code><a href="writeRaster.html">writeRaster</a></code></p> </td></tr> <tr valign="top"><td><code>object</code></td> <td> <p>Raster* object</p> </td></tr> </table> <h3>Details</h3> <p>There are two approaches you can follow to project the values of a Raster object. </p> <p>1) Provide a <code>crs</code> argument, and, optionally, a <code>res</code> argument, but do not provide a <code>to</code> argument. </p> <p>2) Create a template Raster with the CRS you want to project to. You can use an existing object, or use <code>projectExtent</code> for this or an existing Raster* object. Also set the number of rows and columns (or the resolution), and perhaps adjust the extent. The resolution of the output raster should normally be similar to that of the input raster. Then use that object as <code>from</code> argument to project the input Raster to. This is the preferred method because you have most control. For example you can assure that the resulting Raster object lines up with other Raster objects. </p> <p>Projection is performed using the PROJ.4 library accessed through the rgdal package. </p> <p>One of the best places to find PROJ.4 coordinate reference system descriptions is <a href="http://www.spatialreference.org">http://www.spatialreference.org</a>. </p> <p>You can also consult this page: <a href="http://geotiff.maptools.org/proj_list">http://geotiff.maptools.org/proj_list</a> to find the parameter options and names for projections. </p> <p>Also see <code>projInfo('proj')</code>, <code>projInfo('ellps')</code>, and <code>projInfo('datum')</code> for valid PROJ.4 values. </p> <h3>Value</h3> <p>RasterLayer or RasterBrick object. </p> <h3>Note</h3> <p>If the resolution of the output is much larger than that of the input, you should first aggregate the input such that the resolution of the input becomes more similar (perhaps a little smaller) to the output. </p> <h3>Note</h3> <p>Vector (points, lines, polygons) can be transformed with <code><a href="../../sp/html/spTransform.html">spTransform</a></code>. </p> <p><code>projectExtent</code> does not work very well when transforming projected circumpolar data to (e.g.) longitude/latitude. With such data you may need to adjust the returned object. E.g. do <code>ymax(object) <- 90</code> </p> <h3>Author(s)</h3> <p>Robert J. Hijmans and Joe Cheng</p> <h3>See Also</h3> <p><code><a href="resample.html">resample</a></code>, <code><a href="../../rgdal/html/CRS-class.html">CRS-class</a></code>, <code><a href="../../rgdal/html/projInfo.html">projInfo</a></code>, <code><a href="../../sp/html/spTransform.html">spTransform</a></code> </p> <h3>Examples</h3> <pre> # create a new (not projected) RasterLayer with cellnumbers as values r <- raster(xmn=-110, xmx=-90, ymn=40, ymx=60, ncols=40, nrows=40) r <- setValues(r, 1:ncell(r)) crs(r) # wkt(r) # proj.4 projection description newproj <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84" # we need the rgdal package for this if (require(rgdal)) { #simplest approach pr1 <- projectRaster(r, crs=newproj) # alternatively also set the resolution pr2 <- projectRaster(r, crs=newproj, res=20000) # inverse projection, back to the properties of 'r' inv <- projectRaster(pr2, r) # to have more control, provide an existing Raster object, here we create one # using projectExtent (no values are transferred) pr3 <- projectExtent(r, newproj) # Adjust the cell size res(pr3) <- 200000 # now project pr3 <- projectRaster(r, pr3) ## Not run: # using a higher resolution res(pr1) <- 10000 pr <- projectRaster(r, pr1, method='bilinear') inv <- projectRaster(pr, r, method='bilinear') dif <- r - inv # small difference plot(dif) ## End(Not run) } </pre> <hr /><div style="text-align: center;">[Package <em>raster</em> version 3.3-13 <a href="00Index.html">Index</a>]</div> </body></html>