Skip to content

Commit

Permalink
[sensorthings] Observation phenomenonTime can be a time instant
Browse files Browse the repository at this point in the history
According to the specifications, an Observation phenomenonTime can
either be a period OR a time instant. Correctly handle instants
instead of returning null for the phenomenonTime
  • Loading branch information
nyalldawson committed Apr 8, 2024
1 parent 02562d7 commit 2ad9065
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/providers/sensorthings/qgssensorthingsshareddata.cpp
Expand Up @@ -527,7 +527,7 @@ bool QgsSensorThingsSharedData::processFeatureRequest( QString &nextPage, QgsFee
return QVariant();
};

auto getDateTimeRange = []( const basic_json<> &json, const char *tag ) -> std::pair< QVariant, QVariant >
auto getDateTimeRange = []( const basic_json<> &json, const char *tag, bool allowInstant = false ) -> std::pair< QVariant, QVariant >
{
if ( !json.contains( tag ) )
return { QVariant(), QVariant() };
Expand All @@ -545,6 +545,11 @@ bool QgsSensorThingsSharedData::processFeatureRequest( QString &nextPage, QgsFee
QDateTime::fromString( rangeParts.at( 1 ), Qt::ISODateWithMs )
};
}
else if ( allowInstant )
{
const QDateTime instant = QDateTime::fromString( rangeString, Qt::ISODateWithMs );
return { instant, instant };
}
}

return { QVariant(), QVariant() };
Expand Down Expand Up @@ -650,7 +655,7 @@ bool QgsSensorThingsSharedData::processFeatureRequest( QString &nextPage, QgsFee

case Qgis::SensorThingsEntity::Observation:
{
std::pair< QVariant, QVariant > phenomenonTime = getDateTimeRange( featureData, "phenomenonTime" );
std::pair< QVariant, QVariant > phenomenonTime = getDateTimeRange( featureData, "phenomenonTime", true );
std::pair< QVariant, QVariant > validTime = getDateTimeRange( featureData, "validTime" );
feature.setAttributes(
QgsAttributes()
Expand Down

0 comments on commit 2ad9065

Please sign in to comment.