JuliaClimate / STAC.jl

SpatioTemporal Asset Catalog (STAC) julia client
MIT License
28 stars 3 forks source link

Implement STAC API - Query Fragment #14

Closed Alexander-Barth closed 1 year ago

Alexander-Barth commented 1 year ago

This is currently a candiate extension:

https://github.com/radiantearth/stac-api-spec/tree/master/fragments/query

As suggested by @visr, we could implemented it here, as it is also implemented in pystac:

search = catalog.search(
    collections=["sentinel-2-l2a"],
    bbox=bbox,
    datetime=time_range,
    query={"eo:cloud_cover": {"lt": 20}},
)
search = catalog.search(
    collections=["goes-cmi"],
    bbox=[-67.2729, 25.6000, -61.7999, 27.5423],
    datetime=["2018-09-11T13:00:00Z", "2018-09-11T15:40:00Z"],
    query={"goes:image-type": {"eq": "MESOSCALE"}},
)

https://planetarycomputer.microsoft.com/docs/quickstarts/reading-stac/

I am wondering if we can make the API nicers by using a macro, any ideas?

STAC.search(..., query = @STACQL("goes:image-type" == "MESOSCALE" && "eo:cloud_cover" <= 50))
visr commented 1 year ago

I am wondering if we can make the API nicers by using a macro, any ideas?

I don't think the macro is that much nicer than just using normal syntax. I'm a bit of a macro minimalist though.

Looking at the rather complex query example from the spec, this is what it would look like with regular syntax:, which IMO is quite ok, and doesn't have the mental overhead of trying to guess what a macro is doing.

query = Dict(
  "stringAttr1"    => Dict("endsWith"=>"xyz", "startsWith"=>"abc"),
  "stringAttr2"    => Dict("contains"=>"mnop"),
  "stringAttr3"    => Dict("in"=>["landsat", "modis", "naip"]),
  "eo:cloud_cover" => Dict("lte"=>10, "gte"=>0),
)
Alexander-Barth commented 1 year ago

Thank you for your feedback, this is implemented now using the API as you suggested.

https://github.com/JuliaClimate/STAC.jl/blob/main/test/runtests.jl#L105-L110

Also CQL2 (a bit more verbose) filter work in my tests with the filter parameter for search.