| 1 |
|
| 2 |
R Under development (unstable) (2026-02-11 r89406 ucrt) -- "Unsuffered Consequences" |
| 3 |
Copyright (C) 2026 The R Foundation for Statistical Computing |
| 4 |
Platform: x86_64-w64-mingw32/x64 |
| 5 |
|
| 6 |
R is free software and comes with ABSOLUTELY NO WARRANTY. |
| 7 |
You are welcome to redistribute it under certain conditions. |
| 8 |
Type 'license()' or 'licence()' for distribution details. |
| 9 |
|
| 10 |
R is a collaborative project with many contributors. |
| 11 |
Type 'contributors()' for more information and |
| 12 |
'citation()' on how to cite R or R packages in publications. |
| 13 |
|
| 14 |
Type 'demo()' for some demos, 'help()' for on-line help, or |
| 15 |
'help.start()' for an HTML browser interface to help. |
| 16 |
Type 'q()' to quit R. |
| 17 |
|
| 18 |
> options("rgdal_show_exportToProj4_warnings"="none") |
| 19 |
> source("utils/print.R") |
| 20 |
> |
| 21 |
> library(sp) |
| 22 |
> data(meuse) |
| 23 |
> x = meuse |
| 24 |
> coordinates(x) = cbind(rnorm(155), rnorm(155)) |
| 25 |
> # should pass: |
| 26 |
> names(x@data) |
| 27 |
[1] "x" "y" "cadmium" "copper" "lead" "zinc" "elev" |
| 28 |
[8] "dist" "om" "ffreq" "soil" "lime" "landuse" "dist.m" |
| 29 |
> names(as.data.frame(x)) |
| 30 |
[1] "x" "y" "cadmium" "copper" "lead" "zinc" |
| 31 |
[7] "elev" "dist" "om" "ffreq" "soil" "lime" |
| 32 |
[13] "landuse" "dist.m" "coords.x1" "coords.x2" |
| 33 |
> class(as(x, "data.frame")) |
| 34 |
[1] "data.frame" |
| 35 |
> x = meuse |
| 36 |
> # coordinates defined as data: |
| 37 |
> coordinates(x) = cbind(xcoord = rnorm(155), ycoord = rnorm(155)) |
| 38 |
> # should pass: |
| 39 |
> names(x@data) |
| 40 |
[1] "x" "y" "cadmium" "copper" "lead" "zinc" "elev" |
| 41 |
[8] "dist" "om" "ffreq" "soil" "lime" "landuse" "dist.m" |
| 42 |
> names(as.data.frame(x)) |
| 43 |
[1] "x" "y" "cadmium" "copper" "lead" "zinc" "elev" |
| 44 |
[8] "dist" "om" "ffreq" "soil" "lime" "landuse" "dist.m" |
| 45 |
[15] "xcoord" "ycoord" |
| 46 |
> is.projected(x) |
| 47 |
[1] NA |
| 48 |
> proj4string(x) |
| 49 |
[1] NA |
| 50 |
> |
| 51 |
> set.seed(13131) # make sample reproducable: |
| 52 |
> x = meuse[, sample(ncol(meuse))] # 'randomly' shuffle columns |
| 53 |
> # coordinates defined as variable names: |
| 54 |
> coordinates(x) = c("x", "y") # no matter their position |
| 55 |
> #plot(x, cex=.05 * sqrt(x@data[,"zinc"]), |
| 56 |
> plot(x, cex=.05 * sqrt(as.data.frame(x)[["zinc"]]),pch=1) |
| 57 |
> title("Meuse: zinc bubble plot") |
| 58 |
> print(summary(x)) |
| 59 |
Object of class SpatialPointsDataFrame |
| 60 |
Coordinates: |
| 61 |
min max |
| 62 |
x 178605 181390 |
| 63 |
y 329714 333611 |
| 64 |
Is projected: NA |
| 65 |
proj4string : [NA] |
| 66 |
Number of points: 155 |
| 67 |
Data attributes: |
| 68 |
lime om landuse ffreq zinc |
| 69 |
0:111 Min. : 1.000 W :50 1:84 Min. : 113.0 |
| 70 |
1: 44 1st Qu.: 5.300 Ah :39 2:48 1st Qu.: 198.0 |
| 71 |
Median : 6.900 Am :22 3:23 Median : 326.0 |
| 72 |
Mean : 7.478 Fw :10 Mean : 469.7 |
| 73 |
3rd Qu.: 9.000 Ab : 8 3rd Qu.: 674.5 |
| 74 |
Max. :17.000 (Other):25 Max. :1839.0 |
| 75 |
NAs :2 NAs : 1 |
| 76 |
dist copper cadmium soil dist.m |
| 77 |
Min. :0.00000 Min. : 14.00 Min. : 0.200 1:97 Min. : 10.0 |
| 78 |
1st Qu.:0.07569 1st Qu.: 23.00 1st Qu.: 0.800 2:46 1st Qu.: 80.0 |
| 79 |
Median :0.21184 Median : 31.00 Median : 2.100 3:12 Median : 270.0 |
| 80 |
Mean :0.24002 Mean : 40.32 Mean : 3.246 Mean : 290.3 |
| 81 |
3rd Qu.:0.36407 3rd Qu.: 49.50 3rd Qu.: 3.850 3rd Qu.: 450.0 |
| 82 |
Max. :0.88039 Max. :128.00 Max. :18.100 Max. :1000.0 |
| 83 |
|
| 84 |
lead elev |
| 85 |
Min. : 37.0 Min. : 5.180 |
| 86 |
1st Qu.: 72.5 1st Qu.: 7.546 |
| 87 |
Median :123.0 Median : 8.180 |
| 88 |
Mean :153.4 Mean : 8.165 |
| 89 |
3rd Qu.:207.0 3rd Qu.: 8.955 |
| 90 |
Max. :654.0 Max. :10.520 |
| 91 |
|
| 92 |
> |
| 93 |
> # coordinates defined as formula: |
| 94 |
> x = meuse[, 1:5] |
| 95 |
> coordinates(x) = ~x+y |
| 96 |
> print(summary(x)) |
| 97 |
Object of class SpatialPointsDataFrame |
| 98 |
Coordinates: |
| 99 |
min max |
| 100 |
x 178605 181390 |
| 101 |
y 329714 333611 |
| 102 |
Is projected: NA |
| 103 |
proj4string : [NA] |
| 104 |
Number of points: 155 |
| 105 |
Data attributes: |
| 106 |
cadmium copper lead |
| 107 |
Min. : 0.200 Min. : 14.00 Min. : 37.0 |
| 108 |
1st Qu.: 0.800 1st Qu.: 23.00 1st Qu.: 72.5 |
| 109 |
Median : 2.100 Median : 31.00 Median :123.0 |
| 110 |
Mean : 3.246 Mean : 40.32 Mean :153.4 |
| 111 |
3rd Qu.: 3.850 3rd Qu.: 49.50 3rd Qu.:207.0 |
| 112 |
Max. :18.100 Max. :128.00 Max. :654.0 |
| 113 |
> |
| 114 |
> # a = NULL |
| 115 |
> # cc = cbind(sample(1:10), sample(1:10), sample(1:10)) |
| 116 |
> # coordinates(a) = cc |
| 117 |
> # summary(a) |
| 118 |
> |
| 119 |
> xx = SpatialPointsDataFrame(matrix(1:10,5,2),data.frame(f = 1:5)) |
| 120 |
> rbind(xx,xx,xx,xx) |
| 121 |
coordinates f |
| 122 |
1 (1, 6) 1 |
| 123 |
2 (2, 7) 2 |
| 124 |
3 (3, 8) 3 |
| 125 |
4 (4, 9) 4 |
| 126 |
5 (5, 10) 5 |
| 127 |
6 (1, 6) 1 |
| 128 |
7 (2, 7) 2 |
| 129 |
8 (3, 8) 3 |
| 130 |
9 (4, 9) 4 |
| 131 |
10 (5, 10) 5 |
| 132 |
11 (1, 6) 1 |
| 133 |
12 (2, 7) 2 |
| 134 |
13 (3, 8) 3 |
| 135 |
14 (4, 9) 4 |
| 136 |
15 (5, 10) 5 |
| 137 |
16 (1, 6) 1 |
| 138 |
17 (2, 7) 2 |
| 139 |
18 (3, 8) 3 |
| 140 |
19 (4, 9) 4 |
| 141 |
20 (5, 10) 5 |
| 142 |
> |
| 143 |
> grd <- GridTopology(c(1,1), c(1,1), c(10,10)) |
| 144 |
> polys <- as.SpatialPolygons.GridTopology(grd) |
| 145 |
> summary(rbind(polys[1:10], polys[11:20], polys[21:30])) |
| 146 |
Object of class SpatialPolygons |
| 147 |
Coordinates: |
| 148 |
min max |
| 149 |
x 0.5 10.5 |
| 150 |
y 7.5 10.5 |
| 151 |
Is projected: NA |
| 152 |
proj4string : [NA] |
| 153 |
> plot(rbind(polys[1:10],polys[21:30])) |
| 154 |
> title("2 x 10 blocks -- test rbind on SpatialPolygons") |
| 155 |
> |
| 156 |
> l1 = cbind(c(1,2,3),c(3,2,2)) |
| 157 |
> l1a = cbind(l1[,1]+.05,l1[,2]+.05) |
| 158 |
> l2 = cbind(c(1,2,3),c(1,1.5,1)) |
| 159 |
> Sl1 = Line(l1) |
| 160 |
> Sl1a = Line(l1a) |
| 161 |
> Sl2 = Line(l2) |
| 162 |
> S1 = Lines(list(Sl1, Sl1a), ID="a") |
| 163 |
> S2 = Lines(list(Sl2), ID="b") |
| 164 |
> Sl = SpatialLines(list(S1,S2)) |
| 165 |
> |
| 166 |
> summary(as(polys, "SpatialLines")) |
| 167 |
Object of class SpatialLines |
| 168 |
Coordinates: |
| 169 |
min max |
| 170 |
x 0.5 10.5 |
| 171 |
y 0.5 10.5 |
| 172 |
Is projected: NA |
| 173 |
proj4string : [NA] |
| 174 |
> summary(as(Sl, "SpatialPoints")) |
| 175 |
Object of class SpatialPoints |
| 176 |
Coordinates: |
| 177 |
min max |
| 178 |
coords.x1 1 3.05 |
| 179 |
coords.x2 1 3.05 |
| 180 |
Is projected: NA |
| 181 |
proj4string : [NA] |
| 182 |
Number of points: 9 |
| 183 |
> summary(as(Sl, "SpatialPointsDataFrame")) |
| 184 |
Object of class SpatialPointsDataFrame |
| 185 |
Coordinates: |
| 186 |
min max |
| 187 |
coords.x1 1 3.05 |
| 188 |
coords.x2 1 3.05 |
| 189 |
Is projected: NA |
| 190 |
proj4string : [NA] |
| 191 |
Number of points: 9 |
| 192 |
Data attributes: |
| 193 |
Lines.NR Lines.ID Line.NR |
| 194 |
Min. :1.000 a:6 Min. :1.000 |
| 195 |
1st Qu.:1.000 b:3 1st Qu.:1.000 |
| 196 |
Median :1.000 Median :1.000 |
| 197 |
Mean :1.333 Mean :1.333 |
| 198 |
3rd Qu.:2.000 3rd Qu.:2.000 |
| 199 |
Max. :2.000 Max. :2.000 |
| 200 |
> SlDf = SpatialLinesDataFrame(Sl, data.frame(xx = factor(c("foo", "bar"))), match.ID = FALSE) |
| 201 |
> summary(as(SlDf, "SpatialPointsDataFrame")) |
| 202 |
Object of class SpatialPointsDataFrame |
| 203 |
Coordinates: |
| 204 |
min max |
| 205 |
coords.x1 1 3.05 |
| 206 |
coords.x2 1 3.05 |
| 207 |
Is projected: NA |
| 208 |
proj4string : [NA] |
| 209 |
Number of points: 9 |
| 210 |
Data attributes: |
| 211 |
xx Lines.NR Lines.ID Line.NR |
| 212 |
bar:3 Min. :1.000 a:6 Min. :1.000 |
| 213 |
foo:6 1st Qu.:1.000 b:3 1st Qu.:1.000 |
| 214 |
Median :1.000 Median :1.000 |
| 215 |
Mean :1.333 Mean :1.333 |
| 216 |
3rd Qu.:2.000 3rd Qu.:2.000 |
| 217 |
Max. :2.000 Max. :2.000 |
| 218 |
> |
| 219 |
> meuse[["xxx"]] = log(meuse$zinc) |
| 220 |
> print(summary(meuse)) |
| 221 |
x y cadmium copper |
| 222 |
Min. :178605 Min. :329714 Min. : 0.200 Min. : 14.00 |
| 223 |
1st Qu.:179371 1st Qu.:330762 1st Qu.: 0.800 1st Qu.: 23.00 |
| 224 |
Median :179991 Median :331633 Median : 2.100 Median : 31.00 |
| 225 |
Mean :180005 Mean :331635 Mean : 3.246 Mean : 40.32 |
| 226 |
3rd Qu.:180630 3rd Qu.:332463 3rd Qu.: 3.850 3rd Qu.: 49.50 |
| 227 |
Max. :181390 Max. :333611 Max. :18.100 Max. :128.00 |
| 228 |
|
| 229 |
lead zinc elev dist |
| 230 |
Min. : 37.0 Min. : 113.0 Min. : 5.180 Min. :0.00000 |
| 231 |
1st Qu.: 72.5 1st Qu.: 198.0 1st Qu.: 7.546 1st Qu.:0.07569 |
| 232 |
Median :123.0 Median : 326.0 Median : 8.180 Median :0.21184 |
| 233 |
Mean :153.4 Mean : 469.7 Mean : 8.165 Mean :0.24002 |
| 234 |
3rd Qu.:207.0 3rd Qu.: 674.5 3rd Qu.: 8.955 3rd Qu.:0.36407 |
| 235 |
Max. :654.0 Max. :1839.0 Max. :10.520 Max. :0.88039 |
| 236 |
|
| 237 |
om ffreq soil lime landuse dist.m |
| 238 |
Min. : 1.000 1:84 1:97 0:111 W :50 Min. : 10.0 |
| 239 |
1st Qu.: 5.300 2:48 2:46 1: 44 Ah :39 1st Qu.: 80.0 |
| 240 |
Median : 6.900 3:23 3:12 Am :22 Median : 270.0 |
| 241 |
Mean : 7.478 Fw :10 Mean : 290.3 |
| 242 |
3rd Qu.: 9.000 Ab : 8 3rd Qu.: 450.0 |
| 243 |
Max. :17.000 (Other):25 Max. :1000.0 |
| 244 |
NAs :2 NAs : 1 |
| 245 |
xxx |
| 246 |
Min. :4.727 |
| 247 |
1st Qu.:5.288 |
| 248 |
Median :5.787 |
| 249 |
Mean :5.886 |
| 250 |
3rd Qu.:6.514 |
| 251 |
Max. :7.517 |
| 252 |
|
| 253 |
> meuse$xxy = log(meuse[["zinc"]]) |
| 254 |
> print(summary(meuse)) |
| 255 |
x y cadmium copper |
| 256 |
Min. :178605 Min. :329714 Min. : 0.200 Min. : 14.00 |
| 257 |
1st Qu.:179371 1st Qu.:330762 1st Qu.: 0.800 1st Qu.: 23.00 |
| 258 |
Median :179991 Median :331633 Median : 2.100 Median : 31.00 |
| 259 |
Mean :180005 Mean :331635 Mean : 3.246 Mean : 40.32 |
| 260 |
3rd Qu.:180630 3rd Qu.:332463 3rd Qu.: 3.850 3rd Qu.: 49.50 |
| 261 |
Max. :181390 Max. :333611 Max. :18.100 Max. :128.00 |
| 262 |
|
| 263 |
lead zinc elev dist |
| 264 |
Min. : 37.0 Min. : 113.0 Min. : 5.180 Min. :0.00000 |
| 265 |
1st Qu.: 72.5 1st Qu.: 198.0 1st Qu.: 7.546 1st Qu.:0.07569 |
| 266 |
Median :123.0 Median : 326.0 Median : 8.180 Median :0.21184 |
| 267 |
Mean :153.4 Mean : 469.7 Mean : 8.165 Mean :0.24002 |
| 268 |
3rd Qu.:207.0 3rd Qu.: 674.5 3rd Qu.: 8.955 3rd Qu.:0.36407 |
| 269 |
Max. :654.0 Max. :1839.0 Max. :10.520 Max. :0.88039 |
| 270 |
|
| 271 |
om ffreq soil lime landuse dist.m |
| 272 |
Min. : 1.000 1:84 1:97 0:111 W :50 Min. : 10.0 |
| 273 |
1st Qu.: 5.300 2:48 2:46 1: 44 Ah :39 1st Qu.: 80.0 |
| 274 |
Median : 6.900 3:23 3:12 Am :22 Median : 270.0 |
| 275 |
Mean : 7.478 Fw :10 Mean : 290.3 |
| 276 |
3rd Qu.: 9.000 Ab : 8 3rd Qu.: 450.0 |
| 277 |
Max. :17.000 (Other):25 Max. :1000.0 |
| 278 |
NAs :2 NAs : 1 |
| 279 |
xxx xxy |
| 280 |
Min. :4.727 Min. :4.727 |
| 281 |
1st Qu.:5.288 1st Qu.:5.288 |
| 282 |
Median :5.787 Median :5.787 |
| 283 |
Mean :5.886 Mean :5.886 |
| 284 |
3rd Qu.:6.514 3rd Qu.:6.514 |
| 285 |
Max. :7.517 Max. :7.517 |
| 286 |
|
| 287 |
> |
| 288 |
> # test behaviour on zero-length objects: |
| 289 |
> demo(meuse, ask = FALSE, echo = FALSE) |
| 290 |
> p = as(meuse, "SpatialPoints") |
| 291 |
> |
| 292 |
> p[0] |
| 293 |
SpatialPoints: |
| 294 |
x y |
| 295 |
Coordinate Reference System (CRS) arguments: +proj=sterea |
| 296 |
+lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 |
| 297 |
+x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs |
| 298 |
> dim(p[0]) |
| 299 |
NULL |
| 300 |
> |
| 301 |
> meuse[0,] |
| 302 |
[1] coordinates cadmium copper lead zinc elev |
| 303 |
[7] dist om ffreq soil lime landuse |
| 304 |
[13] dist.m |
| 305 |
<0 rows> (or 0-length row.names) |
| 306 |
> dim(meuse[1:3,0]) |
| 307 |
[1] 3 0 |
| 308 |
> dim(subset(meuse, zinc < 100, 0)) |
| 309 |
[1] 0 0 |
| 310 |
> dim(subset(meuse, , 0)) |
| 311 |
[1] 155 0 |
| 312 |
> dim(subset(meuse, F, 0)) |
| 313 |
[1] 0 0 |
| 314 |
> |
| 315 |
> dim(meuse.grid[0,]) |
| 316 |
[1] 0 5 |
| 317 |
> fullgrid(meuse.grid) = TRUE |
| 318 |
> dim(meuse.grid[0,]) |
| 319 |
[1] 8112 5 |
| 320 |
> print(summary(meuse.grid[0,])) |
| 321 |
Object of class SpatialGridDataFrame |
| 322 |
Coordinates: |
| 323 |
min max |
| 324 |
x 178440 181560 |
| 325 |
y 329600 333760 |
| 326 |
Is projected: TRUE |
| 327 |
proj4string : |
| 328 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 329 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 330 |
Grid attributes: |
| 331 |
cellcentre.offset cellsize cells.dim |
| 332 |
x 178460 40 78 |
| 333 |
y 329620 40 104 |
| 334 |
Data attributes: |
| 335 |
part.a part.b dist soil ffreq |
| 336 |
Mode:logical Mode:logical Mode:logical Mode:logical Mode:logical |
| 337 |
NAs :8112 NAs :8112 NAs :8112 NAs :8112 NAs :8112 |
| 338 |
> dim(meuse.grid[,0]) |
| 339 |
[1] 8112 5 |
| 340 |
> print(summary(meuse.grid[,0])) |
| 341 |
Object of class SpatialGridDataFrame |
| 342 |
Coordinates: |
| 343 |
min max |
| 344 |
x 178440 181560 |
| 345 |
y 329600 333760 |
| 346 |
Is projected: TRUE |
| 347 |
proj4string : |
| 348 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 349 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 350 |
Grid attributes: |
| 351 |
cellcentre.offset cellsize cells.dim |
| 352 |
x 178460 40 78 |
| 353 |
y 329620 40 104 |
| 354 |
Data attributes: |
| 355 |
part.a part.b dist soil ffreq |
| 356 |
Mode:logical Mode:logical Mode:logical Mode:logical Mode:logical |
| 357 |
NAs :8112 NAs :8112 NAs :8112 NAs :8112 NAs :8112 |
| 358 |
> dim(meuse.grid[0,,0]) |
| 359 |
[1] 8112 0 |
| 360 |
> print(summary(meuse.grid[0,,0])) |
| 361 |
Object of class SpatialGridDataFrame |
| 362 |
Coordinates: |
| 363 |
min max |
| 364 |
x 178440 181560 |
| 365 |
y 329600 333760 |
| 366 |
Is projected: TRUE |
| 367 |
proj4string : |
| 368 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 369 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 370 |
Grid attributes: |
| 371 |
cellcentre.offset cellsize cells.dim |
| 372 |
x 178460 40 78 |
| 373 |
y 329620 40 104 |
| 374 |
> |
| 375 |
> # SpatialPolygons: |
| 376 |
> L = as(meuse.riv, "SpatialPolygons") |
| 377 |
> length(L[1]) |
| 378 |
[1] 1 |
| 379 |
> length(L[0]) |
| 380 |
[1] 0 |
| 381 |
> summary(L[0]) |
| 382 |
Object of class SpatialPolygons |
| 383 |
Coordinates: |
| 384 |
min max |
| 385 |
x 178304.0 182331.5 |
| 386 |
y 325698.5 337684.8 |
| 387 |
Is projected: TRUE |
| 388 |
proj4string : |
| 389 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 390 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 391 |
> |
| 392 |
> # SpatialPolygonsDataFrame: |
| 393 |
> L$something = factor("bla") |
| 394 |
> class(L) |
| 395 |
[1] "SpatialPolygonsDataFrame" |
| 396 |
attr(,"package") |
| 397 |
[1] "sp" |
| 398 |
> length(L[1]) |
| 399 |
[1] 1 |
| 400 |
> summary(L[1]) |
| 401 |
Object of class SpatialPolygonsDataFrame |
| 402 |
Coordinates: |
| 403 |
min max |
| 404 |
x 178304.0 182331.5 |
| 405 |
y 325698.5 337684.8 |
| 406 |
Is projected: TRUE |
| 407 |
proj4string : |
| 408 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 409 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 410 |
Data attributes: |
| 411 |
something |
| 412 |
bla:1 |
| 413 |
> length(L[0]) |
| 414 |
[1] 1 |
| 415 |
> summary(L[0]) |
| 416 |
Object of class SpatialPolygonsDataFrame |
| 417 |
Coordinates: |
| 418 |
min max |
| 419 |
x 178304.0 182331.5 |
| 420 |
y 325698.5 337684.8 |
| 421 |
Is projected: TRUE |
| 422 |
proj4string : |
| 423 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 424 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 425 |
> |
| 426 |
> # SpatialLines |
| 427 |
> L = as(meuse.riv, "SpatialLines") |
| 428 |
> length(L[1]) |
| 429 |
[1] 1 |
| 430 |
> length(L[0]) |
| 431 |
[1] 0 |
| 432 |
> summary(L[0]) |
| 433 |
Object of class SpatialLines |
| 434 |
Coordinates: |
| 435 |
min max |
| 436 |
x 178304.0 182331.5 |
| 437 |
y 325698.5 337684.8 |
| 438 |
Is projected: TRUE |
| 439 |
proj4string : |
| 440 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 441 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 442 |
> |
| 443 |
> # SpatialLinesDataFrame |
| 444 |
> L$something = factor("bla") |
| 445 |
> class(L) |
| 446 |
[1] "SpatialLinesDataFrame" |
| 447 |
attr(,"package") |
| 448 |
[1] "sp" |
| 449 |
> length(L[1]) |
| 450 |
[1] 1 |
| 451 |
> summary(L[1]) |
| 452 |
Object of class SpatialLinesDataFrame |
| 453 |
Coordinates: |
| 454 |
min max |
| 455 |
x 178304.0 182331.5 |
| 456 |
y 325698.5 337684.8 |
| 457 |
Is projected: TRUE |
| 458 |
proj4string : |
| 459 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 460 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 461 |
Data attributes: |
| 462 |
something |
| 463 |
bla:1 |
| 464 |
> length(L[0]) |
| 465 |
[1] 1 |
| 466 |
> summary(L[0]) |
| 467 |
Object of class SpatialLinesDataFrame |
| 468 |
Coordinates: |
| 469 |
min max |
| 470 |
x 178304.0 182331.5 |
| 471 |
y 325698.5 337684.8 |
| 472 |
Is projected: TRUE |
| 473 |
proj4string : |
| 474 |
[+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 |
| 475 |
+k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs] |
| 476 |
> |
| 477 |
> m = meuse |
| 478 |
> all.equal(rbind(m[1:3,], m[5:7,]), rbind(m[1:3,], m[0,], m[5:7,])) |
| 479 |
[1] TRUE |
| 480 |
> all.equal(rbind(m[1:3,], m[5:7,]), rbind(m[0,], m[1:3,], m[0,], m[5:7,])) |
| 481 |
[1] TRUE |
| 482 |
> all.equal(rbind(m[1:3,], m[5:7,]), rbind(m[1:3,], m[0,], m[5:7,], m[0,])) |
| 483 |
[1] TRUE |
| 484 |
> |
| 485 |
> # match.ID settings for SpatialPointsDataFrame(): |
| 486 |
> set.seed(1331) |
| 487 |
> pts = cbind(1:5, 1:5) |
| 488 |
> dimnames(pts)[[1]] = letters[1:5] |
| 489 |
> df = data.frame(a = 1:5) |
| 490 |
> row.names(df) = letters[5:1] |
| 491 |
> |
| 492 |
> library(sp) |
| 493 |
> options(warn=1) # show warnings where they occur |
| 494 |
> SpatialPointsDataFrame(pts, df) # warn |
| 495 |
Warning in SpatialPointsDataFrame(pts, df) : |
| 496 |
forming a SpatialPointsDataFrame based on maching IDs, not on record order. Use match.ID = FALSE to match on record order |
| 497 |
coordinates a |
| 498 |
a (1, 1) 5 |
| 499 |
b (2, 2) 4 |
| 500 |
c (3, 3) 3 |
| 501 |
d (4, 4) 2 |
| 502 |
e (5, 5) 1 |
| 503 |
> SpatialPointsDataFrame(pts, df, match.ID = TRUE) # don't warn |
| 504 |
coordinates a |
| 505 |
a (1, 1) 5 |
| 506 |
b (2, 2) 4 |
| 507 |
c (3, 3) 3 |
| 508 |
d (4, 4) 2 |
| 509 |
e (5, 5) 1 |
| 510 |
> SpatialPointsDataFrame(pts, df, match.ID = FALSE) # don't warn |
| 511 |
coordinates a |
| 512 |
e (1, 1) 1 |
| 513 |
d (2, 2) 2 |
| 514 |
c (3, 3) 3 |
| 515 |
b (4, 4) 4 |
| 516 |
a (5, 5) 5 |
| 517 |
> df$m = letters[5:1] |
| 518 |
> SpatialPointsDataFrame(pts, df, match.ID = "m") # don't warn |
| 519 |
coordinates a m |
| 520 |
a (1, 1) 5 a |
| 521 |
b (2, 2) 4 b |
| 522 |
c (3, 3) 3 c |
| 523 |
d (4, 4) 2 d |
| 524 |
e (5, 5) 1 e |
| 525 |
> |
| 526 |
> dimnames(pts)[[1]] = letters[5:1] |
| 527 |
> pts |
| 528 |
[,1] [,2] |
| 529 |
e 1 1 |
| 530 |
d 2 2 |
| 531 |
c 3 3 |
| 532 |
b 4 4 |
| 533 |
a 5 5 |
| 534 |
> SpatialPointsDataFrame(pts, df) # don't warn: match doesn't reorder |
| 535 |
coordinates a m |
| 536 |
e (1, 1) 1 e |
| 537 |
d (2, 2) 2 d |
| 538 |
c (3, 3) 3 c |
| 539 |
b (4, 4) 4 b |
| 540 |
a (5, 5) 5 a |
| 541 |
> |
| 542 |
> # duplicated row name: |
| 543 |
> dimnames(pts)[[1]] = letters[c(1:4,1)] |
| 544 |
> pts |
| 545 |
[,1] [,2] |
| 546 |
a 1 1 |
| 547 |
b 2 2 |
| 548 |
c 3 3 |
| 549 |
d 4 4 |
| 550 |
a 5 5 |
| 551 |
> xx = try(x <- SpatialPointsDataFrame(pts, df)) |
| 552 |
Warning in SpatialPointsDataFrame(pts, df) : |
| 553 |
forming a SpatialPointsDataFrame based on maching IDs, not on record order. Use match.ID = FALSE to match on record order |
| 554 |
Error in SpatialPointsDataFrame(pts, df) : |
| 555 |
row.names of data and dimnames of coords do not match |
| 556 |
> class(xx) |
| 557 |
[1] "try-error" |
| 558 |
> xx |
| 559 |
[1] "Error in SpatialPointsDataFrame(pts, df) : \n row.names of data and dimnames of coords do not match\n" |
| 560 |
attr(,"class") |
| 561 |
[1] "try-error" |
| 562 |
attr(,"condition") |
| 563 |
<simpleError in SpatialPointsDataFrame(pts, df): row.names of data and dimnames of coords do not match> |
| 564 |
> SpatialPointsDataFrame(pts, df, match.ID = FALSE) |
| 565 |
Warning in validityMethod(object) : |
| 566 |
duplicate rownames are interpreted by rgeos as MultiPoints; use SpatialMultiPoints to define these; in future sp versions this warning will become an error |
| 567 |
coordinates a m |
| 568 |
e (1, 1) 1 e |
| 569 |
d (2, 2) 2 d |
| 570 |
c (3, 3) 3 c |
| 571 |
b (4, 4) 4 b |
| 572 |
a (5, 5) 5 a |
| 573 |
> try(x <- SpatialPointsDataFrame(pts, df, match.ID = TRUE)) # fail |
| 574 |
Error in SpatialPointsDataFrame(pts, df, match.ID = TRUE) : |
| 575 |
row.names of data and dimnames of coords do not match |
| 576 |
> |
| 577 |
> dimnames(pts)[[1]] = letters[5:1] |
| 578 |
> row.names(df) = letters[6:2] # non-matching row.names |
| 579 |
> SpatialPointsDataFrame(pts, df) # do not match.ID |
| 580 |
coordinates a m |
| 581 |
f (1, 1) 1 e |
| 582 |
e (2, 2) 2 d |
| 583 |
d (3, 3) 3 c |
| 584 |
c (4, 4) 4 b |
| 585 |
b (5, 5) 5 a |
| 586 |
> SpatialPointsDataFrame(pts, df, match.ID = FALSE) |
| 587 |
coordinates a m |
| 588 |
f (1, 1) 1 e |
| 589 |
e (2, 2) 2 d |
| 590 |
d (3, 3) 3 c |
| 591 |
c (4, 4) 4 b |
| 592 |
b (5, 5) 5 a |
| 593 |
> try(x <- SpatialPointsDataFrame(pts, df, match.ID = TRUE)) # fail |
| 594 |
Error in SpatialPointsDataFrame(pts, df, match.ID = TRUE) : |
| 595 |
row.names of data and coords do not match |
| 596 |
> |
| 597 |
> proc.time() |
| 598 |
user system elapsed |
| 599 |
1.70 0.25 1.92 |