| 1 |
|
| 2 |
R version 3.2.2 (2015-08-14) -- "Fire Safety" |
| 3 |
Copyright (C) 2015 The R Foundation for Statistical Computing |
| 4 |
Platform: x86_64-pc-linux-gnu (64-bit) |
| 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 |
> set.seed(1331) |
| 19 |
> cl1 = cbind(rnorm(3, 10), rnorm(3, 10)) |
| 20 |
> cl2 = cbind(rnorm(5, 10), rnorm(5, 0)) |
| 21 |
> cl3 = cbind(rnorm(7, 0), rnorm(7, 10)) |
| 22 |
> |
| 23 |
> library(sp) |
| 24 |
> mp = SpatialMultiPoints(list(cl1, cl2, cl3)) |
| 25 |
> plot(mp, col = 2, cex = 1, pch = 1:3) |
| 26 |
> mp |
| 27 |
SpatialMultiPoints: |
| 28 |
[[1]] |
| 29 |
[,1] [,2] |
| 30 |
[1,] 9.377732 11.529001 |
| 31 |
[2,] 11.136951 9.845501 |
| 32 |
[3,] 9.762133 11.236448 |
| 33 |
|
| 34 |
[[2]] |
| 35 |
[,1] [,2] |
| 36 |
[1,] 10.386325 -0.5827836 |
| 37 |
[2,] 10.532143 -0.3125824 |
| 38 |
[3,] 9.796604 -1.0536246 |
| 39 |
[4,] 10.272737 -0.7188880 |
| 40 |
[5,] 11.364576 -1.0525404 |
| 41 |
|
| 42 |
[[3]] |
| 43 |
[,1] [,2] |
| 44 |
[1,] -0.8441413 9.184820 |
| 45 |
[2,] 1.1420848 10.767842 |
| 46 |
[3,] 1.9479070 10.844674 |
| 47 |
[4,] -0.4512836 10.718613 |
| 48 |
[5,] 0.6695716 10.349259 |
| 49 |
[6,] 0.1269003 10.508655 |
| 50 |
[7,] -0.7273297 9.233874 |
| 51 |
|
| 52 |
Coordinate Reference System (CRS) arguments: NA |
| 53 |
> mp[1:2] |
| 54 |
SpatialMultiPoints: |
| 55 |
[[1]] |
| 56 |
[,1] [,2] |
| 57 |
[1,] 9.377732 11.529001 |
| 58 |
[2,] 11.136951 9.845501 |
| 59 |
[3,] 9.762133 11.236448 |
| 60 |
|
| 61 |
[[2]] |
| 62 |
[,1] [,2] |
| 63 |
[1,] 10.386325 -0.5827836 |
| 64 |
[2,] 10.532143 -0.3125824 |
| 65 |
[3,] 9.796604 -1.0536246 |
| 66 |
[4,] 10.272737 -0.7188880 |
| 67 |
[5,] 11.364576 -1.0525404 |
| 68 |
|
| 69 |
Coordinate Reference System (CRS) arguments: NA |
| 70 |
> as(mp, "SpatialPoints") |
| 71 |
SpatialPoints: |
| 72 |
coords.x1 coords.x2 |
| 73 |
[1,] 9.3777317 11.5290011 |
| 74 |
[2,] 11.1369510 9.8455013 |
| 75 |
[3,] 9.7621333 11.2364485 |
| 76 |
[4,] 10.3863251 -0.5827836 |
| 77 |
[5,] 10.5321429 -0.3125824 |
| 78 |
[6,] 9.7966038 -1.0536246 |
| 79 |
[7,] 10.2727371 -0.7188880 |
| 80 |
[8,] 11.3645757 -1.0525404 |
| 81 |
[9,] -0.8441413 9.1848197 |
| 82 |
[10,] 1.1420848 10.7678420 |
| 83 |
[11,] 1.9479070 10.8446745 |
| 84 |
[12,] -0.4512836 10.7186131 |
| 85 |
[13,] 0.6695716 10.3492587 |
| 86 |
[14,] 0.1269003 10.5086550 |
| 87 |
[15,] -0.7273297 9.2338744 |
| 88 |
attr(,"groupIndex") |
| 89 |
[1] "1" "1" "1" "2" "2" "2" "2" "2" "3" "3" "3" "3" "3" "3" "3" |
| 90 |
Coordinate Reference System (CRS) arguments: NA |
| 91 |
> |
| 92 |
> print(mp, asWKT=TRUE, digits=3) |
| 93 |
SpatialMultiPoints: |
| 94 |
geometry |
| 95 |
1 MULTIPOINT (9.38 11.5,11.1 9.85,9.76 11.2) |
| 96 |
2 MULTIPOINT (10.4 -0.583,10.5 -0.313,9.8 -1.05,10.3 -0.719,11.4 -1.05) |
| 97 |
3 MULTIPOINT (-0.844 9.18,1.14 10.8,1.95 10.8,-0.451 10.7,0.67 10.3,0.127 10.5,-0.727 9.23) |
| 98 |
Coordinate Reference System (CRS) arguments: NA |
| 99 |
> |
| 100 |
> mpdf = SpatialMultiPointsDataFrame(list(cl1, cl2, cl3), data.frame(a = 1:3)) |
| 101 |
> mpdf |
| 102 |
coordinates a |
| 103 |
1 (9.377732, 11.529) 1 |
| 104 |
1.1 (11.13695, 9.845501) 1 |
| 105 |
1.2 (9.762133, 11.23645) 1 |
| 106 |
2 (10.38633, -0.5827836) 2 |
| 107 |
2.1 (10.53214, -0.3125824) 2 |
| 108 |
2.2 (9.796604, -1.053625) 2 |
| 109 |
2.3 (10.27274, -0.718888) 2 |
| 110 |
2.4 (11.36458, -1.05254) 2 |
| 111 |
3 (-0.8441413, 9.18482) 3 |
| 112 |
3.1 (1.142085, 10.76784) 3 |
| 113 |
3.2 (1.947907, 10.84467) 3 |
| 114 |
3.3 (-0.4512836, 10.71861) 3 |
| 115 |
3.4 (0.6695716, 10.34926) 3 |
| 116 |
3.5 (0.1269003, 10.50866) 3 |
| 117 |
3.6 (-0.7273297, 9.233874) 3 |
| 118 |
> print(mpdf, asWKT=TRUE, digits=3) |
| 119 |
geometry |
| 120 |
1 MULTIPOINT (9.38 11.5,11.1 9.85,9.76 11.2) |
| 121 |
2 MULTIPOINT (10.4 -0.583,10.5 -0.313,9.8 -1.05,10.3 -0.719,11.4 -1.05) |
| 122 |
3 MULTIPOINT (-0.844 9.18,1.14 10.8,1.95 10.8,-0.451 10.7,0.67 10.3,0.127 10.5,-0.727 9.23) |
| 123 |
a |
| 124 |
1 1 |
| 125 |
2 2 |
| 126 |
3 3 |
| 127 |
> |
| 128 |
> plot(mpdf, col = mpdf$a, cex = 1:3) |
| 129 |
> as(mpdf, "data.frame") |
| 130 |
X1 X2 index a |
| 131 |
1 9.3777317 11.5290011 1 1 |
| 132 |
1.1 11.1369510 9.8455013 1 1 |
| 133 |
1.2 9.7621333 11.2364485 1 1 |
| 134 |
2 10.3863251 -0.5827836 2 2 |
| 135 |
2.1 10.5321429 -0.3125824 2 2 |
| 136 |
2.2 9.7966038 -1.0536246 2 2 |
| 137 |
2.3 10.2727371 -0.7188880 2 2 |
| 138 |
2.4 11.3645757 -1.0525404 2 2 |
| 139 |
3 -0.8441413 9.1848197 3 3 |
| 140 |
3.1 1.1420848 10.7678420 3 3 |
| 141 |
3.2 1.9479070 10.8446745 3 3 |
| 142 |
3.3 -0.4512836 10.7186131 3 3 |
| 143 |
3.4 0.6695716 10.3492587 3 3 |
| 144 |
3.5 0.1269003 10.5086550 3 3 |
| 145 |
3.6 -0.7273297 9.2338744 3 3 |
| 146 |
Warning message: |
| 147 |
In data.row.names(row.names, rowsi, i) : |
| 148 |
some row.names duplicated: 2,3,5,6,7,8,10,11,12,13,14,15 --> row.names NOT used |
| 149 |
> mpdf[1:2,] |
| 150 |
coordinates a |
| 151 |
1 (9.377732, 11.529) 1 |
| 152 |
1.1 (11.13695, 9.845501) 1 |
| 153 |
1.2 (9.762133, 11.23645) 1 |
| 154 |
2 (10.38633, -0.5827836) 2 |
| 155 |
2.1 (10.53214, -0.3125824) 2 |
| 156 |
2.2 (9.796604, -1.053625) 2 |
| 157 |
2.3 (10.27274, -0.718888) 2 |
| 158 |
2.4 (11.36458, -1.05254) 2 |
| 159 |
> as(mpdf, "SpatialPointsDataFrame") |
| 160 |
coordinates a |
| 161 |
1 (9.377732, 11.529) 1 |
| 162 |
1.1 (11.13695, 9.845501) 1 |
| 163 |
1.2 (9.762133, 11.23645) 1 |
| 164 |
2 (10.38633, -0.5827836) 2 |
| 165 |
2.1 (10.53214, -0.3125824) 2 |
| 166 |
2.2 (9.796604, -1.053625) 2 |
| 167 |
2.3 (10.27274, -0.718888) 2 |
| 168 |
2.4 (11.36458, -1.05254) 2 |
| 169 |
3 (-0.8441413, 9.18482) 3 |
| 170 |
3.1 (1.142085, 10.76784) 3 |
| 171 |
3.2 (1.947907, 10.84467) 3 |
| 172 |
3.3 (-0.4512836, 10.71861) 3 |
| 173 |
3.4 (0.6695716, 10.34926) 3 |
| 174 |
3.5 (0.1269003, 10.50866) 3 |
| 175 |
3.6 (-0.7273297, 9.233874) 3 |
| 176 |
> |
| 177 |
> # aggregate SpatialPointsDataFrame to SpatialMultiPointsDataFrame: |
| 178 |
> demo(meuse, ask = FALSE, echo = FALSE) |
| 179 |
> a = aggregate(meuse[c("zinc", "lead")], list(meuse$ffreq)) |
| 180 |
> spplot(a[c("zinc", "lead")]) |
| 181 |
> |
| 182 |
> proc.time() |
| 183 |
user system elapsed |
| 184 |
0.660 0.323 0.656 |