Agg2Spatial: Aggregate per spatial unit

Description Usage Arguments Examples

View source: R/180710_Agg2Spatial.R

Description

This function take as arguements geocoded locations and some spatial units and aggregates the geocodes on the selected spatial units.

Usage

1
Agg2Spatial(geocodes, shapefile, density = FALSE)

Arguments

geocodes

a SpatialPoints object

shapefile

a shapefile object or raster object defining the desirable spatial units

density

if TRUE then the function computes the density of the points per spatial unit

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
library(spatstat)
 library(maptools)
 set.seed(123456789)
 x <- runif(100, -5, 5)
 y <- runif(100, -5, 5)
 df <- data.frame(x=x, y=y) 
 # need a boundary window: 
 W <- owin(xrange=c(-5,5), yrange=c(-5, 5))
 # create point pattern 
 X <- as.ppp(df, W=W) 
 plot(X) 
 # compute Dirichlet triangles 
 Y <- dirichlet(X) 
 plot(Y) 
 points(df$x, df$y)
 # convert 
 t <- as(Y, "SpatialPolygons") 
 newdata <- data.frame(layer = 1:length(x))
 row.names(newdata) <- 1:length(x)
 polygons <- SpatialPolygonsDataFrame(t, newdata)
 # and make it a spatialdataframe
 newdata <- data.frame(layer = 1:length(x))
 row.names(newdata) <- 1:length(x)
 polygons <- SpatialPolygonsDataFrame(t, newdata)
 # now aggregate sample points on this domain 
 set.seed(123456789)
 x_1 <- runif(1000, -5, 5)
 y_1 <- runif(1000, -5, 5)
 points(x_1, y_1, cex = .5, col = "red")
 # and now use Agg2Spatial for the aggregation
 geosp <- SpatialPoints(cbind(x_1, y_1))
 aggobj <- Agg2Spatial(geocodes = geosp, shapefile = polygons, density = F)
 spplot(aggobj, "x")
Agg2Spatial()

akiskon89/GeoSwiss documentation built on April 6, 2020, 8:44 p.m.