jjrom / resto

A metadata catalog and search engine for geospatialized data
Apache License 2.0
57 stars 19 forks source link

Search api not working with OpticalModel filters #375

Closed volodin-artem closed 1 year ago

volodin-artem commented 1 year ago

Describe the bug Hello. When i put colletion with SatelliteModel or OpticalModel prop in json and trying to search SatelliteModel filters like resolution, sunAzimuth and other, i getting empty array which is very weird because OpticalModel filters like cloudCover working well and i getting correct json. Resto is creating a row in feature_(satellite / optical) table with correct id so i guess it's not a problem in it. I'm pretty sure it's my trouble but i really don't see any problems with my Resto or json files. I hope you can help me.

To Reproduce Steps to reproduce the behavior:

  1. Put this collection in Resto or collection in the Additional context below

    Collection So i send this json to my resto server with model property with value OpticalModel or SatelliteModel which is does not matter at this point ```json { "type": "Collection", "stac_version": "1.0.0", "id": "AMAZONIA1-WFI", "description": "AMAZONIA1 WFI camera catalog", "model": "OpticalModel", "stac_extensions": [ "https://stac-extensions.github.io/item-assets/v1.0.0/schema.json" ], "license": "CC-BY-SA-3.0", "providers": [ { "name": "Instituto Nacional de Pesquisas Espaciais, INPE", "roles": [ "producer" ], "url": "http://www.inpe.br/amazonia1" }, { "name": "AMS Kepler", "roles": [ "processor" ], "description": "Convert INPE's original TIFF to COG and copy to Amazon Web Services", "url": "https://amskepler.com" }, { "name": "Amazon Web Services", "roles": [ "host" ], "url": "https://registry.opendata.aws/amazonia" } ], "extent": { "spatial": { "bbox": [ [ -180.0, -83.0, 180.0, 83.0 ] ] }, "temporal": { "interval": [ [ "2021-02-28T00:00:00Z", null ] ] } }, "summaries": { "gsd": [ 64.0 ], "sat:platform_international_designator": [ "2021-015A" ], "sat:orbit_state": [ "ascending", "descending" ] }, "links": [ { "rel": "self", "href": "https://cbers-stac-1-0-0.s3.amazonaws.com/AMAZONIA1/WFI/collection.json" }, { "rel": "root", "href": "https://cbers-stac-1-0-0.s3.amazonaws.com/catalog.json" }, { "rel": "parent", "href": "../catalog.json" }, { "rel": "child", "href": "021/catalog.json" }, { "rel": "child", "href": "023/catalog.json" }, { "rel": "child", "href": "029/catalog.json" }, { "rel": "child", "href": "032/catalog.json" }, { "rel": "child", "href": "033/catalog.json" }, { "rel": "child", "href": "034/catalog.json" }, { "rel": "child", "href": "035/catalog.json" }, { "rel": "child", "href": "036/catalog.json" }, { "rel": "child", "href": "037/catalog.json" }, { "rel": "child", "href": "038/catalog.json" }, { "rel": "child", "href": "039/catalog.json" }, { "rel": "child", "href": "040/catalog.json" }, { "rel": "child", "href": "041/catalog.json" } ], "item_assets": { "thumbnail": { "title": "Thumbnail", "type": "image/png" }, "metadata": { "title": "INPE original metadata", "type": "text/xml" }, "B1": { "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B1", "common_name": "blue" } ] }, "B2": { "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B2", "common_name": "green" } ] }, "B3": { "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B3", "common_name": "red" } ] }, "B4": { "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B4", "common_name": "nir" } ] } }, "title": "AMAZONIA1-WFI" } ```

  1. Add a feature to new collection
Feature ```json { "stac_version": "1.0.0", "stac_extensions": [ "https://stac-extensions.github.io/projection/v1.0.0/schema.json", "https://stac-extensions.github.io/view/v1.0.0/schema.json", "https://stac-extensions.github.io/eo/v1.0.0/schema.json", "https://stac-extensions.github.io/sat/v1.0.0/schema.json" ], "id": "AMAZONIA_1_WFI_20210319_041_017_L4", "type": "Feature", "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -81.80162, -14.573639 ], [ -77.700519, -15.259091 ], [ -76.166587, -8.442401 ], [ -80.166454, -7.78974 ], [ -81.80162, -14.573639 ] ] ] ] }, "bbox": [ -81.827286, -15.204054, -76.154356, -7.742466 ], "collection": "AMAZONIA1-WFI", "properties": { "datetime": "2021-03-19T15:27:10Z", "platform": "amazonia-1", "instruments": [ "WFI" ], "gsd": 64, "view:sun_azimuth": 70, "view:sun_elevation": 60, "view:off_nadir": 0.000141652, "proj:epsg": 32717, "sat:platform_international_designator": "2021-015A", "sat:orbit_state": "descending", "amazonia:data_type": "L4", "amazonia:path": 41, "amazonia:row": 17, "eo:cloud_cover": 60 }, "links": [ { "rel": "self", "href": "https://cbers-stac-1-0-0.s3.amazonaws.com/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4.json" }, { "rel": "parent", "href": "https://cbers-stac-1-0-0.s3.amazonaws.com/AMAZONIA1/WFI/041/017/catalog.json" }, { "rel": "collection", "href": "https://cbers-stac-1-0-0.s3.amazonaws.com/AMAZONIA1/WFI/collection.json" } ], "assets": { "thumbnail": { "href": "https://s3.amazonaws.com/amazonia-meta-pds/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4/AMAZONIA_1_WFI_20210319_041_017.png", "type": "image/png" }, "metadata": { "href": "s3://amazonia-pds/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4/AMAZONIA_1_WFI_20210319_041_017_L4_LEFT_BAND2.xml", "title": "INPE original metadata", "type": "text/xml" }, "B1": { "href": "s3://amazonia-pds/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4/AMAZONIA_1_WFI_20210319_041_017_L4_LEFT_BAND1.tif", "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B1", "common_name": "blue" } ] }, "B2": { "href": "s3://amazonia-pds/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4/AMAZONIA_1_WFI_20210319_041_017_L4_LEFT_BAND2.tif", "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B2", "common_name": "green" } ] }, "B3": { "href": "s3://amazonia-pds/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4/AMAZONIA_1_WFI_20210319_041_017_L4_LEFT_BAND3.tif", "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B3", "common_name": "red" } ] }, "B4": { "href": "s3://amazonia-pds/AMAZONIA1/WFI/041/017/AMAZONIA_1_WFI_20210319_041_017_L4/AMAZONIA_1_WFI_20210319_041_017_L4_LEFT_BAND4.tif", "type": "image/tiff; application=geotiff; profile=cloud-optimized", "eo:bands": [ { "name": "B4", "common_name": "nir" } ] } } } ```
  1. Go search an features with api. For example, i got this URL

