mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-29 00:06:58 -05:00
Allow adding a single asset as a layer
This commit is contained in:
parent
8abedd0c5f
commit
a9e23faa3e
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include "qgsstacasset.h"
|
#include "qgsstacasset.h"
|
||||||
|
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
QgsStacAsset::QgsStacAsset( const QString &href,
|
QgsStacAsset::QgsStacAsset( const QString &href,
|
||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &description,
|
const QString &description,
|
||||||
@ -72,3 +74,46 @@ QString QgsStacAsset::formatName() const
|
|||||||
return QStringLiteral( "EPT" );
|
return QStringLiteral( "EPT" );
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsMimeDataUtils::Uri QgsStacAsset::uri() const
|
||||||
|
{
|
||||||
|
QgsMimeDataUtils::Uri uri;
|
||||||
|
QUrl url( href() );
|
||||||
|
if ( url.isLocalFile() )
|
||||||
|
{
|
||||||
|
uri.uri = href();
|
||||||
|
}
|
||||||
|
else if ( formatName() == QLatin1String( "COG" ) )
|
||||||
|
{
|
||||||
|
uri.layerType = QStringLiteral( "raster" );
|
||||||
|
uri.providerKey = QStringLiteral( "gdal" );
|
||||||
|
if ( href().startsWith( QLatin1String( "http" ), Qt::CaseInsensitive ) ||
|
||||||
|
href().startsWith( QLatin1String( "ftp" ), Qt::CaseInsensitive ) )
|
||||||
|
{
|
||||||
|
uri.uri = QStringLiteral( "/vsicurl/%1" ).arg( href() );
|
||||||
|
}
|
||||||
|
else if ( href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) )
|
||||||
|
{
|
||||||
|
uri.uri = QStringLiteral( "/vsis3/%1" ).arg( href().mid( 5 ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uri.uri = href();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( formatName() == QLatin1String( "COPC" ) )
|
||||||
|
{
|
||||||
|
uri.layerType = QStringLiteral( "pointcloud" );
|
||||||
|
uri.providerKey = QStringLiteral( "copc" );
|
||||||
|
uri.uri = href();
|
||||||
|
}
|
||||||
|
else if ( formatName() == QLatin1String( "EPT" ) )
|
||||||
|
{
|
||||||
|
uri.layerType = QStringLiteral( "pointcloud" );
|
||||||
|
uri.providerKey = QStringLiteral( "ept" );
|
||||||
|
uri.uri = href();
|
||||||
|
}
|
||||||
|
uri.name = title().isEmpty() ? url.fileName() : title();
|
||||||
|
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#define SIP_NO_FILE
|
#define SIP_NO_FILE
|
||||||
|
|
||||||
#include "qgis_core.h"
|
#include "qgis_core.h"
|
||||||
|
#include "qgsmimedatautils.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@ -73,6 +74,12 @@ class CORE_EXPORT QgsStacAsset
|
|||||||
*/
|
*/
|
||||||
QString formatName() const;
|
QString formatName() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a uri for the asset if it is a local or cloud optimized file like COG or COPC
|
||||||
|
* \since QGIS 3.42
|
||||||
|
*/
|
||||||
|
QgsMimeDataUtils::Uri uri() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mHref;
|
QString mHref;
|
||||||
QString mTitle;
|
QString mTitle;
|
||||||
|
|||||||
@ -191,50 +191,14 @@ QString QgsStacItem::description() const
|
|||||||
QgsMimeDataUtils::UriList QgsStacItem::uris() const
|
QgsMimeDataUtils::UriList QgsStacItem::uris() const
|
||||||
{
|
{
|
||||||
QgsMimeDataUtils::UriList uris;
|
QgsMimeDataUtils::UriList uris;
|
||||||
for ( auto it = mAssets.constBegin(); it != mAssets.constEnd(); ++it )
|
for ( const QgsStacAsset &asset : std::as_const( mAssets ) )
|
||||||
{
|
{
|
||||||
QgsMimeDataUtils::Uri uri;
|
QgsMimeDataUtils::Uri uri = asset.uri();
|
||||||
QUrl url( it->href() );
|
|
||||||
if ( url.isLocalFile() )
|
|
||||||
{
|
|
||||||
uri.uri = it->href();
|
|
||||||
}
|
|
||||||
else if ( it->formatName() == QLatin1String( "COG" ) )
|
|
||||||
{
|
|
||||||
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() );
|
|
||||||
}
|
|
||||||
else if ( it->href().startsWith( QLatin1String( "s3://" ), Qt::CaseInsensitive ) )
|
|
||||||
{
|
|
||||||
uri.uri = QStringLiteral( "/vsis3/%1" ).arg( it->href().mid( 5 ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uri.uri = it->href();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( it->formatName() == QLatin1String( "COPC" ) )
|
|
||||||
{
|
|
||||||
uri.layerType = QStringLiteral( "pointcloud" );
|
|
||||||
uri.providerKey = QStringLiteral( "copc" );
|
|
||||||
uri.uri = it->href();
|
|
||||||
}
|
|
||||||
else if ( it->formatName() == QLatin1String( "EPT" ) )
|
|
||||||
{
|
|
||||||
uri.layerType = QStringLiteral( "pointcloud" );
|
|
||||||
uri.providerKey = QStringLiteral( "ept" );
|
|
||||||
uri.uri = it->href();
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip assets with incompatible formats
|
// skip assets with incompatible formats
|
||||||
if ( uri.uri.isEmpty() )
|
if ( uri.uri.isEmpty() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uri.name = it->title().isEmpty() ? url.fileName() : it->title();
|
|
||||||
uris.append( uri );
|
uris.append( uri );
|
||||||
}
|
}
|
||||||
return uris;
|
return uris;
|
||||||
|
|||||||
@ -128,7 +128,7 @@ class CORE_EXPORT QgsStacItem : public QgsStacObject
|
|||||||
QString description() const;
|
QString description() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of uris of all assets that have a cloud optimized format like COG or COPC
|
* Returns a list of uris of all assets that are local or have a cloud optimized format like COG or COPC
|
||||||
* \since QGIS 3.42
|
* \since QGIS 3.42
|
||||||
*/
|
*/
|
||||||
QgsMimeDataUtils::UriList uris() const;
|
QgsMimeDataUtils::UriList uris() const;
|
||||||
|
|||||||
@ -123,20 +123,7 @@ void QgsStacSourceSelect::addButtonClicked()
|
|||||||
|
|
||||||
for ( auto &uri : std::as_const( allUris ) )
|
for ( auto &uri : std::as_const( allUris ) )
|
||||||
{
|
{
|
||||||
if ( uri.layerType == QLatin1String( "raster" ) )
|
loadUri( uri );
|
||||||
{
|
|
||||||
Q_NOWARN_DEPRECATED_PUSH
|
|
||||||
emit addRasterLayer( uri.uri, uri.name, uri.providerKey );
|
|
||||||
Q_NOWARN_DEPRECATED_POP
|
|
||||||
emit addLayer( Qgis::LayerType::Raster, uri.uri, uri.name, uri.providerKey );
|
|
||||||
}
|
|
||||||
else if ( uri.layerType == QLatin1String( "pointcloud" ) )
|
|
||||||
{
|
|
||||||
Q_NOWARN_DEPRECATED_PUSH
|
|
||||||
emit addPointCloudLayer( uri.uri, uri.name, uri.providerKey );
|
|
||||||
Q_NOWARN_DEPRECATED_POP
|
|
||||||
emit addLayer( Qgis::LayerType::PointCloud, uri.uri, uri.name, uri.providerKey );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,6 +499,23 @@ void QgsStacSourceSelect::showItemsContextMenu( QPoint point )
|
|||||||
if ( dsm )
|
if ( dsm )
|
||||||
bar = dsm->messageBar();
|
bar = dsm->messageBar();
|
||||||
|
|
||||||
|
const QgsStacItem *item = dynamic_cast<QgsStacItem *>( index.data( QgsStacItemListModel::Role::StacObject ).value<QgsStacObject *>() );
|
||||||
|
QMenu *assetsMenu = menu->addMenu( tr( "Add Layer" ) );
|
||||||
|
const QMap<QString, QgsStacAsset> assets = item->assets();
|
||||||
|
for ( const QgsStacAsset &asset : assets )
|
||||||
|
{
|
||||||
|
if ( asset.isCloudOptimized() )
|
||||||
|
{
|
||||||
|
QAction *loadAssetAction = new QAction( asset.title(), assetsMenu );
|
||||||
|
connect( loadAssetAction, &QAction::triggered, this, [this, &asset]
|
||||||
|
{
|
||||||
|
QgsTemporaryCursorOverride cursorOverride( Qt::WaitCursor );
|
||||||
|
loadUri( asset.uri() );
|
||||||
|
} );
|
||||||
|
assetsMenu->addAction( loadAssetAction );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QAction *zoomToAction = new QAction( tr( "Zoom to Item" ) );
|
QAction *zoomToAction = new QAction( tr( "Zoom to Item" ) );
|
||||||
connect( zoomToAction, &QAction::triggered, this, [index, this]
|
connect( zoomToAction, &QAction::triggered, this, [index, this]
|
||||||
{
|
{
|
||||||
@ -561,8 +565,11 @@ void QgsStacSourceSelect::showItemsContextMenu( QPoint point )
|
|||||||
details.exec();
|
details.exec();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
menu->addAction( zoomToAction );
|
menu->addAction( zoomToAction );
|
||||||
menu->addAction( panToAction );
|
menu->addAction( panToAction );
|
||||||
|
if ( !assetsMenu->isEmpty() )
|
||||||
|
menu->addMenu( assetsMenu );
|
||||||
menu->addAction( downloadAction );
|
menu->addAction( downloadAction );
|
||||||
menu->addAction( detailsAction );
|
menu->addAction( detailsAction );
|
||||||
|
|
||||||
@ -606,4 +613,21 @@ void QgsStacSourceSelect::showFootprints( bool enable )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsStacSourceSelect::loadUri( const QgsMimeDataUtils::Uri &uri )
|
||||||
|
{
|
||||||
|
if ( uri.layerType == QLatin1String( "raster" ) )
|
||||||
|
{
|
||||||
|
Q_NOWARN_DEPRECATED_PUSH
|
||||||
|
emit addRasterLayer( uri.uri, uri.name, uri.providerKey );
|
||||||
|
Q_NOWARN_DEPRECATED_POP
|
||||||
|
emit addLayer( Qgis::LayerType::Raster, uri.uri, uri.name, uri.providerKey );
|
||||||
|
}
|
||||||
|
else if ( uri.layerType == QLatin1String( "pointcloud" ) )
|
||||||
|
{
|
||||||
|
Q_NOWARN_DEPRECATED_PUSH
|
||||||
|
emit addPointCloudLayer( uri.uri, uri.name, uri.providerKey );
|
||||||
|
Q_NOWARN_DEPRECATED_POP
|
||||||
|
emit addLayer( Qgis::LayerType::PointCloud, uri.uri, uri.name, uri.providerKey );
|
||||||
|
}
|
||||||
|
}
|
||||||
///@endcond
|
///@endcond
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include "ui_qgsstacsourceselectbase.h"
|
#include "ui_qgsstacsourceselectbase.h"
|
||||||
#include "qgsabstractdatasourcewidget.h"
|
#include "qgsabstractdatasourcewidget.h"
|
||||||
#include "qgis_gui.h"
|
#include "qgis_gui.h"
|
||||||
|
#include "qgsmimedatautils.h"
|
||||||
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
@ -32,7 +33,6 @@ class QgsStacItemListModel;
|
|||||||
class QgsStacController;
|
class QgsStacController;
|
||||||
class QgsRubberBand;
|
class QgsRubberBand;
|
||||||
|
|
||||||
|
|
||||||
class GUI_EXPORT QgsStacSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsStacSourceSelectBase
|
class GUI_EXPORT QgsStacSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsStacSourceSelectBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -99,6 +99,7 @@ class GUI_EXPORT QgsStacSourceSelect : public QgsAbstractDataSourceWidget, priva
|
|||||||
|
|
||||||
void highlightFootprint( const QModelIndex &index );
|
void highlightFootprint( const QModelIndex &index );
|
||||||
void showFootprints( bool enable );
|
void showFootprints( bool enable );
|
||||||
|
void loadUri( const QgsMimeDataUtils::Uri &uri );
|
||||||
|
|
||||||
QString mCollectionsUrl;
|
QString mCollectionsUrl;
|
||||||
QString mSearchUrl;
|
QString mSearchUrl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user