aggregate: aggregation of spatial objects

Description Usage Arguments Value Note Author(s) Examples

Description

spatial aggregation of thematic information in spatial objects

Usage

1
2
## S3 method for class 'Spatial'
aggregate(x, by, FUN = mean, ..., dissolve = TRUE)

Arguments

x

object deriving from Spatial, with attributes

by

aggregation predicate; if by is a Spatial object, the geometry over which attributes in x are aggregated; if by is a list, aggregation by attribute(s), see aggregate.data.frame

FUN

aggregation function

...

arguments passed on to function FUN

dissolve

logical; should, when aggregating based on attributes, the resulting geometries be dissolved? Note that if x has class SpatialPointsDataFrame, this is not possible

Value

Function aggregate.Spatial aggregates the attribute values of x either over the geometry of by by using over for spatial matching, or by attribute values, using aggregation function FUN.

Note

uses over to find spatial match if by is a Spatial object

Author(s)

Edzer Pebesma, edzer.pebesma@uni-muenster.de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
data("meuse")
coordinates(meuse) <- ~x+y
data("meuse.grid")
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
i = cut(meuse.grid$dist, c(0,.25,.5,.75,1), include.lowest = TRUE)
j = sample(1:2, 3103,replace=TRUE)
## Not run: 
if (require(rgeos)) {
	# aggregation by spatial object:
	ab = gUnaryUnion(as(meuse.grid, "SpatialPolygons"), meuse.grid$part.a)
	x = aggregate(meuse["zinc"], ab, mean)
	spplot(x)
	# aggregation by attribute, then dissolve to polygon:
	x = aggregate(meuse.grid["dist"], list(i=i))
	spplot(x["i"])
	x = aggregate(meuse.grid["dist"], list(i=i,j=j))
	spplot(x["dist"], col.regions=bpy.colors())
	spplot(x["i"], col.regions=bpy.colors(4))
	spplot(x["j"], col.regions=bpy.colors())
}

## End(Not run)

x = aggregate(meuse.grid["dist"], list(i=i,j=j), dissolve = FALSE)
spplot(x["j"], col.regions=bpy.colors())

if (require(gstat) && require(rgeos)) {
	x = idw(log(zinc)~1, meuse, meuse.grid, debug.level=0)[1]
	spplot(x[1],col.regions=bpy.colors())
	i = cut(x$var1.pred, seq(4, 7.5, by=.5), 
		include.lowest = TRUE)
	xa = aggregate(x["var1.pred"], list(i=i))
	spplot(xa[1],col.regions=bpy.colors(8))
}

dis-organization/sp_dplyrexpt documentation built on May 15, 2019, 8:52 a.m.