Filtering over nested properties
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"
},
"[email protected]": "[...]/v1.0/Locations(708)/Things",
"[email protected]": "[...]/v1.0/Locations(708)/HistoricalLocations"
}
- How can I geo-filter locations starting from HistoricalLocations?
- Is there a way to filter locations based on any of the "properties" (e.g.
receptionTime)?
Hi, we did a quick analysis, some remarks:
question 1:
- we think your current query will not work because the filter is executed on historicallocation. However, the historicallocation has only a pointer to location;
- a better solution would be filtering on location, something like:
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.
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