SpatialPolygridDataFrame: Class "SpatialPolygridDataFrame"

Description Objects from the Class Slots Methods Note Author(s) See Also Examples

View source: R/SpatialPolygridDataFrame-class.R

Description

Class for a data frame with associated spatial grid, several grid cells may share one attribute.

Objects from the Class

Objects can be created by calls to the function SpatialPolygridDataFrame. They may also be created from SpatialGridDataFrame objects by calls of the form
y = as(x, "SpatialPolygridDataFrame"), in this case all grid cells have individual attributes. Transformation in the opposite direction can be done by x = as(y, "SpatialGridDataFrame"); it copies the attributes to all assigned grid cells. SpatialPolygridDataFrame objects can also be created from SpatialPointsDataFrame objects by calls of the form as(x, "SpatialPolygridDataFrame"); it generates a rectangular grid that covers all points and then assigns cells to the nearest neighbouring point – it may fail if points are too irregular to allow for a common grid.

Slots

data:

object of class data.frame; contains the data, one row per index

index:

object of class integer, assigns data to grid cells: order indicates reference to grid cells: upper left to right, then to bottom – length must agree with number of grid cells; value indicates the row of the data with the related attributes; may contain NA, and values outside of 1:nrow(data) are ignored.

grid:

object of class GridTopology

bbox:

bounding box of the grid

proj4string

object of class CRS; projection of the grid, may be missing

Methods

coordinates

signature(obj = "SpatialPolygridDataFrame"): Retrieves the mean coordinates for each index, i.e. the centroid of all grid cells belonging to it.

proj4string

signature(obj = "SpatialPolygridDataFrame"): Returns the projection character string, the value of the slot proj4string.

bbox

signature(obj = "SpatialPolygridDataFrame"): Returns the bounding box matrix, the value of the slot bbox.

spplot

signature(obj = "SpatialPolygridDataFrame", geoTiffPath, zcol = names(obj@data), plot = TRUE, returnSGDF = FALSE ...): Method to plot maps, by coercing the SpatialPolygridDataFrame into a SpatialGridDataFrame – see above – and using spplot to plot it. Therefore it may take any layout parameters to be forwarded to spplot. To keep the resulting SpatialGridDataFrame it may be returned by returnSGDF = TRUE. It can also be saved to a (multilayer) tif file by providing a file path in geoTiffPath. To speed up the function, it may be run without graphical output by plot = FALSE, e.g. to directly create a tif file.

cbind

signature(...): cbind-like method; if grids and indices agree, the data are combined by cbind.

subsetSDF

Subsetting, see subsetSDF,SpatialPolygridDataFrame-method; there is no "[" function.

areaSDF

Method to compute the areas of all polygrids, see areaSDF,SpatialPolygridDataFrame-method.

length

signature(x = "SpatialPolygridDataFrame"): number of elements, i.e. of groups of cells with respectively share the attributes.

Note

The code for coercing is based on polygrid2grid and points2polygrid. Using these functions directly allows better control of the parameters, like the resolution of the grid.

Author(s)

Kristina B. Helle, kristina.helle@uni-muenster.de

See Also

SpatialDataFrame-class, which is a wrapper.

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# prepare 
index1 = as.integer(
  c( 6, 6, 7, 7, 8, 8,
     6, 6, 7, 7, 8, 8,
     5, 5, 1, 2, 9, 9,
     5, 5, 4, 3, 9, 9,
     12,12,11,11,10,10,
     12,12,11,11,10,10))
dataFrame1 = data.frame(a = 1:12 * 10, b = 2^(12:1))
grid1 = GridTopology(c(1,1), c(2,2), c(6,6))
spatialGrid1 = SpatialGrid(grid1, CRS("+proj=longlat +datum=WGS84"))

#- - create object by function SpatialPolygridDataFrame - -#
SPolygridDF1 = SpatialPolygridDataFrame(
  grid = grid1,
  data = dataFrame1,
  index = index1,
  proj4string = CRS("+proj=longlat +datum=WGS84"))

#- - - - coerce from SpatialGridDataFrame - - - - - - - -#
spatialGridDataFrame1 = SpatialGridDataFrame(
    grid = spatialGrid1, data = dataFrame1[index1,])
# coerce, each cell keeps individual values
s = as(spatialGridDataFrame1, "SpatialPolygridDataFrame")

# coerce back (name of coordinates may change)
#spatialGridDataFrame2 = as(SPolygridDF2, "SpatialGridDataFrame")
spatialGridDataFrame2 = as(s, "SpatialGridDataFrame")

#- - - - coerce from SpatialPointsDataFrame - - - - - - - #
# from irregular points, grid is created, cells are assigned values of nearest point
spatialPoints1 = SpatialPoints(coordinates(SPolygridDF1) + runif(24))
spatialPointsDataFrame1 = SpatialPointsDataFrame(
    coords = spatialPoints1, data = dataFrame1)
## Not run: 
## takes some seconds
SPolygridDF3 = as(spatialPointsDataFrame1, "SpatialPolygridDataFrame")


# from regular points: one cell per point
spatialPointsDataFrame2 = as(spatialGridDataFrame1, "SpatialPointsDataFrame")
SPolygridDF4 = as(spatialPointsDataFrame2, "SpatialPolygridDataFrame")

# - - - - - - - - - - - - - coordinates - - - - - - - - - - - - #
# compare irregular input points and centroids of output
plot(spatialPoints1)
points(coordinates(SPolygridDF3))

# - - - - - - - - - - - - - proj4string - - - - - - - - - - - -  #
# only to retrieve projection attributes
#proj4string(SPolygridDF2)
proj4string(s)
proj4string(SPolygridDF3)
# - - - - - - - - - - - - - proj4string - - - - - - - - - - - -  #
bbox(SPolygridDF3)
# - - - - - - - - - - - spplot - - - - - - - - - - - - - - - - #

## takes some time
# plot map with original points
spplot(SPolygridDF3, zcol = "a", 
  sp.layout = list(list("sp.points", spatialPoints1, col = 8)))
# plot map with centres of polygrid cells
spplot(SPolygridDF4, zcol = "a", col.regions = rainbow(16),
  sp.layout = list("sp.points", spatialPointsDataFrame2@coords, col = 8))


# - - - - - - - - - - - - cbind - - - - - - - - - - - - - - - - #
#SPolygridDF5 = cbind(SPolygridDF2, SPolygridDF4) 
SPolygridDF5 = cbind(s, SPolygridDF4) 

## End(Not run)

sensors4plumes documentation built on May 1, 2019, 10:27 p.m.