feat(#62838): refactor duplicated logic

This commit is contained in:
Tom Christian 2025-09-26 14:39:07 -07:00
parent 90da1671e9
commit 320b3afd1c
No known key found for this signature in database
GPG Key ID: 0CC611E0CD80A370
5 changed files with 39 additions and 37 deletions

View File

@ -76,6 +76,14 @@ Returns the format name for cloud optimized formats
QgsMimeDataUtils::Uri uri() const;
%Docstring
Returns a uri for the asset if it is a cloud optimized file like COG or
COPC, empty auth configuration
.. versionadded:: 3.42
%End
QgsMimeDataUtils::Uri uri( QString authcfg ) const;
%Docstring
Returns a uri for the asset if it is a cloud optimized file like COG or
COPC
.. versionadded:: 3.42

View File

@ -76,6 +76,14 @@ Returns the format name for cloud optimized formats
QgsMimeDataUtils::Uri uri() const;
%Docstring
Returns a uri for the asset if it is a cloud optimized file like COG or
COPC, empty auth configuration
.. versionadded:: 3.42
%End
QgsMimeDataUtils::Uri uri( QString authcfg ) const;
%Docstring
Returns a uri for the asset if it is a cloud optimized file like COG or
COPC
.. versionadded:: 3.42

View File

@ -79,6 +79,12 @@ QString QgsStacAsset::formatName() const
}
QgsMimeDataUtils::Uri QgsStacAsset::uri() const
{
return uri( QString() );
}
QgsMimeDataUtils::Uri QgsStacAsset::uri( QString authcfg ) const
{
QgsMimeDataUtils::Uri uri;
QUrl url( href() );
@ -90,6 +96,8 @@ QgsMimeDataUtils::Uri QgsStacAsset::uri() const
href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) )
{
uri.uri = QStringLiteral( "/vsicurl/%1" ).arg( href() );
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
else if ( href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) )
{
@ -105,12 +113,16 @@ QgsMimeDataUtils::Uri QgsStacAsset::uri() const
uri.layerType = QStringLiteral( "pointcloud" );
uri.providerKey = QStringLiteral( "copc" );
uri.uri = href();
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
else if ( formatName() == QLatin1String( "EPT" ) )
{
uri.layerType = QStringLiteral( "pointcloud" );
uri.providerKey = QStringLiteral( "ept" );
uri.uri = href();
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
else if ( formatName() == QLatin1String( "Zarr" ) )
{
@ -120,6 +132,8 @@ QgsMimeDataUtils::Uri QgsStacAsset::uri() const
href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) )
{
uri.uri = QStringLiteral( "ZARR:\"/vsicurl/%1\"" ).arg( href() );
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
else if ( href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) )
{

View File

@ -73,11 +73,17 @@ class CORE_EXPORT QgsStacAsset
QString formatName() const;
/**
* Returns a uri for the asset if it is a cloud optimized file like COG or COPC
* Returns a uri for the asset if it is a cloud optimized file like COG or COPC, empty auth configuration
* \since QGIS 3.42
*/
QgsMimeDataUtils::Uri uri() const;
/**
* Returns a uri for the asset if it is a cloud optimized file like COG or COPC
* \since QGIS 3.42
*/
QgsMimeDataUtils::Uri uri( QString authcfg ) const;
private:
QString mHref;
QString mTitle;

View File

@ -109,44 +109,10 @@ QgsMimeDataUtils::UriList QgsStacItemItem::mimeUris() const
{
uri.uri = it->href();
}
else if ( it->mediaType() == QLatin1String( "image/tiff; application=geotiff; profile=cloud-optimized" ) ||
it->mediaType() == QLatin1String( "image/vnd.stac.geotiff; cloud-optimized=true" ) )
else
{
uri.layerType = QStringLiteral( "raster" );
uri.providerKey = QStringLiteral( "gdal" );
if ( it->href().startsWith( QLatin1String( "http" ), Qt::CaseInsensitive ) ||
it->href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) )
{
uri.uri = QStringLiteral( "/vsicurl/%1" ).arg( it->href() );
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
else if ( it->href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) )
{
uri.uri = QStringLiteral( "/vsis3/%1" ).arg( it->href().mid( 5 ) );
}
else
{
uri.uri = it->href();
}
uri = it->uri( authcfg );
}
else if ( it->mediaType() == QLatin1String( "application/vnd.laszip+copc" ) )
{
uri.layerType = QStringLiteral( "pointcloud" );
uri.providerKey = QStringLiteral( "copc" );
uri.uri = it->href();
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
else if ( it->href().endsWith( QLatin1String( "/ept.json" ) ) )
{
uri.layerType = QStringLiteral( "pointcloud" );
uri.providerKey = QStringLiteral( "ept" );
uri.uri = it->href();
if ( !authcfg.isEmpty() )
uri.uri.append( QStringLiteral( " authcfg='%1'" ).arg( authcfg ) );
}
uri.name = it->title().isEmpty() ? url.fileName() : it->title();
uris.append( uri );
}