http://192.168.4.120:5252/search?resolution=64

  1. See a empty result array for any SatelliteModel props and actual correct result for OpticalModel prop if we are getting data like that http://192.168.4.120:5252/search?cloudCover=60. I tried to get data like this

http://192.168.4.120:5252/search?offNadir=0.000141652&model=SatelliteModel but it does not working as well and i always getting json like that:

Empty result ```json { "type": "FeatureCollection", "id": "3e3db103-0690-5785-bf1e-8e9918c4f661", "context": { "returned": 0, "limit": 20, "matched": 0, "exactCount": true, "startIndex": 1, "query": { "inputFilters": { "model": "SatelliteModel", "q": "#sunElevation:60" }, "appliedFilters": { "model": { "value": "SatelliteModel", "operation": "=" }, "view:sun_elevation": { "value": "60", "operation": "keywords" } }, "processingTime": 0.013104915618896484 } }, "links": [ { "rel": "self", "type": "application/geo+json", "href": "http://127.0.0.1:5252/search?&sunElevation=60&model=SatelliteModel" }, { "rel": "search", "type": "application/opensearchdescription+xml", "href": "http://127.0.0.1:5252/services/osdd" } ], "timeStamp": "2023-05-25T09:28:55Z", "numberMatched": 0, "numberReturned": 0, "features": [] } ```

Expected behavior A json with SatelliteModel props.

Desktop (please complete the following information):

Additional context Links to STAC sources: Collection: https://cbers-stac-1-0-0.s3.amazonaws.com/AMAZONIA1/WFI/collection.json Feature: https://cbers-stac-1-0-0.s3.amazonaws.com/AMAZONIA1/WFI/021/009/AMAZONIA_1_WFI_20210319_021_009_L4.json

jjrom commented 1 year ago

Hi @volodin-artem ! Thanks for raising this issue.

First of all both your updated collection (i.e. with additional model property) and the POST procedure are correct. To be sure that the collection is correctly handled, you can check the resto:info property returned in the collection description at this url :

http://192.168.4.120:5252/collections/AMAZONIA1-WFI?_pretty=1

The resto:info gives you the collection model, so something like this in your case :

"resto:info": {
        "model": "OpticalModel",
        "lineage": [
            "DefaultModel",
            "LandCoverModel",
            "SatelliteModel",
            "OpticalModel"
        ],
       [...]

Now it is important to note that only properties that are explicitly described as searchable in the model - (i.e. searchFilters) can be effectively searched.

So for an OpticalModel collection, search on resolution and cloudCover should work. In your case it was not working because the search on resolution was disabled. I just corrected it in https://github.com/jjrom/resto/pull/376 so a docker pull on jjrom/resto:latestshould do the job !

However, the offNadir property is not searchable so it is a normal behavior that this cannot be searched.

volodin-artem commented 1 year ago

Yeah, that's working great. Thank you very much for you answer.

jjrom commented 1 year ago

Great :) By the way, I just add a "model" query parameter in the collection POST (see #377) so you don't have to add a "model" property to the collection description i.e. if you modify POST like this:

curl -X POST -d@collection.json "http://localhost:5252/collections?model=OpticalModel"

It will automatically assign the OpticalModel to the input collection

volodin-artem commented 1 year ago

Great :) By the way, I just add a "model" query parameter in the collection POST (see #377) so you don't have to add a "model" property to the collection description i.e. if you modify POST like this:

curl -X POST -d@collection.json "http://localhost:5252/collections?model=OpticalModel"

It will automatically assign the OpticalModel to the input collection

Woah. It's really useful for me because i got some collections and i was thinking about best way to insert an extra prop in json collections before post it, but i your advice is the best way for sure. You really helped me out. A huge thank you!