EVOLUTION-MANAGER
Edit File: aggregate.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: Aggregate raster cells or SpatialPolygons/Lines</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 aggregate {raster}"><tr><td>aggregate {raster}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Aggregate raster cells or SpatialPolygons/Lines</h2> <h3>Description</h3> <p>Raster* objects: </p> <p>Aggregate a Raster* object to create a new RasterLayer or RasterBrick with a lower resolution (larger cells). Aggregation groups rectangular areas to create larger cells. The value for the resulting cells is computed with a user-specified function. </p> <p>SpatialPolygon*: </p> <p>Aggregate a SpatialPolygon* object, optionally by combining polygons that have the same attributes for one or more variables. If the polygons touch or overlap, internal boundaries are optionally "dissolved". </p> <h3>Usage</h3> <pre> ## S4 method for signature 'Raster' aggregate(x, fact, fun=mean, expand=TRUE, na.rm=TRUE, filename='', ...) ## S4 method for signature 'SpatialPolygons' aggregate(x, by, sums, dissolve=TRUE, vars=NULL, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Raster* object or SpatialPolygons* object</p> </td></tr> <tr valign="top"><td><code>fact</code></td> <td> <p>postive integer. Aggregation factor expressed as number of cells in each direction (horizontally and vertically). Or two integers (horizontal and vertical aggregation factor) or three integers (when also aggregating over layers). See Details</p> </td></tr> <tr valign="top"><td><code>fun</code></td> <td> <p>function used to aggregate values </p> </td></tr> <tr valign="top"><td><code>expand</code></td> <td> <p>logical. If <code>TRUE</code> the output Raster* object will be larger then the input Raster* object if a division of the number of columns or rows with <code>factor</code> is not an integer</p> </td></tr> <tr valign="top"><td><code>na.rm</code></td> <td> <p>logical. If <code>TRUE</code>, NA cells are removed from calculations </p> </td></tr> <tr valign="top"><td><code>filename</code></td> <td> <p>character. Output filename (optional)</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>if <code>x</code> is a Raster* object, additional arguments as for <code><a href="writeRaster.html">writeRaster</a></code></p> </td></tr> <tr valign="top"><td><code>by</code></td> <td> <p>character or integer. The variables (column names or numbers) that should be used to aggregate (dissolve) the SpatialPolygons by only maintaining unique combinations of these variables. The default setting is to use no variables and aggregate all polygons. You can also supply a vector with a length of length(x)</p> </td></tr> <tr valign="top"><td><code>sums</code></td> <td> <p>list with function(s) and variable(s) to summarize. This should be a list of lists in which each element of the main lists has two items. The first item is function (e.g. mean), the second element is a vector of column names (or indices) that need to summarize with that function. Be careful with character and factor variables (you can use, e.g. 'first' <code>function(x)x[1]</code> or 'last' <code>function(x)x[length(x)]</code> or <code>modal</code> for these variables</p> </td></tr> <tr valign="top"><td><code>vars</code></td> <td> <p>deprecated. Same as <code>by</code></p> </td></tr> <tr valign="top"><td><code>dissolve</code></td> <td> <p>logical. If <code>TRUE</code> borders between touching or overlapping polygons are removed (requires package rgeos)</p> </td></tr> </table> <h3>Details</h3> <p>Aggregation of a <code>x</code> will result in a Raster* object with fewer cells. The number of cells is the number of cells of <code>x</code> divided by <code>fact*fact</code> (when fact is a single number) or <code>prod(fact)</code> (when fact consists of 2 or 3 numbers). If necessary this number is adjusted according to the value of <code>expand</code>. For example, <code>fact=2</code> will result in a new Raster* object with <code>2*2=4</code> times fewer cells. If two numbers are supplied, e.g., <code>fact=c(2,3)</code>, the first will be used for aggregating in the horizontal direction, and the second for aggregating in the vertical direction, and the returned object will have <code>2*3=6</code> times fewer cells. Likewise, <code>fact=c(2,3,4)</code> aggregates cells in groups of 2 (rows) by 3 (columns) and 4 (layers). </p> <p>Aggregation starts at the upper-left end of a raster (you can use <code><a href="flip.html">flip</a></code> if you want to start elsewhere). If a division of the number of columns or rows with <code>factor</code> does not return an integer, the extent of the resulting Raster object will either be somewhat smaller or somewhat larger than the original RasterLayer. For example, if an input RasterLayer has 100 columns, and <code>fact=12</code>, the output Raster object will have either 8 columns (<code>expand=FALSE</code>) (using <code>8 x 12 = 96</code> of the original columns) or 9 columns (<code>expand=TRUE</code>). In both cases, the maximum x coordinate of the output RasterLayer would, of course, also be adjusted. </p> <p>The function <code>fun</code> should take multiple numbers, and return a single number. For example <code>mean</code>, <code>modal</code>, <code>min</code> or <code>max</code>. It should also accept a <code>na.rm</code> argument (or ignore it as one of the 'dots' arguments). </p> <h3>Value</h3> <p>RasterLayer or RasterBrick, or a SpatialPolygons* object </p> <h3>Author(s)</h3> <p>Robert J. Hijmans and Jacob van Etten</p> <h3>See Also</h3> <p><code><a href="disaggregate.html">disaggregate</a></code>, <code><a href="resample.html">resample</a></code>. For SpatialPolygons* <code><a href="../../sp/html/disaggregate.html">disaggregate</a></code> </p> <h3>Examples</h3> <pre> r <- raster() # a new aggregated raster, no values ra <- aggregate(r, fact=10) r <- setValues(r, runif(ncell(r))) # a new aggregated raster, max of the values ra <- aggregate(r, fact=10, fun=max) # multiple layers s <- stack(r, r*2) x <- aggregate(s,2) #SpatialPolygons if (require(rgdal) & require(rgeos)) { p <- shapefile(system.file("external/lux.shp", package="raster")) p pa0 <- aggregate(p) pa0 pa1 <- aggregate(p, by='NAME_1', sums=list(list(mean, 'ID_2'))) pa1 } </pre> <hr /><div style="text-align: center;">[Package <em>raster</em> version 3.3-13 <a href="00Index.html">Index</a>]</div> </body></html>