forked from r-spatial/stars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sf.Rout.save
208 lines (203 loc) · 6.99 KB
/
sf.Rout.save
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> suppressPackageStartupMessages(library(stars))
> library(sf)
> #jp2 = system.file("jp2/B01.jp2", package = "stars")
> #(x = read_stars(jp2, options = c("OVERVIEW_LEVEL=3")))
> tif = system.file("tif/L7_ETMs.tif", package = "stars")
> #(x = read_stars(tif, options = c("OVERVIEW_LEVEL=3"))) # FIXME: breaks on windows
> (x = read_stars(tif)[,1:20,1:20])
stars object with 3 dimensions and 1 attribute
attribute(s):
L7_ETMs.tif
Min. : 17.0
1st Qu.: 44.0
Median : 58.0
Mean : 58.2
3rd Qu.: 70.0
Max. :130.0
dimension(s):
from to offset delta refsys point values x/y
x 1 20 288776 28.5 UTM Zone 25, Southern Hem... FALSE NULL [x]
y 1 20 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE NULL [y]
band 1 6 NA NA NA NA NULL
> # names(x) = "L7_ETM"
>
> # library(abind)
> # x = adrop(x)
> image(x)
> (sfc = st_as_sfc(x, as_points = FALSE))
Geometry set for 400 features
geometry type: POLYGON
dimension: XY
bbox: xmin: 288776.3 ymin: 9120191 xmax: 289346.3 ymax: 9120761
projected CRS: UTM Zone 25, Southern Hemisphere
First 5 geometries:
POLYGON ((288776.3 9120761, 288804.8 9120761, 2...
POLYGON ((288804.8 9120761, 288833.3 9120761, 2...
POLYGON ((288833.3 9120761, 288861.8 9120761, 2...
POLYGON ((288861.8 9120761, 288890.3 9120761, 2...
POLYGON ((288890.3 9120761, 288918.8 9120761, 2...
> plot(sfc, add =TRUE)
> (sfc = st_as_sfc(x, as_points = TRUE))
Geometry set for 400 features
geometry type: POINT
dimension: XY
bbox: xmin: 288790.5 ymin: 9120205 xmax: 289332 ymax: 9120747
projected CRS: UTM Zone 25, Southern Hemisphere
First 5 geometries:
POINT (288790.5 9120747)
POINT (288819 9120747)
POINT (288847.5 9120747)
POINT (288876 9120747)
POINT (288904.5 9120747)
> plot(sfc, add = TRUE)
>
> sf = st_as_sf(x, as_points = FALSE)
> plot(sf, border = NA)
> sf = st_as_sf(x[,,,1], as_points = FALSE, merge = TRUE)
> plot(sf, border = NA)
>
> sfc1 <- st_as_sfc(x, as_points = TRUE, use_cpp = TRUE, na.rm = FALSE)
> sfc2 <- st_as_sfc(x, as_points = TRUE, use_cpp = FALSE)
> identical(sfc1, sfc2)
[1] TRUE
>
> sfc1 <- st_as_sfc(x, as_points = FALSE, use_cpp = TRUE, na.rm = FALSE)
> sfc2 <- st_as_sfc(x, as_points = FALSE, use_cpp = FALSE)
> identical(sfc1, sfc2)
[1] TRUE
>
> # sf -> stars -> sf
> x = st_sfc(st_point(0:1), st_point(1:2), st_point(2:3))
> m = matrix(1:9,3)
> colnames(m) = c("a", "b", "c")
> foo = st_sf(m, geom = x)
> x = st_as_stars(foo)
> c(x)
stars object with 1 dimensions and 3 attributes
attribute(s):
a b c
Min. :1.0 Min. :4.0 Min. :7.0
1st Qu.:1.5 1st Qu.:4.5 1st Qu.:7.5
Median :2.0 Median :5.0 Median :8.0
Mean :2.0 Mean :5.0 Mean :8.0
3rd Qu.:2.5 3rd Qu.:5.5 3rd Qu.:8.5
Max. :3.0 Max. :6.0 Max. :9.0
dimension(s):
from to offset delta refsys point values
geom 1 3 NA NA NA TRUE POINT (0 1), POINT (1 2), POINT (2 3)
> st_redimension(x)
stars object with 2 dimensions and 1 attribute
attribute(s):
a.b.c
Min. :1
1st Qu.:3
Median :5
Mean :5
3rd Qu.:7
Max. :9
dimension(s):
from to offset delta refsys point values
geom 1 3 NA NA NA TRUE POINT (0 1), POINT (1 2), POINT (2 3)
new_dim 1 3 NA NA NA NA a, b, c
> c(x, x)
stars object with 1 dimensions and 6 attributes
attribute(s):
a b c a.1 b.1
Min. :1.0 Min. :4.0 Min. :7.0 Min. :1.0 Min. :4.0
1st Qu.:1.5 1st Qu.:4.5 1st Qu.:7.5 1st Qu.:1.5 1st Qu.:4.5
Median :2.0 Median :5.0 Median :8.0 Median :2.0 Median :5.0
Mean :2.0 Mean :5.0 Mean :8.0 Mean :2.0 Mean :5.0
3rd Qu.:2.5 3rd Qu.:5.5 3rd Qu.:8.5 3rd Qu.:2.5 3rd Qu.:5.5
Max. :3.0 Max. :6.0 Max. :9.0 Max. :3.0 Max. :6.0
c.1
Min. :7.0
1st Qu.:7.5
Median :8.0
Mean :8.0
3rd Qu.:8.5
Max. :9.0
dimension(s):
from to offset delta refsys point values
geom 1 3 NA NA NA TRUE POINT (0 1), POINT (1 2), POINT (2 3)
> (y = st_redimension(x, along = list(time = as.Date("2017-11-27") + 0:2)))
stars object with 2 dimensions and 1 attribute
attribute(s):
a.b.c
Min. :1
1st Qu.:3
Median :5
Mean :5
3rd Qu.:7
Max. :9
dimension(s):
from to offset delta refsys point
geom 1 3 NA NA NA TRUE
time 1 3 2017-11-27 1 days Date NA
values
geom POINT (0 1), POINT (1 2), POINT (2 3)
time NULL
> st_as_sf(y)
Simple feature collection with 3 features and 3 fields
geometry type: POINT
dimension: XY
bbox: xmin: 0 ymin: 1 xmax: 2 ymax: 3
CRS: NA
2017-11-27 2017-11-28 2017-11-29 geom
1 1 4 7 POINT (0 1)
2 2 5 8 POINT (1 2)
3 3 6 9 POINT (2 3)
> st_as_sf(st_as_stars(foo))
Simple feature collection with 3 features and 3 fields
geometry type: POINT
dimension: XY
bbox: xmin: 0 ymin: 1 xmax: 2 ymax: 3
CRS: NA
a b c geom
1 1 4 7 POINT (0 1)
2 2 5 8 POINT (1 2)
3 3 6 9 POINT (2 3)
>
> c(x,x,along=1) # NEEDS FIXING!
stars object with 1 dimensions and 3 attributes
attribute(s):
a b c
Min. :1.00 Min. :4.00 Min. :7.00
1st Qu.:1.25 1st Qu.:4.25 1st Qu.:7.25
Median :2.00 Median :5.00 Median :8.00
Mean :2.00 Mean :5.00 Mean :8.00
3rd Qu.:2.75 3rd Qu.:5.75 3rd Qu.:8.75
Max. :3.00 Max. :6.00 Max. :9.00
dimension(s):
from to offset delta refsys point values
geom 1 6 NA NA NA TRUE POINT (0 1),...,POINT (2 3)
> # st_as_stars.sfc
> st_as_stars(st_geometry(st_as_sf(y)), nx = 10, ny = 10, as_points = FALSE)
stars object with 2 dimensions and 1 attribute
attribute(s):
values
Min. :0.00
1st Qu.:0.00
Median :0.00
Mean :0.06
3rd Qu.:0.00
Max. :1.00
dimension(s):
from to offset delta refsys point values x/y
x 1 10 0 0.2 NA NA NULL [x]
y 1 10 3 -0.2 NA NA NULL [y]
>
> proc.time()
user system elapsed
1.237 0.066 1.303