forked from r-spatial/stars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectilinear.Rout.save
93 lines (88 loc) · 3.06 KB
/
rectilinear.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
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
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))
> tif = system.file("tif/L7_ETMs.tif", package = "stars")
> x = read_stars(tif)
> (xx = x[,c(1:347,349),c(1:350,352),]) # rectilinear: one-but-last row & col missing
stars object with 3 dimensions and 1 attribute
attribute(s):
L7_ETMs.tif
Min. : 1.00
1st Qu.: 54.00
Median : 69.00
Mean : 68.99
3rd Qu.: 86.00
Max. :255.00
dimension(s):
from to offset delta refsys point
x 1 348 NA NA UTM Zone 25, Southern Hem... FALSE
y 1 351 NA NA UTM Zone 25, Southern Hem... FALSE
band 1 6 NA NA NA NA
values x/y
x [288790.5,288819),...,[298708.5,298737) [x]
y [9120747,9120718),...,[9110743,9110715) [y]
band NULL
> image(xx) # chooses useRaster itself
> # see also tidy.R for a ggplot example, leaving out the row.
>
> m = matrix(1:16, 4, 4)
> x = 1:4
> y = 2:5
> (st = st_as_stars(list(m = m), dimensions = st_dimensions(x = x, y = y)))
stars object with 2 dimensions and 1 attribute
attribute(s):
m
Min. : 1.00
1st Qu.: 4.75
Median : 8.50
Mean : 8.50
3rd Qu.:12.25
Max. :16.00
dimension(s):
from to offset delta refsys point values x/y
x 1 4 1 1 NA FALSE NULL [x]
y 1 4 2 1 NA FALSE NULL [y]
> st = st_set_dimensions(st, 1, values = c(1,2,3,4,6))
> st = st_set_dimensions(st, 2, values = c(2,3,4,5,8))
> try(st_set_dimensions(st, 2, values = c(2,3,4,5,8,20))) # one too many
Error in st_set_dimensions(st, 2, values = c(2, 3, 4, 5, 8, 20)) :
length of values ( 6 ) does not match length of dimension 2 ( 4 )
>
> # $<-.stars:
> st$foo = st$m * 2
> st
stars object with 2 dimensions and 2 attributes
attribute(s):
m foo
Min. : 1.00 Min. : 2.0
1st Qu.: 4.75 1st Qu.: 9.5
Median : 8.50 Median :17.0
Mean : 8.50 Mean :17.0
3rd Qu.:12.25 3rd Qu.:24.5
Max. :16.00 Max. :32.0
dimension(s):
from to offset delta refsys point values x/y
x 1 4 NA NA NA FALSE [1,2),...,[4,6) [x]
y 1 4 NA NA NA FALSE [2,3),...,[5,8) [y]
>
> # st_as_sf:
>
> if (utils::packageVersion("sf") > "0.7.2") {
+ plot(st_as_sf(st, as_points = FALSE), axes = TRUE)
+ }
>
> image(st, text_values = TRUE, axes = TRUE)
>
> proc.time()
user system elapsed
1.299 0.225 1.211