SpatialGrid: define spatial grid

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/SpatialGrid-methods.R

Description

defines spatial grid by offset, cell size and dimensions

Usage

1
2
3
4
5
6
7
8
9
GridTopology(cellcentre.offset, cellsize, cells.dim)
SpatialPixels(points, tolerance = sqrt(.Machine$double.eps),
		proj4string = CRS(as.character(NA)), round = NULL, grid = NULL)
SpatialGrid(grid, proj4string = CRS(as.character(NA)))
coordinatevalues(obj)
points2grid(points, tolerance = sqrt(.Machine$double.eps), round=NULL)
getGridIndex(cc, grid, all.inside = TRUE)
getGridTopology(obj)
areaSpatialGrid(obj)

Arguments

cellcentre.offset

numeric; vector with the smallest centroid coordinates for each dimension; coordinates refer to the cell centre

cellsize

numeric; vector with the cell size in each dimension

cells.dim

integer; vector with number of cells in each dimension

points

coordinates, object of class SpatialPoints-class

grid

grid topology; object of class GridTopology-class; for calls to SpatialPixels, a value of NULL implies that this will be derived from the point coordinates

tolerance

precision, used to which extent points are exactly on a grid

round

default NULL, otherwise a value passed to as the digits argument to round for setting cell size

proj4string

object of class CRS-class

obj

object of class or deriving from SpatialGrid-class

cc

numeric matrix with coordinates

all.inside

logical; if TRUE and cc points fall outside the grid area, an error message is generated; if FALSE, NA values are generated for such points

Value

GridTopology returns a value of class GridTopology-class; SpatialGrid returns an object of class SpatialGrid-class

coordinatevalues returns a list with the unique x-coordinates, the unique y-coordinate, etc. instead of the coordinates of all grid cells

SpatialGrid returns an object of class SpatialGrid-class.

points2grid returns the GridTopology-class from a set of points.

getGridIndex finds the index of a set of point coordinates in a given grid topology, and depending on all.inside setting, generates NA or an error message if points are outside the grid domain.

getGridTopology returns the slot of class GridTopology-class from obj.

areaSpatialGrid returns the spatial area of (the non-missing valued cells of) the grid. For objects of class SpatialGridDataFrame-class the area refers to cells where any (one or more) of the attribute columns are non-missing valued.

Note

SpatialGrid stores grid topology and may or may not store the coordinates of the actual points, which may form a subset of the full grid. To find out or change this, see fullgrid.

points2grid tries to figure out the grid topology from points. It succeeds only if points on a grid line have constant y column, and points on a grid column have constant x coordinate, etc. In other cases, use signif on the raw coordinate matrices to make sure this is the case.

Author(s)

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

See Also

SpatialGrid-class, SpatialGridDataFrame-class,

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
x = GridTopology(c(0,0), c(1,1), c(5,4))
class(x)
x
summary(x)
coordinates(x)
coordinates(GridTopology(c(0,0), c(1,1), c(5,4)))
coordinatevalues(x)
data(meuse.grid)
coordinates(meuse.grid) <- c("x", "y")
points2grid(meuse.grid)
data(meuse.grid)
set.seed(1)
meuse.grid$x <- meuse.grid$x + rnorm(length(meuse.grid$x), 0, 0.002)
meuse.grid$y <- meuse.grid$y + rnorm(length(meuse.grid$y), 0, 0.002)
coordinates(meuse.grid) <- c("x", "y")
#EJP
# points2grid(meuse.grid, tolerance=0.76, round=1)
data(meuse.grid)
a <- which(meuse.grid$x == 180140)
b <- which(meuse.grid$x == 180180)
c <- which(meuse.grid$x == 179260)
d <- which(meuse.grid$y == 332460)
e <- which(meuse.grid$y == 332420)
f <- which(meuse.grid$y == 330740)
meuse.grid <- meuse.grid[-c(a, b, c, d, e, f),]
coordinates(meuse.grid) <- c("x", "y")
points2grid(meuse.grid)
data(meuse.grid)
set.seed(1)
meuse.grid$x <- meuse.grid$x + rnorm(length(meuse.grid$x), 0, 0.002)
meuse.grid$y <- meuse.grid$y + rnorm(length(meuse.grid$y), 0, 0.002)
meuse.grid <- meuse.grid[-c(a, b, c, d, e, f),]
coordinates(meuse.grid) <- c("x", "y")
# EJP
# points2grid(meuse.grid, tolerance=0.69, round=1)

Example output

[1] "GridTopology"
attr(,"package")
[1] "sp"
                  X1 X2
cellcentre.offset  0  0
cellsize           1  1
cells.dim          5  4
Grid topology:
  cellcentre.offset cellsize cells.dim
1                 0        1         5
2                 0        1         4
      s1 s2
 [1,]  0  3
 [2,]  1  3
 [3,]  2  3
 [4,]  3  3
 [5,]  4  3
 [6,]  0  2
 [7,]  1  2
 [8,]  2  2
 [9,]  3  2
[10,]  4  2
[11,]  0  1
[12,]  1  1
[13,]  2  1
[14,]  3  1
[15,]  4  1
[16,]  0  0
[17,]  1  0
[18,]  2  0
[19,]  3  0
[20,]  4  0
      s1 s2
 [1,]  0  3
 [2,]  1  3
 [3,]  2  3
 [4,]  3  3
 [5,]  4  3
 [6,]  0  2
 [7,]  1  2
 [8,]  2  2
 [9,]  3  2
[10,]  4  2
[11,]  0  1
[12,]  1  1
[13,]  2  1
[14,]  3  1
[15,]  4  1
[16,]  0  0
[17,]  1  0
[18,]  2  0
[19,]  3  0
[20,]  4  0
$s1
[1] 0 1 2 3 4

$s2
[1] 3 2 1 0

                       x      y
cellcentre.offset 178460 329620
cellsize              40     40
cells.dim             78    104
                       x      y
cellcentre.offset 178460 329620
cellsize              40     40
cells.dim             78    104
Warning messages:
1: In points2grid(meuse.grid) : grid has empty column/rows in dimension 1
2: In points2grid(meuse.grid) : grid has empty column/rows in dimension 2

sp documentation built on Jan. 13, 2021, 12:09 p.m.