Examples for 'stars::st_crop'


crop a stars object

Aliases: st_crop st_crop.mdim st_crop.stars_proxy st_crop.stars

Keywords:

### ** Examples

l7 = read_stars(system.file("tif/L7_ETMs.tif", package = "stars"))
d = st_dimensions(l7)

# area around cells 3:10 (x) and 4:11 (y):
offset = c(d[["x"]]$offset, d[["y"]]$offset)
res = c(d[["x"]]$delta, d[["y"]]$delta)
bb = st_bbox(c(xmin = offset[1] + 2 * res[1],
        ymin = offset[2] + 11 * res[2],
        xmax = offset[1] + 10 * res[1],
        ymax = offset[2] +  3 * res[2]), crs = st_crs(l7))
l7[bb]
stars object with 3 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median     Mean 3rd Qu. Max.
L7_ETMs.tif    17      43   55.5 56.36979      65  111
dimension(s):
     from to  offset delta                     refsys point x/y
x       3 10  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
y       4 11 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
band    1  6      NA    NA                         NA    NA    
# equivalent:
st_crop(l7, bb)
stars object with 3 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median     Mean 3rd Qu. Max.
L7_ETMs.tif    17      43   55.5 56.36979      65  111
dimension(s):
     from to  offset delta                     refsys point x/y
x       3 10  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
y       4 11 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
band    1  6      NA    NA                         NA    NA    
plot(l7[,1:13,1:13,1], reset = FALSE)
image(l7[bb,,,1], add = TRUE, col = sf.colors())
plot(st_as_sfc(bb), add = TRUE, border = 'green', lwd = 2)
plot of chunk example-stars-st_crop-1
# slightly smaller bbox:
bb = st_bbox(c(xmin = offset[1] + 2.1 * res[1],
        ymin = offset[2] + 10.9 * res[2],
        xmax = offset[1] +  9.9 * res[1],
        ymax = offset[2] +  3.1 * res[2]), crs = st_crs(l7))
l7[bb]
stars object with 3 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median     Mean 3rd Qu. Max.
L7_ETMs.tif    17      43   55.5 56.36979      65  111
dimension(s):
     from to  offset delta                     refsys point x/y
x       3 10  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
y       4 11 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
band    1  6      NA    NA                         NA    NA    
plot(l7[,1:13,1:13,1], reset = FALSE)
image(l7[bb,,,1], add = TRUE, col = sf.colors())
plot(st_as_sfc(bb), add = TRUE, border = 'green', lwd = 2)
plot of chunk example-stars-st_crop-1
# slightly larger bbox:
bb = st_bbox(c(xmin = offset[1] + 1.9 * res[1],
        ymin = offset[2] + 11.1 * res[2],
        xmax = offset[1] + 10.1 * res[1],
        ymax = offset[2] +  2.9 * res[2]), crs = st_crs(l7))
l7[bb]
stars object with 3 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median     Mean 3rd Qu. Max.
L7_ETMs.tif    17      43     55 56.11167      66  112
dimension(s):
     from to  offset delta                     refsys point x/y
x       2 11  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
y       3 12 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
band    1  6      NA    NA                         NA    NA    
plot(l7[,1:13,1:13,1], reset = FALSE)
image(l7[bb,,,1], add = TRUE, col = sf.colors())
plot(st_as_sfc(bb), add = TRUE, border = 'green', lwd = 2)
plot of chunk example-stars-st_crop-1
# half a cell size larger bbox:
bb = st_bbox(c(xmin = offset[1] + 1.49 * res[1],
        ymin = offset[2] + 11.51 * res[2],
        xmax = offset[1] + 10.51 * res[1],
        ymax = offset[2] +  2.49 * res[2]), crs = st_crs(l7))
l7[bb]
stars object with 3 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median     Mean 3rd Qu. Max.
L7_ETMs.tif    17      43     55 56.11167      66  112
dimension(s):
     from to  offset delta                     refsys point x/y
x       2 11  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
y       3 12 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
band    1  6      NA    NA                         NA    NA    
plot(l7[,1:13,1:13,1], reset = FALSE)
image(l7[bb,,,1], add = TRUE, col = sf.colors())
plot(st_as_sfc(bb), add = TRUE, border = 'green', lwd = 2)
plot of chunk example-stars-st_crop-1

[Package stars version 0.6-7 Index]