if (FALSE) {
# Standard comparison operators in rstac:
# Creating a stac search query
req <- stac("https://planetarycomputer.microsoft.com/api/stac/v1") %>%
stac_search(limit = 5)
# Equal operator '=' with collection property
req %>% ext_filter(collection == "sentinel-2-l2a") %>% post_request()
# Not equal operator '!=' with collection property
req %>% ext_filter(collection != "sentinel-2-l2a") %>% post_request()
# Less than or equal operator '<=' with datetime property
req %>% ext_filter(datetime <= "1986-01-01") %>% post_request()
# Greater than or equal '>=' with AND operator
req %>% ext_filter(collection == "sentinel-2-l2a" &&
`s2:vegetation_percentage` >= 50 &&
`eo:cloud_cover` <= 10) %>% post_request()
# Advanced comparison operators
# 'LIKE' operator
req %>% ext_filter(collection %like% "modis%") %>% post_request()
# 'IN' operator
req %>% ext_filter(
collection %in% c("landsat-c2-l2", "sentinel-2-l2a") &&
datetime > "2019-01-01" &&
datetime < "2019-06-01") %>%
post_request()
# Spatial operator
# Lets create a polygon with list
polygon <- list(
type = "Polygon",
coordinates = list(
matrix(c(-62.34499836, -8.57414572,
-62.18858174, -8.57414572,
-62.18858174, -8.15351185,
-62.34499836, -8.15351185,
-62.34499836, -8.57414572),
ncol = 2, byrow = TRUE)
)
)
# 'S_INTERSECTS' spatial operator with polygon and geometry property
req %>% ext_filter(collection == "sentinel-2-l2a" &&
s_intersects(geometry, {{polygon}})) %>% post_request()
# 'S_CONTAINS' spatial operator with point and geometry property
point <- list(type = "Point", coordinates = c(-62.45792211, -8.61158488))
req %>% ext_filter(collection == "landsat-c2-l2" &&
s_contains(geometry, {{point}})) %>% post_request()
# 'S_CROSSES' spatial operator with linestring and geometry property
linestring <- list(
type = "LineString",
coordinates = matrix(
c(-62.55735320, -8.43329465, -62.21791603, -8.36815014),
ncol = 2, byrow = TRUE
)
)
req %>% ext_filter(collection == "landsat-c2-l2" &&
s_crosses(geometry, {{linestring}})) %>% post_request()
# Temporal operator
# 'T_INTERSECTS' temporal operator with datetime property
req %>% ext_filter(
collection == "landsat-c2-l2" &&
t_intersects(datetime, interval("1985-07-16T05:32:00Z",
"1985-07-24T16:50:35Z"))) %>%
post_request()
# 'T_DURING' temporal operator with datetime property
req %>%
ext_filter(collection == "landsat-c2-l2" &&
t_during(datetime,
interval("2022-07-16T05:32:00Z", ".."))) %>%
post_request()
# 'T_BEFORE' temporal operator with datetime property
req %>%
ext_filter(collection == "landsat-c2-l2" &&
t_before(datetime, timestamp("2022-07-16T05:32:00Z"))) %>%
post_request()
# 'T_AFTER' temporal operator with datetime property
req %>%
ext_filter(collection == "landsat-c2-l2" &&
t_after(datetime, timestamp("2022-07-16T05:32:00Z"))) %>%
post_request()
# Shows how CQL2 expression (TEXT format)
cql2_text(collection == "landsat-c2-l2" &&
s_crosses(geometry, {{linestring}}))
# Shows how CQL2 expression (JSON format)
cql2_json(collection == "landsat-c2-l2" &&
t_after(datetime, timestamp("2022-07-16T05:32:00Z")))
}
Run the code above in your browser using DataLab