Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Calculate all available temporal ranges for postgres raster temporal …
…sources
  • Loading branch information
nyalldawson committed Mar 28, 2021
1 parent 9f1cc82 commit c7da1f7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/providers/postgres/raster/qgspostgresrasterprovider.cpp
Expand Up @@ -1432,6 +1432,29 @@ bool QgsPostgresRasterProvider::initFieldsAndTemporal( )
QStringLiteral( "PostGIS" ), Qgis::Warning );
}
}

// Set temporal ranges
QList< QgsDateTimeRange > allRanges;
const QString sql = QStringLiteral( "SELECT DISTINCT %1::timestamp "
"FROM %2 %3 ORDER BY %1::timestamp" ).arg( quotedIdentifier( temporalFieldName ),
mQuery,
where );

QgsPostgresResult result( connectionRO()->PQexec( sql ) );
if ( PGRES_TUPLES_OK == result.PQresultStatus() && result.PQntuples() > 0 )
{
for ( qlonglong row = 0; row < result.PQntuples(); ++row )
{
const QDateTime date = QDateTime::fromString( result.PQgetvalue( row, 0 ), Qt::DateFormat::ISODate );
allRanges.push_back( QgsDateTimeRange( date, date ) );
}
temporalCapabilities()->setAllAvailableTemporalRanges( allRanges );
}
else
{
QgsMessageLog::logMessage( tr( "No temporal ranges detected in raster temporal capabilities for field %1: %2" ).arg( temporalFieldName, mUri.param( QStringLiteral( "temporalDefaultTime" ) ) ),
QStringLiteral( "PostGIS" ), Qgis::Info );
}
}
else
{
Expand Down

0 comments on commit c7da1f7

Please sign in to comment.