| 1 |
\name{aggregate} |
| 2 |
\docType{methods} |
| 3 |
\alias{aggregate} |
| 4 |
\alias{aggregate.Spatial} |
| 5 |
|
| 6 |
\title{ aggregation of spatial objects } |
| 7 |
\description{ spatial aggregation of thematic information in spatial objects} |
| 8 |
\usage{ |
| 9 |
\method{aggregate}{Spatial}(x, by = list(ID = rep(1, length(x))), |
| 10 |
FUN, \dots, dissolve = TRUE, areaWeighted = FALSE) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{x}{object deriving from \link{Spatial}, with attributes } |
| 14 |
\item{by}{aggregation predicate; if \code{by} is a \link{Spatial} object, |
| 15 |
the geometry by which attributes in \code{x} are aggregated; if \code{by} |
| 16 |
is a list, aggregation by attribute(s), see \link{aggregate.data.frame}} |
| 17 |
\item{FUN}{aggregation function, e.g. \link{mean}; see details} |
| 18 |
\item{...}{arguments passed on to function \code{FUN}, unless \code{minDimension} |
| 19 |
is specified, which is passed on to function \link{over}} |
| 20 |
\item{dissolve}{logical; should, when aggregating based on attributes, the |
| 21 |
resulting geometries be dissolved? Note that if \code{x} has class |
| 22 |
\code{SpatialPointsDataFrame}, this returns an object of class \code{SpatialMultiPointsDataFrame}; deprecated} |
| 23 |
\item{areaWeighted}{logical; should the aggregation of \code{x} be weighted by the |
| 24 |
areas it intersects with each feature of \code{by}? See value; deprecated.} |
| 25 |
} |
| 26 |
\value{ |
| 27 |
The aggregation of attribute values of \code{x} either over the |
| 28 |
geometry of \code{by} by using \link{over} for spatial matching, |
| 29 |
or by attribute values, using aggregation function \code{FUN}. |
| 30 |
|
| 31 |
If \code{areaWeighted} is \code{TRUE}, \code{FUN} is ignored and the |
| 32 |
area weighted mean is computed for numerical variables, or if all |
| 33 |
attributes are \code{factor}s, the area dominant factor level (area |
| 34 |
mode) is returned. This computes the intersection of \code{x} |
| 35 |
and \code{by}; see examples below. As this uses code from package |
| 36 |
rgeos, it is deprecated as package rgeos will retire. |
| 37 |
|
| 38 |
If \code{by} is missing, aggregates over all features. |
| 39 |
} |
| 40 |
\details{ |
| 41 |
For as far as these functions use package rgeos, (lines, polygons, |
| 42 |
dissolve = TRUE), they are deprecated as rgeos will retire; try |
| 43 |
using sf::aggregate instead. |
| 44 |
|
| 45 |
\code{FUN} should be a function that takes as first argument a |
| 46 |
vector, and that returns a single number. The canonical examples |
| 47 |
are \link{mean} and \link{sum}. Counting features is obtained when |
| 48 |
summing an attribute variable that has the value 1 everywhere. |
| 49 |
} |
| 50 |
|
| 51 |
\author{Edzer Pebesma, \email{[email protected]}} |
| 52 |
|
| 53 |
\note{ uses \link{over} to find spatial match if \code{by} is a |
| 54 |
\link{Spatial} object } |
| 55 |
|
| 56 |
\examples{ |
| 57 |
data("meuse") |
| 58 |
coordinates(meuse) <- ~x+y |
| 59 |
data("meuse.grid") |
| 60 |
coordinates(meuse.grid) <- ~x+y |
| 61 |
gridded(meuse.grid) <- TRUE |
| 62 |
i = cut(meuse.grid$dist, c(0,.25,.5,.75,1), include.lowest = TRUE) |
| 63 |
j = sample(1:2, 3103,replace=TRUE) |
| 64 |
|
| 65 |
x = aggregate(meuse.grid["dist"], list(i=i,j=j), mean, dissolve = FALSE) |
| 66 |
spplot(x["j"], col.regions=bpy.colors()) |
| 67 |
|
| 68 |
|
| 69 |
} |
| 70 |
\keyword{methods} |