Debian Codegraph @

tests/grid.R

raw
1 options("rgdal_show_exportToProj4_warnings"="none")
2 library(sp)
3 data(meuse.grid)
4 x = meuse.grid
5 coordinates(x) = c("x", "y")
6 gridded(x) = TRUE
7 gridded(x)
8 image(x["dist"])
9
10 fullgrid(x) = TRUE
11 fullgrid(x)
12 # summary(x)
13 gridparameters(x)
14 class(as(x, "matrix"))
15
16 fullgrid(x) = FALSE
17 fullgrid(x)
18 # summary(x)
19 class(as(x, "matrix"))
20 gridparameters(x)
21
22 df = data.frame(z = c(1:6,NA,8,9),
23 xc = c(1,1,1,2,2,2,3,3,3),
24 yc = c(rep(c(0, 1.5, 3),3)))
25
26 coordinates(df) = ~xc+yc
27 gridded(df) = TRUE
28 gridparameters(df)
29 as(df, "matrix")
30
31 # get grid topology:
32 grd = points2grid(as(df, "SpatialPoints"), 1e-31)
33 grd
34 getGridIndex(coordinates(df), grd)
35
36 g = SpatialGrid(grid = grd)
37 fullgrid(g)
38 fullgrid(g) = TRUE
39 class(g)
40 # the next one has to fail:
41 fullgrid(g) <- FALSE
42 class(g)
43
44 # summary(df)
45 image(df["z"])
46 as.image.SpatialGridDataFrame(df)
47 as.image.SpatialGridDataFrame(df["z"])
48 coordinatevalues(getGridTopology(df))
49
50 as.data.frame(df)
51
52 fullgrid(df) = TRUE
53 as.data.frame(df)
54
55 fullgrid(df) = FALSE
56 as.data.frame(df)
57
58 fullgrid(df) = TRUE
59 fullgrid(df) = FALSE
60 as.data.frame(df)
61
62 df = as.data.frame(df)
63 set.seed(133331)
64 df$xc = df$xc + rep(.001*rnorm(3), 3)[1:8]
65 df.sp = SpatialPoints(df[c("xc", "yc")])
66 df.grd = SpatialPixels(df.sp, tolerance = .01)
67 df.grd[1:4,,tolerance=.01,drop=TRUE]
68 df.grd[1:4,,tolerance=.01]