Skip to content

Commit a1c94fa

Browse files
authored
Allow configurable expand to SensorThings provider (geopython#1879)
* Allow configurable expand to SensorThings provider * Update license year
1 parent f032628 commit a1c94fa

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

docs/source/data-publishing/ogcapi-features.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ If ``intralink`` is true for an adjacent STA provider collection within a
667667
pygeoapi instance, the expanded entity is instead represented by an intra-pygeoapi
668668
link to the other entity or it's ``uri_field`` if declared.
669669

670+
Additionally there is the optional field ``expand``. This field will overwrite the default
671+
pygeoapi expand behavior and instead implement the configured expand strategy. This is
672+
particularly useful if you have Datastreams with many observations.
673+
670674
.. code-block:: yaml
671675
672676
providers:
@@ -677,6 +681,7 @@ link to the other entity or it's ``uri_field`` if declared.
677681
entity: Datastreams
678682
time_field: phenomenonTime
679683
intralink: true
684+
expand: Thing/Locations,Observations($select=result,phenomenonTime;$orderby=phenomenonTime desc;$top=1)
680685
681686
If all three entities are configured, the STA provider will represent a complete STA
682687
endpoint as OGC-API feature collections. The ``Things`` features will include links

pygeoapi/provider/sensorthings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Authors: Benjamin Webb <benjamin.miller.webb@gmail.com>
44
# Authors: Tom Kralidis <tomkralidis@gmail.com>
55
#
6-
# Copyright (c) 2023 Benjamin Webb
6+
# Copyright (c) 2024 Benjamin Webb
77
# Copyright (c) 2022 Tom Kralidis
88
#
99
# Permission is hereby granted, free of charge, to any person
@@ -518,6 +518,10 @@ def _generate_mappings(self, provider_def: dict):
518518
LOGGER.debug('Using default @iot.id for id field')
519519
self.id_field = '@iot.id'
520520

521+
# Custom expand
522+
if provider_def.get('expand'):
523+
EXPAND[self.entity] = provider_def['expand']
524+
521525
# Create intra-links
522526
self.intralink = provider_def.get('intralink', False)
523527
if self.intralink and provider_def.get('rel_link'):

tests/test_sensorthings_provider.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Authors: Benjamin Webb <bwebb@lincolninst.edu>
44
#
5-
# Copyright (c) 2022 Benjamin Webb
5+
# Copyright (c) 2024 Benjamin Webb
66
#
77
# Permission is hereby granted, free of charge, to any person
88
# obtaining a copy of this software and associated documentation
@@ -138,3 +138,27 @@ def test_get(config):
138138
assert result['id'] == '9'
139139
assert result['properties']['name'] == 'Depth Below Surface'
140140
assert isinstance(result['properties']['Thing'], dict)
141+
142+
143+
def test_custom_expand(config):
144+
p = SensorThingsProvider(config)
145+
fields = p.get_fields()
146+
assert 'Observations' in fields
147+
assert 'ObservedProperty' in fields
148+
assert 'Sensor' in fields
149+
150+
config['expand'] = 'Thing/Locations'
151+
p = SensorThingsProvider(config)
152+
fields = p.get_fields()
153+
assert len(fields) == 12
154+
assert 'Observations' not in fields
155+
assert 'ObservedProperty' not in fields
156+
assert 'Sensor' not in fields
157+
158+
config['expand'] = 'Thing/Locations,Observations'
159+
p = SensorThingsProvider(config)
160+
fields = p.get_fields()
161+
assert len(fields) == 14
162+
assert 'Observations' in fields
163+
assert 'ObservedProperty' not in fields
164+
assert 'Sensor' not in fields

0 commit comments

Comments
 (0)