gost / server

GOST - Go implementation of OGC SensorThings API
MIT License
61 stars 19 forks source link

Filtering over nested properties #169

Open Alystrasz opened 4 years ago

Alystrasz commented 4 years ago

Hello, I'm trying to filter a thing's locations, expanding its historical locations (since Things(42)/Locations only returns the current location); the objective is to match locations present in a given area.

Here's the request :

v1.0/Things(42)/HistoricalLocations
    ?$expand=Locations
    &$filter=st_within(location, geography'POLYGON ((-4 -11, 4 -11, 4 11, -4 11, -4 -11))')

Unfortunately, it returns { "value": null }. This is what my Location entities look like:

{
   "@iot.id": 708,
   "@iot.selfLink": "[...]/v1.0/Locations(708)",
   "name": "42",
   "description": "Location of Station 71",
   "encodingType": "application/vnd.geo+json",
   "location": {
      "coordinates": [ 3.128898, 10.095246 ],
      "properties": {
         "height": "5",
         "receptionTime": "1745420000"
      },
      "type": "Point"
   },
   "Things@iot.navigationLink": "[...]/v1.0/Locations(708)/Things",
   "HistoricalLocations@iot.navigationLink": "[...]/v1.0/Locations(708)/HistoricalLocations"
}
  1. How can I geo-filter locations starting from HistoricalLocations?
  2. Is there a way to filter locations based on any of the "properties" (e.g. receptionTime)?
bertt commented 4 years ago

Hi, we did a quick analysis, some remarks:

question 1:

v1.0/Things(42)/HistoricalLocations?$expand=Locations($filter=st_within(location, geography'POLYGON ((-4 -11, 4 -11, 4 11, -4 11, -4 -11))'))

However this does also not correct results. This needs to be further analyzed.

question 2: At the moment filtering locations on properties is not possible. Maybe it's defined in the SensorThings 1.1 spec.

tebben commented 4 years ago

Regarding the solution of bert, the result you will get is all HistoricalLocations with or without expanded locations. What you probably want is relation filtering

v1.0/Things(2704005)/HistoricalLocations?$expand=Locations&$filter=st_within(Locations/location, geography'POLYGON((-4 -11, 4 -11, 4 11, -4 11, -4 -11))')

This will return only the HistoricalLocations with expanded locations that are within your geometry, however relation filtering is not yet implemented in GOST, I hope I have some time to work on this soon