| 1 |
options("rgdal_show_exportToProj4_warnings"="none") |
| 2 |
library(sp) |
| 3 |
data(meuse) |
| 4 |
x = meuse |
| 5 |
|
| 6 |
coordinates(x) <- c("x", "y") |
| 7 |
inherits(try(proj4string(x) <- 1.5, silent = TRUE), "try-error") |
| 8 |
try(coordinates(a) <- cbind(1:10, 10:1)) |
| 9 |
# fails because a is not found; passes if a assigned NULL, see pass1.R |
| 10 |
|
| 11 |
x = meuse |
| 12 |
# invalid coordinate formulae: |
| 13 |
try(coordinates(x) <- ~log(x)+sqrt(y)) # no expressions allowed |
| 14 |
try(coordinates(x) <- ~x+y+z) # z is not present |
| 15 |
x$x2 = x$x^2 |
| 16 |
x$y2 = x$y^2 |
| 17 |
try(coordinates(x) <- ~x+y+x2+y2) # 4D now passes check... |
| 18 |
x = meuse |
| 19 |
try(coordinates(x) <- ~x) # 1D not allowed |
| 20 |
|
| 21 |
# is.na.sp.coords |
| 22 |
a = data.frame(cbind(xx=c(1,NA,2,10),yy=c(2,NA,NA,20))) |
| 23 |
try(coordinates(a) <- c("xx", "yy")) # should fail! |
| 24 |
|
| 25 |
x = meuse[1:4,] |
| 26 |
coordinates(x) = c(1,2) |
| 27 |
# this should fail -- zinc is not a row: |
| 28 |
#(and will break automatic testing, so outcommented!) |
| 29 |
#try(q <- x["zinc",]) |
| 30 |
# this will issue warning under S-Plus, or a silent rename under R |
| 31 |
try(x[c("zinc", "copper", "zinc")]) |
| 32 |
|
| 33 |
# this will fail, as "x" is not in the data part: |
| 34 |
try(x[c("zinc", "x", "copper", "zinc")]) |
| 35 |
|
| 36 |
# row index containing missing values will fail: |
| 37 |
try(xx <- x[c(1:3,NA),]) |
| 38 |
|
| 39 |
xx = data.frame(x=1:10, y=1:10) |
| 40 |
|
| 41 |
# fails; use SpatialPoints() to create points without attribute |
| 42 |
try(coordinates(xx) <- c("x", "y")) |
| 43 |
|
| 44 |
x = matrix(3, 5, 2) |
| 45 |
dimnames(x) = list(c(1,1:4), NULL) |
| 46 |
y = data.frame(a = 1:5, b = 5:1) |
| 47 |
try(SpatialPointsDataFrame(x, y)) # will complain: |
| 48 |
SpatialPointsDataFrame(x, y, match.ID = FALSE) # won't complain |
| 49 |
|
| 50 |
Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) |
| 51 |
Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) |
| 52 |
Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) |
| 53 |
Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) |
| 54 |
|
| 55 |
Srs1 = Polygons(list(Sr1), "s1") |
| 56 |
Srs2 = Polygons(list(Sr2), "s2") |
| 57 |
Srs3 = Polygons(list(Sr3, Sr4), "s2") |
| 58 |
try(SR <- SpatialPolygons(list(Srs1,Srs2,Srs3))) # will complain |
| 59 |
Srs3 = Polygons(list(Sr3, Sr4), "s3/4") |
| 60 |
SR = SpatialPolygons(list(Srs1,Srs2,Srs3)) # won't complain |
| 61 |
try(SRx <- SR[c(1,2,NA),]) |
| 62 |
|
| 63 |
attr = data.frame(a=1:3, b=3:1, row.names=c("s1", "s2", "s3")) |
| 64 |
try(SrDf <- SpatialPolygonsDataFrame(SR, attr)) # will complain |
| 65 |
SrDf = SpatialPolygonsDataFrame(SR, attr, match.ID = FALSE) # won't complain |
| 66 |
attr = data.frame(a=1:3, b=3:1, row.names=c("s1", "s2", "s3/4")) |
| 67 |
SrDf = SpatialPolygonsDataFrame(SR, attr) # won't complain |
| 68 |
|
| 69 |
l1 = cbind(c(1,2,3),c(3,2,2)) |
| 70 |
l1a = cbind(l1[,1]+.05,l1[,2]+.05) |
| 71 |
l2 = cbind(c(1,2,3),c(1,1.5,1)) |
| 72 |
Sl1 = Line(l1) |
| 73 |
Sl1a = Line(l1a) |
| 74 |
Sl2 = Line(l2) |
| 75 |
S1 = Lines(list(Sl1, Sl1a), ID="a") |
| 76 |
S2 = Lines(list(Sl2), ID="b") |
| 77 |
S3 = Lines(list(Sl2), ID="a") |
| 78 |
Sl = SpatialLines(list(S1,S2)) # won't complain |
| 79 |
try(Sl1 <- SpatialLines(list(S1,S3))) # will complain |
| 80 |
try(Sl1 <- Sl[c(NA,2),]) # will fail |
| 81 |
|
| 82 |
df = data.frame(z = c(1,2), row.names=sapply(slot(Sl, "lines"), function(x) slot(x, "ID"))) |
| 83 |
Sldf = SpatialLinesDataFrame(Sl, data = df) # won't complain |
| 84 |
df1 = data.frame(z = c(1,2)) |
| 85 |
try(Sldf1 <- SpatialLinesDataFrame(Sl, data = df1)) # will complain |
| 86 |
Sldf1 = SpatialLinesDataFrame(Sl, data = df1, match.ID = FALSE) # won't complain |
| 87 |
try(Sldf1 <- Sldf1[c(1,NA),]) |
| 88 |
|
| 89 |
data(meuse.grid) |
| 90 |
gridded(meuse.grid) = ~x+y |
| 91 |
try(x <- meuse.grid[c(1:10,NA,12),]) |
| 92 |
fullgrid(meuse.grid) = TRUE |
| 93 |
try(x <- meuse.grid[c(1:10,NA,12),]) |
| 94 |
|
| 95 |
try(x <- meuse[[c("zinc", "cadmium")]]) |
| 96 |
try(meuse[[c("zn", "cd")]] <- cbind(meuse$zinc, meuse$cadmium)) |
| 97 |
|
| 98 |
data(meuse.grid) |
| 99 |
coordinates(meuse.grid) <- c("x", "y") |
| 100 |
gridded(meuse.grid) <- TRUE |
| 101 |
gridparameters(meuse.grid) |
| 102 |
|
| 103 |
image(meuse.grid) |
| 104 |
image(meuse.grid[2]) |
| 105 |
image(meuse.grid, 2) |
| 106 |
try(image(meuse.grid, 0)) |
| 107 |
image(meuse.grid[3], breaks=c(0,.2,.5,.8,1), col = bpy.colors(4)) |
| 108 |
image(meuse.grid, 3, zlim = c(0,.3)) |
| 109 |
image(meuse.grid, 3, zlim = c(.3,.1)) |
| 110 |
image(meuse.grid, 3, zlim = c(.2,.8)) |
| 111 |
image(meuse.grid, 3, zlim = c(.2,.8), breaks = c(.2,.4,.6,.8), |
| 112 |
col = bpy.colors(3)) |
| 113 |
|
| 114 |
data(meuse.grid) |
| 115 |
set.seed(1) |
| 116 |
meuse.grid$x <- meuse.grid$x + rnorm(length(meuse.grid$x), 0, 0.0002) |
| 117 |
meuse.grid$y <- meuse.grid$y + rnorm(length(meuse.grid$y), 0, 0.0002) |
| 118 |
coordinates(meuse.grid) <- c("x", "y") |
| 119 |
try(gridded(meuse.grid) <- TRUE) |
| 120 |
try(meuse.grid <- SpatialPixelsDataFrame(as(meuse.grid, "SpatialPoints"), |
| 121 |
data=as(meuse.grid, "data.frame"), tolerance=0.077)) |
| 122 |
gridparameters(meuse.grid) |
| 123 |
|
| 124 |
data(meuse.grid_ll) |
| 125 |
try(gridded(meuse.grid_ll) <- TRUE) |
| 126 |
try(meuse.grid_ll <- SpatialPixelsDataFrame(as(meuse.grid_ll, "SpatialPoints"), data=as(meuse.grid_ll, "data.frame"), tolerance=0.9)) |
| 127 |
gridparameters(meuse.grid_ll) |
| 128 |
|
| 129 |
try(CRS("+proj=latlon +ellps=WGS84")) |
| 130 |
try(CRS("+proj=lonlat +ellps=WGS84")) |