Skip to content

Commit

Permalink
When parsing STAC jsons, check for stac_version first
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and wonder-sk committed Dec 3, 2024
1 parent 7528ca6 commit 9538226
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/stac/qgsstaccontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void QgsStacController::handleStacObjectReply()
break;
case QgsStacObject::Type::Unknown:
object = nullptr;
error = QStringLiteral( "Parsed STAC data is not a Catalog, Collection or Item" );
error = parser.error().isEmpty() ? QStringLiteral( "Parsed STAC data is not a Catalog, Collection or Item" ) : parser.error();
break;
}
mFetchedStacObjects.insert( requestId, object );
Expand Down
26 changes: 21 additions & 5 deletions src/core/stac/qgsstacparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,29 @@
void QgsStacParser::setData( const QByteArray &data )
{
mError = QString();
mType = QgsStacObject::Type::Unknown;
try
{
mData = nlohmann::json::parse( data.data() );
if ( mData.contains( "stac_version" ) )
{
const QString ver( QString::fromStdString( mData.at( "stac_version" ) ) );
if ( !isSupportedStacVersion( ver ) )
{
mError = QStringLiteral( "Unsupported STAC version: %1" ).arg( ver );
return;
}
}
}
catch ( nlohmann::json::exception &ex )
{
mError = QStringLiteral( "Error parsing JSON" );
QgsDebugError( QStringLiteral( "Error parsing JSON : %1" ).arg( ex.what() ) );
return;
}

try
{
if ( mData.at( "type" ) == "Catalog" )
{
mType = QgsStacObject::Type::Catalog;
Expand All @@ -41,14 +61,10 @@ void QgsStacParser::setData( const QByteArray &data )
{
mType = QgsStacObject::Type::Item;
}
else
{
mType = QgsStacObject::Type::Unknown;
}
}
catch ( nlohmann::json::exception &ex )
{
mType = QgsStacObject::Type::Unknown;
// might still be FeatureCollection or Collections Collection
}
}

Expand Down

0 comments on commit 9538226

Please sign in to comment.