Skip to content

Commit c7da1f7

Browse files
committedMar 28, 2021
Calculate all available temporal ranges for postgres raster temporal sources
1 parent 9f1cc82 commit c7da1f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎src/providers/postgres/raster/qgspostgresrasterprovider.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,29 @@ bool QgsPostgresRasterProvider::initFieldsAndTemporal( )
14321432
QStringLiteral( "PostGIS" ), Qgis::Warning );
14331433
}
14341434
}
1435+
1436+
// Set temporal ranges
1437+
QList< QgsDateTimeRange > allRanges;
1438+
const QString sql = QStringLiteral( "SELECT DISTINCT %1::timestamp "
1439+
"FROM %2 %3 ORDER BY %1::timestamp" ).arg( quotedIdentifier( temporalFieldName ),
1440+
mQuery,
1441+
where );
1442+
1443+
QgsPostgresResult result( connectionRO()->PQexec( sql ) );
1444+
if ( PGRES_TUPLES_OK == result.PQresultStatus() && result.PQntuples() > 0 )
1445+
{
1446+
for ( qlonglong row = 0; row < result.PQntuples(); ++row )
1447+
{
1448+
const QDateTime date = QDateTime::fromString( result.PQgetvalue( row, 0 ), Qt::DateFormat::ISODate );
1449+
allRanges.push_back( QgsDateTimeRange( date, date ) );
1450+
}
1451+
temporalCapabilities()->setAllAvailableTemporalRanges( allRanges );
1452+
}
1453+
else
1454+
{
1455+
QgsMessageLog::logMessage( tr( "No temporal ranges detected in raster temporal capabilities for field %1: %2" ).arg( temporalFieldName, mUri.param( QStringLiteral( "temporalDefaultTime" ) ) ),
1456+
QStringLiteral( "PostGIS" ), Qgis::Info );
1457+
}
14351458
}
14361459
else
14371460
{

0 commit comments

Comments
 (0)
Please sign in to comment.