28#include <QRegularExpression>
38 QgsDebugMsgLevel( QStringLiteral(
"Layer count: %1" ).arg( layers.count() ), 5 );
44 if ( layer->extent().isNull() )
60 QgsDebugError( QStringLiteral(
"Could not reproject layer extent" ) );
64 if ( fullExtent.
width() == 0.0 || fullExtent.
height() == 0.0 )
73 fullExtent.
set( -1.0, -1.0, 1.0, 1.0 );
77 const double padFactor = 1e-8;
78 const double widthPad = fullExtent.
xMinimum() * padFactor;
79 const double heightPad = fullExtent.
yMinimum() * padFactor;
80 const double xmin = fullExtent.
xMinimum() - widthPad;
81 const double xmax = fullExtent.
xMaximum() + widthPad;
82 const double ymin = fullExtent.
yMinimum() - heightPad;
83 const double ymax = fullExtent.
yMaximum() + heightPad;
84 fullExtent.
set( xmin, ymin, xmax, ymax );
102 if ( ! providerMetadata )
108 return conn.release();
112 if ( !ex.
what().contains( QLatin1String(
"createConnection" ) ) )
114 QgsDebugError( QStringLiteral(
"Error retrieving database connection for layer %1: %2" ).arg( layer->
name(), ex.
what() ) );
122 if ( !layer || path.isEmpty() )
126 return parts.value( QStringLiteral(
"path" ) ).toString() == path;
131 if ( !layer || newPath.isEmpty() )
135 if ( !parts.contains( QStringLiteral(
"path" ) ) )
138 parts.insert( QStringLiteral(
"path" ), newPath );
146 QList< QgsMapLayer * > res = layers;
149 for ( Qgis::LayerType type : order )
151 if ( a->type() == type && b->type() != type )
153 else if ( b->type() == type )
163 QString laundered = name.toLower();
164 const thread_local QRegularExpression sRxSwapChars( QStringLiteral(
"\\s" ) );
165 laundered.replace( sRxSwapChars, QStringLiteral(
"_" ) );
167 const thread_local QRegularExpression sRxRemoveChars( QStringLiteral(
"[^a-zA-Z0-9_]" ) );
168 laundered.replace( sRxRemoveChars, QString() );
179 QVariantMap details = metadata->decodeUri( layer->
source() );
180 QUrl url( details.value( QStringLiteral(
"url" ) ).toString() );
181 if ( url.host().endsWith( QLatin1String(
".openstreetmap.org" ) ) || url.host().endsWith( QLatin1String(
".osm.org" ) ) )
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
virtual QString name() const =0
Returns a provider name.
static bool updateLayerSourcePath(QgsMapLayer *layer, const QString &newPath)
Updates a layer's data source, replacing its data source with a path referring to newPath.
static QgsRectangle combinedExtent(const QList< QgsMapLayer * > &layers, const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext)
Returns the combined extent of a list of layers.
static QgsAbstractDatabaseProviderConnection * databaseConnection(const QgsMapLayer *layer)
Creates and returns the (possibly nullptr) database connection for a layer.
static QList< QgsMapLayer * > sortLayersByType(const QList< QgsMapLayer * > &layers, const QList< Qgis::LayerType > &order)
Sorts a list of map layers by their layer type, respecting the order of types specified.
static QString launderLayerName(const QString &name)
Launders a layer's name, converting it into a format which is general suitable for file names or data...
static bool isOpenStreetMapLayer(QgsMapLayer *layer)
Returns true if the layer is served by OpenStreetMap server.
static bool layerSourceMatchesPath(const QgsMapLayer *layer, const QString &path)
Returns true if the source of the specified layer matches the given path.
Base class for all map layer types.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QgsProviderMetadata * providerMetadata() const
Returns the layer data provider's metadata, it may be nullptr.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Custom exception class for provider connection related exceptions.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
const QgsCoordinateReferenceSystem & crs