47 , mTransformContext( options.transformContext )
63void QgsVectorTileLayer::setDataSourcePrivate(
const QString &dataSource,
const QString &baseName,
const QString &,
const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags )
67 mDataProvider.reset();
72bool QgsVectorTileLayer::loadDataSource()
79 mSourceType = dsUri.
param( QStringLiteral(
"type" ) );
80 mSourcePath = dsUri.
param( QStringLiteral(
"url" ) );
81 if ( mSourceType == QLatin1String(
"xyz" ) && dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
83 if ( !setupArcgisVectorTileServiceConnection( mSourcePath, dsUri ) )
86 else if ( mSourceType == QLatin1String(
"xyz" ) )
90 QgsDebugMsg( QStringLiteral(
"Invalid format of URL for XYZ source: " ) + mSourcePath );
96 if ( dsUri.
hasParam( QStringLiteral(
"zmin" ) ) )
97 zMin = dsUri.
param( QStringLiteral(
"zmin" ) ).toInt();
100 if ( dsUri.
hasParam( QStringLiteral(
"zmax" ) ) )
101 zMax = dsUri.
param( QStringLiteral(
"zmax" ) ).toInt();
104 setExtent(
QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
106 else if ( mSourceType == QLatin1String(
"mbtiles" ) )
109 if ( !reader.open() )
111 QgsDebugMsg( QStringLiteral(
"failed to open MBTiles file: " ) + mSourcePath );
115 const QString format = reader.metadataValue( QStringLiteral(
"format" ) );
116 if ( format != QLatin1String(
"pbf" ) )
118 QgsDebugMsg( QStringLiteral(
"Cannot open MBTiles for vector tiles. Format = " ) + format );
122 QgsDebugMsgLevel( QStringLiteral(
"name: " ) + reader.metadataValue( QStringLiteral(
"name" ) ), 2 );
123 bool minZoomOk, maxZoomOk;
124 const int minZoom = reader.metadataValue( QStringLiteral(
"minzoom" ) ).toInt( &minZoomOk );
125 const int maxZoom = reader.metadataValue( QStringLiteral(
"maxzoom" ) ).toInt( &maxZoomOk );
135 ct.setBallparkTransformsAreAppropriate(
true );
136 r = ct.transformBoundingBox( r );
139 else if ( mSourceType == QLatin1String(
"vtpk" ) )
142 if ( !reader.open() )
144 QgsDebugMsg( QStringLiteral(
"failed to open VTPK file: " ) + mSourcePath );
148 const QVariantMap
metadata = reader.metadata();
149 const QString format =
metadata.value( QStringLiteral(
"tileInfo" ) ).toMap().value( QStringLiteral(
"format" ) ).toString();
150 if ( format != QLatin1String(
"pbf" ) )
152 QgsDebugMsg( QStringLiteral(
"Cannot open VTPK for vector tiles. Format = " ) + format );
156 mMatrixSet = reader.matrixSet();
162 QgsDebugMsg( QStringLiteral(
"Unknown source type: " ) + mSourceType );
167 const QgsDataProvider::ReadFlags
flags;
168 mDataProvider.reset(
new QgsVectorTileDataProvider( providerOptions,
flags ) );
174bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection(
const QString &uri,
const QgsDataSourceUri &dataSourceUri )
176 QString tileServiceUri = uri;
177 QUrl url( tileServiceUri );
181 query.addQueryItem( QStringLiteral(
"f" ), QStringLiteral(
"pjson" ) );
182 url.setQuery( query );
184 QNetworkRequest request = QNetworkRequest( url );
189 switch ( networkRequest.get( request ) )
201 const QByteArray raw = content.
content();
205 const QJsonDocument doc = QJsonDocument::fromJson( raw, &err );
211 mArcgisLayerConfiguration = doc.object().toVariantMap();
212 if ( mArcgisLayerConfiguration.contains( QStringLiteral(
"error" ) ) )
217 if ( !mArcgisLayerConfiguration.value( QStringLiteral(
"tiles" ) ).
isValid() )
220 const QString sourceUri = mArcgisLayerConfiguration.value( QStringLiteral(
"sources" ) ).toMap().value( QStringLiteral(
"esri" ) ).toMap().value( QStringLiteral(
"url" ) ).toString();
221 if ( !sourceUri.isEmpty() )
223 QUrl url( sourceUri );
227 query.addQueryItem( QStringLiteral(
"f" ), QStringLiteral(
"pjson" ) );
228 url.setQuery( query );
230 QNetworkRequest request = QNetworkRequest( url );
235 switch ( networkRequest.get( request ) )
247 const QByteArray raw = content.
content();
251 const QJsonDocument doc = QJsonDocument::fromJson( raw, &err );
257 tileServiceUri = sourceUri;
260 mArcgisStyleConfiguration = mArcgisLayerConfiguration;
261 mArcgisLayerConfiguration = doc.object().toVariantMap();
262 if ( mArcgisLayerConfiguration.contains( QStringLiteral(
"error" ) ) )
269 mSourcePath = tileServiceUri +
'/' + mArcgisLayerConfiguration.value( QStringLiteral(
"tiles" ) ).toList().value( 0 ).toString();
272 QgsDebugMsg( QStringLiteral(
"Invalid format of URL for XYZ source: " ) + mSourcePath );
276 mArcgisLayerConfiguration.insert( QStringLiteral(
"serviceUri" ), tileServiceUri );
283 if ( dataSourceUri.
hasParam( QStringLiteral(
"zmin" ) ) )
286 if ( dataSourceUri.
hasParam( QStringLiteral(
"zmax" ) ) )
289 const QVariantMap fullExtent = mArcgisLayerConfiguration.value( QStringLiteral(
"fullExtent" ) ).toMap();
290 if ( !fullExtent.isEmpty() )
293 fullExtent.value( QStringLiteral(
"xmin" ) ).toDouble(),
294 fullExtent.value( QStringLiteral(
"ymin" ) ).toDouble(),
295 fullExtent.value( QStringLiteral(
"xmax" ) ).toDouble(),
296 fullExtent.value( QStringLiteral(
"ymax" ) ).toDouble()
303 setExtent( extentTransform.transformBoundingBox( fullExtentRect ) );
307 QgsDebugMsg( QStringLiteral(
"Could not transform layer fullExtent to layer CRS" ) );
316 setExtent( extentTransform.transformBoundingBox(
QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) ) );
320 QgsDebugMsg( QStringLiteral(
"Could not transform layer extent to layer CRS" ) );
340 return mDataProvider.get();
345 return mDataProvider.get();
357 const QDomElement matrixSetElement = layerNode.firstChildElement( QStringLiteral(
"matrixSet" ) );
358 if ( !matrixSetElement.isNull() )
360 mMatrixSet.
readXml( matrixSetElement, context );
374 QDomElement mapLayerNode = layerNode.toElement();
377 mapLayerNode.appendChild( mMatrixSet.
writeXml( doc, context ) );
382 QDomElement provider = doc.createElement( QStringLiteral(
"provider" ) );
383 const QDomText providerText = doc.createTextNode(
providerType() );
384 provider.appendChild( providerText );
385 mapLayerNode.appendChild( provider );
396 const QDomElement elem = node.toElement();
400 const QDomElement elemRenderer = elem.firstChildElement( QStringLiteral(
"renderer" ) );
401 if ( elemRenderer.isNull() )
403 errorMessage = tr(
"Missing <renderer> tag" );
406 const QString rendererType = elemRenderer.attribute( QStringLiteral(
"type" ) );
411 if ( rendererType == QLatin1String(
"basic" ) )
415 errorMessage = tr(
"Unknown renderer type: " ) + rendererType;
419 r->
readXml( elemRenderer, context );
423 if ( categories.testFlag(
Labeling ) )
426 const QDomElement elemLabeling = elem.firstChildElement( QStringLiteral(
"labeling" ) );
427 if ( !elemLabeling.isNull() )
429 const QString labelingType = elemLabeling.attribute( QStringLiteral(
"type" ) );
431 if ( labelingType == QLatin1String(
"basic" ) )
435 errorMessage = tr(
"Unknown labeling type: " ) + rendererType;
449 const QDomNode blendModeNode = node.namedItem( QStringLiteral(
"blendMode" ) );
450 if ( !blendModeNode.isNull() )
452 const QDomElement e = blendModeNode.toElement();
460 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral(
"layerOpacity" ) );
461 if ( !layerOpacityNode.isNull() )
463 const QDomElement e = layerOpacityNode.toElement();
473 Q_UNUSED( errorMessage )
474 QDomElement elem = node.toElement();
480 QDomElement elemRenderer = doc.createElement( QStringLiteral(
"renderer" ) );
481 elemRenderer.setAttribute( QStringLiteral(
"type" ), mRenderer->type() );
484 mRenderer->writeXml( elemRenderer, context );
486 elem.appendChild( elemRenderer );
489 if ( mLabeling && categories.testFlag(
Labeling ) )
491 QDomElement elemLabeling = doc.createElement( QStringLiteral(
"labeling" ) );
492 elemLabeling.setAttribute( QStringLiteral(
"type" ), mLabeling->type() );
493 mLabeling->writeXml( elemLabeling, context );
494 elem.appendChild( elemLabeling );
500 QDomElement blendModeElem = doc.createElement( QStringLiteral(
"blendMode" ) );
502 blendModeElem.appendChild( blendModeText );
503 node.appendChild( blendModeElem );
509 QDomElement layerOpacityElem = doc.createElement( QStringLiteral(
"layerOpacity" ) );
510 const QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
511 layerOpacityElem.appendChild( layerOpacityText );
512 node.appendChild( layerOpacityElem );
530 QStringList warnings;
537 Qgis::MapLayerProperties res;
538 if ( mSourceType == QLatin1String(
"xyz" ) )
553 return loadDefaultStyleAndSubLayersPrivate(
error, warnings,
nullptr );
558 return loadDefaultStyleAndSubLayersPrivate(
error, warnings, &
subLayers );
561bool QgsVectorTileLayer::loadDefaultStyleAndSubLayersPrivate( QString &error, QStringList &warnings, QList<QgsMapLayer *> *subLayers )
566 QVariantMap styleDefinition;
569 if ( !dsUri.
param( QStringLiteral(
"styleUrl" ) ).isEmpty() )
571 styleUrl = dsUri.
param( QStringLiteral(
"styleUrl" ) );
573 else if ( mSourceType == QLatin1String(
"xyz" ) && dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
576 styleUrl = mArcgisLayerConfiguration.value( QStringLiteral(
"serviceUri" ) ).toString()
577 +
'/' + mArcgisLayerConfiguration.value( QStringLiteral(
"defaultStyles" ) ).toString();
580 if ( mSourceType == QLatin1String(
"vtpk" ) )
583 if ( !reader.open() )
585 QgsDebugMsg( QStringLiteral(
"failed to open VTPK file: " ) + mSourcePath );
589 styleDefinition = reader.styleDefinition();
591 const QVariantMap spriteDefinition = reader.spriteDefinition();
592 if ( !spriteDefinition.isEmpty() )
594 const QImage spriteImage = reader.spriteImage();
595 context.
setSprites( spriteImage, spriteDefinition );
598 else if ( !mArcgisStyleConfiguration.isEmpty() || !styleUrl.isEmpty() )
600 if ( !mArcgisStyleConfiguration.isEmpty() )
602 styleDefinition = mArcgisStyleConfiguration;
606 QNetworkRequest request = QNetworkRequest( QUrl( styleUrl ) );
611 switch ( networkRequest.
get( request ) )
619 error = QObject::tr(
"Error retrieving default style" );
627 if ( styleDefinition.contains( QStringLiteral(
"sprite" ) ) )
630 QString spriteUriBase;
631 if ( styleDefinition.value( QStringLiteral(
"sprite" ) ).toString().startsWith( QLatin1String(
"http" ) ) )
633 spriteUriBase = styleDefinition.value( QStringLiteral(
"sprite" ) ).toString();
637 spriteUriBase = styleUrl +
'/' + styleDefinition.value( QStringLiteral(
"sprite" ) ).toString();
640 for (
int resolution = 2; resolution > 0; resolution-- )
642 QUrl spriteUrl = QUrl( spriteUriBase );
643 spriteUrl.setPath( spriteUrl.path() + QStringLiteral(
"%1.json" ).arg( resolution > 1 ? QStringLiteral(
"@%1x" ).arg( resolution ) : QString() ) );
644 QNetworkRequest request = QNetworkRequest( spriteUrl );
647 switch ( networkRequest.get( request ) )
655 QUrl spriteUrl = QUrl( spriteUriBase );
656 spriteUrl.setPath( spriteUrl.path() + QStringLiteral(
"%1.png" ).arg( resolution > 1 ? QStringLiteral(
"@%1x" ).arg( resolution ) : QString() ) );
657 QNetworkRequest request = QNetworkRequest( spriteUrl );
660 switch ( networkRequest.get( request ) )
665 const QImage spriteImage( QImage::fromData( imageContent.
content() ) );
666 context.
setSprites( spriteImage, spriteDefinition );
691 if ( !styleDefinition.isEmpty() )
720 bool resultFlag =
false;
730 if ( mSourceType == QLatin1String(
"xyz" ) && dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
734 metadata.
setIdentifier( mArcgisLayerConfiguration.value( QStringLiteral(
"serviceUri" ) ).toString() );
735 const QString parentIdentifier = mArcgisLayerConfiguration.value( QStringLiteral(
"serviceItemId" ) ).toString();
736 if ( !parentIdentifier.isEmpty() )
741 metadata.
setTitle( mArcgisLayerConfiguration.value( QStringLiteral(
"name" ) ).toString() );
742 const QString copyright = mArcgisLayerConfiguration.value( QStringLiteral(
"copyrightText" ) ).toString();
743 if ( !copyright.isEmpty() )
752 else if ( mSourceType == QLatin1String(
"vtpk" ) )
755 if ( !reader.
open() )
757 QgsDebugMsg( QStringLiteral(
"failed to open VTPK file: " ) + mSourcePath );
785 if ( sourceUrl.isLocalFile() )
790 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
794 else if (
sourceType == QLatin1String(
"mbtiles" ) )
817 if ( sourceUrl.isLocalFile() )
821 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
825 else if (
sourceType == QLatin1String(
"mbtiles" ) )
840 QString info = QStringLiteral(
"<html><head></head>\n<body>\n" );
844 info += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" ) %
845 QStringLiteral(
"<table class=\"list-view\">\n" );
847 info += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"Source type" ) % QStringLiteral(
"</td><td>" ) %
sourceType() % QStringLiteral(
"</td></tr>\n" );
849 info += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"Zoom levels" ) % QStringLiteral(
"</td><td>" ) % QStringLiteral(
"%1 - %2" ).arg(
sourceMinZoom() ).arg(
sourceMaxZoom() ) % QStringLiteral(
"</td></tr>\n" );
851 info += QLatin1String(
"</table>\n<br>" );
857 info += QStringLiteral(
"<h1>" ) % tr(
"Identification" ) % QStringLiteral(
"</h1>\n<hr>\n" ) %
859 QStringLiteral(
"<br>\n" ) %
862 QStringLiteral(
"<h1>" ) % tr(
"Extent" ) % QStringLiteral(
"</h1>\n<hr>\n" ) %
864 QStringLiteral(
"<br>\n" ) %
867 QStringLiteral(
"<h1>" ) % tr(
"Access" ) % QStringLiteral(
"</h1>\n<hr>\n" ) %
869 QStringLiteral(
"<br>\n" ) %
873 QStringLiteral(
"<h1>" ) % tr(
"Contacts" ) % QStringLiteral(
"</h1>\n<hr>\n" ) %
875 QStringLiteral(
"<br><br>\n" ) %
878 QStringLiteral(
"<h1>" ) % tr(
"References" ) % QStringLiteral(
"</h1>\n<hr>\n" ) %
880 QStringLiteral(
"<br>\n" ) %
883 QStringLiteral(
"<h1>" ) % tr(
"History" ) % QStringLiteral(
"</h1>\n<hr>\n" ) %
885 QStringLiteral(
"<br>\n" ) %
887 QStringLiteral(
"\n</body>\n</html>\n" );
902 if ( rawTiles.isEmpty() )
904 return rawTiles.first().data;
909 mRenderer.reset( r );
915 return mRenderer.get();
926 return mLabeling.get();
931 QList< QgsFeature > res;
932 res.reserve( mSelectedFeatures.size() );
933 for (
auto it = mSelectedFeatures.begin(); it != mSelectedFeatures.end(); ++it )
934 res.append( it.value() );
941 return mSelectedFeatures.size();
952 QSet< QgsFeatureId > prevSelection;
953 prevSelection.reserve( mSelectedFeatures.size() );
954 for (
auto it = mSelectedFeatures.begin(); it != mSelectedFeatures.end(); ++it )
955 prevSelection.insert( it.key() );
962 mSelectedFeatures.clear();
973 bool isPointOrRectangle;
978 isPointOrRectangle =
true;
979 point = selectionGeom.
asPoint();
988 auto addDerivedFields = [](
QgsFeature & feature,
const int tileZoom,
const QString & layer )
991 fields.
append(
QgsField( QStringLiteral(
"tile_zoom" ), QVariant::Int ) );
992 fields.
append(
QgsField( QStringLiteral(
"tile_layer" ), QVariant::String ) );
994 attributes << tileZoom << layer;
999 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
1000 QList< QgsFeature > singleSelectCandidates;
1003 if ( isSinglePoint )
1028 for (
int row = tileRange.
startRow(); row <= tileRange.
endRow(); ++row )
1034 if ( data.isEmpty() )
1038 if ( !decoder.
decode( tileID, data ) )
1041 QMap<QString, QgsFields> perLayerFields;
1042 const QStringList layerNames = decoder.
layers();
1043 for (
const QString &layerName : layerNames )
1045 QSet<QString> fieldNames = qgis::listToSet( decoder.
layerFieldNames( layerName ) );
1050 const QStringList featuresLayerNames = features.keys();
1051 for (
const QString &layerName : featuresLayerNames )
1053 const QgsFields fFields = perLayerFields[layerName];
1054 const QVector<QgsFeature> &layerFeatures = features[layerName];
1057 if ( renderContext && mRenderer && !mRenderer->willRenderFeature( f, tileZoom, layerName, *renderContext ) )
1060 if ( f.geometry().intersects( r ) )
1062 bool selectFeature =
true;
1063 if ( selectionGeomPrepared )
1065 switch ( relationship )
1068 selectFeature = selectionGeomPrepared->intersects( f.geometry().constGet() );
1071 selectFeature = selectionGeomPrepared->contains( f.geometry().constGet() );
1076 if ( selectFeature )
1079 addDerivedFields( derivedFeature, tileZoom, layerName );
1081 singleSelectCandidates << derivedFeature;
1083 mSelectedFeatures.insert( derivedFeature.
id(), derivedFeature );
1098 for (
auto it = mSelectedFeatures.begin(); it != mSelectedFeatures.end(); )
1100 bool matchesGeometry =
false;
1101 if ( selectionGeomPrepared )
1103 switch ( relationship )
1106 matchesGeometry = selectionGeomPrepared->intersects( it->geometry().constGet() );
1109 matchesGeometry = selectionGeomPrepared->contains( it->geometry().constGet() );
1115 switch ( relationship )
1118 matchesGeometry = it->geometry().intersects( r );
1121 matchesGeometry = r.
contains( it->geometry().boundingBox() );
1128 singleSelectCandidates << it.value();
1138 it = mSelectedFeatures.erase( it );
1154 double smallestArea = std::numeric_limits< double >::max();
1155 double smallestLength = std::numeric_limits< double >::max();
1156 for (
const QgsFeature &candidate : std::as_const( singleSelectCandidates ) )
1158 if ( !mSelectedFeatures.contains( candidate.id() ) )
1161 switch ( candidate.geometry().type() )
1164 bestCandidate = candidate;
1168 const double length = candidate.geometry().length();
1171 bestCandidate = candidate;
1172 smallestLength = length;
1178 const double area = candidate.geometry().area();
1181 bestCandidate = candidate;
1182 smallestArea = area;
1193 if ( !bestCandidate.
isValid() )
1196 double smallestArea = std::numeric_limits< double >::max();
1197 double smallestLength = std::numeric_limits< double >::max();
1198 for (
const QgsFeature &candidate : std::as_const( singleSelectCandidates ) )
1200 switch ( candidate.geometry().type() )
1203 bestCandidate = candidate;
1207 const double length = candidate.geometry().length();
1210 bestCandidate = candidate;
1211 smallestLength = length;
1217 const double area = candidate.geometry().area();
1220 bestCandidate = candidate;
1221 smallestArea = area;
1234 if ( prevSelection.contains( bestCandidate.
id() ) )
1235 mSelectedFeatures.remove( bestCandidate.
id() );
1237 mSelectedFeatures.insert( bestCandidate.
id(), bestCandidate );
1245 mSelectedFeatures.insert( bestCandidate.
id(), bestCandidate );
1250 if ( mSelectedFeatures.contains( bestCandidate.
id() ) )
1252 mSelectedFeatures.clear();
1253 mSelectedFeatures.insert( bestCandidate.
id(), bestCandidate );
1257 mSelectedFeatures.clear();
1264 mSelectedFeatures.remove( bestCandidate.
id() );
1271 QSet< QgsFeatureId > newSelection;
1272 newSelection.reserve( mSelectedFeatures.size() );
1273 for (
auto it = mSelectedFeatures.begin(); it != mSelectedFeatures.end(); ++it )
1274 newSelection.insert( it.key() );
1277 if ( prevSelection != newSelection )
1283 if ( mSelectedFeatures.empty() )
1286 mSelectedFeatures.clear();
1295QgsVectorTileDataProvider::QgsVectorTileDataProvider(
1296 const ProviderOptions &options,
1297 QgsDataProvider::ReadFlags flags )
1306QString QgsVectorTileDataProvider::name()
const
1308 return QStringLiteral(
"vectortile" );
1311QString QgsVectorTileDataProvider::description()
const
1321bool QgsVectorTileDataProvider::isValid()
const
1326bool QgsVectorTileDataProvider::renderInPreview(
const PreviewContext &context )
1331 return context.lastRenderingTimeMs <= 1000;
@ IsBasemapLayer
Layer is considered a 'basemap' layer, and certain properties of the layer should be ignored when cal...
@ ToggleSelection
Enables a "toggle" selection mode, where previously selected matching features will be deselected and...
@ SingleFeatureSelection
Select only a single feature, picking the "best" match for the selection geometry.
SelectGeometryRelationship
Geometry relationship test to apply for selecting features.
@ Within
Select where features are within the reference geometry.
@ Intersect
Select where features intersect the reference geometry.
SelectBehavior
Specifies how a selection should be applied.
@ SetSelection
Set selection, removing any existing selection.
@ AddToSelection
Add selection to current selection.
@ IntersectSelection
Modify current selection to include only select features which match.
@ RemoveFromSelection
Remove from current selection.
static QgsCoordinateReferenceSystem convertSpatialReference(const QVariantMap &spatialReferenceMap)
Converts a spatial reference JSON definition to a QgsCoordinateReferenceSystem value.
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy...
ErrorCode get(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "get" operation on the specified request.
@ NetworkError
A network error occurred.
@ ServerExceptionError
An exception was raised by the server.
@ NoError
No error was encountered.
@ TimeoutError
Timeout was reached before a reply was received.
QgsNetworkReplyContent reply() const
Returns the content of the network reply, after a get(), post(), head() or put() request has been mad...
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.
Abstract base class for spatial data provider implementations.
Class for storing the component parts of a RDBMS data source URI (e.g.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
int removeParam(const QString &key)
Removes a generic parameter by key.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
QgsHttpHeaders httpHeaders() const
Returns http headers.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
bool isValid() const
Returns the validity of this feature.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
QgsWkbTypes::GeometryType type
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
static QVariant parseJson(const std::string &jsonString)
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and ...
Context for a MapBox GL style conversion operation.
void setPixelSizeConversionFactor(double sizeConversionFactor)
Sets the pixel size conversion factor, used to scale the original pixel sizes when converting styles.
void setSprites(const QImage &image, const QVariantMap &definitions)
Sets the sprite image and definitions JSON to use during conversion.
void setTargetUnit(QgsUnitTypes::RenderUnit targetUnit)
Sets the target unit type.
QVariantMap spriteDefinitions() const
Returns the sprite definitions to use during conversion.
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings.
QgsVectorTileRenderer * renderer() const
Returns a new instance of a vector tile renderer representing the converted style,...
QgsVectorTileLabeling * labeling() const
Returns a new instance of a vector tile labeling representing the converted style,...
Result convert(const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context=nullptr)
Converts a JSON style map, and returns the resultant status of the conversion.
QList< QgsMapLayer * > createSubLayers() const
Returns a list of new map layers corresponding to sublayers of the style, e.g.
@ Success
Conversion was successful.
QString errorMessage() const
Returns a descriptive error message if an error was encountered during the style conversion,...
QStringList warnings() const
Returns a list of user-friendly warnings generated during the conversion, e.g.
static QString typeToString(QgsMapLayerType type)
Converts a map layer type to a string value.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for all map layer types.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
QgsCoordinateReferenceSystem crs
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QString mLayerName
Name of the layer - used for display.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
QgsLayerMetadata metadata
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
QString mProviderKey
Data provider key (name of the data provider)
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
virtual QgsError error() const
Gets current status error.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
QString mDataSource
Data source description string, varies by layer type.
virtual QString loadDefaultMetadata(bool &resultFlag)
Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a rec...
void setValid(bool valid)
Sets whether layer is valid or not.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Utility class for reading and writing MBTiles files (which are SQLite3 databases).
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
QByteArray content() const
Returns the reply content.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
A class to represent a 2D point.
The class is used as a container of context for various read/write operations on other objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle contains other rectangle.
Contains information about the context of a rendering operation.
Encapsulates the context of a layer selection operation.
double scale() const
Returns the map scale at which the selection should occur.
virtual QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const
Writes the set to an XML element.
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system associated with the tiles.
int minimumZoom() const
Returns the minimum zoom level for tiles present in the set.
int scaleToZoomLevel(double scale) const
Finds the best fitting (integer) zoom level given a map scale denominator.
int maximumZoom() const
Returns the maximum zoom level for tiles present in the set.
QgsTileMatrix tileMatrix(int zoom) const
Returns the tile matrix corresponding to the specified zoom.
virtual bool readXml(const QDomElement &element, QgsReadWriteContext &context)
Reads the set from an XML element.
void dropMatricesOutsideZoomRange(int minimumZoom, int maximumZoom)
Deletes any existing matrices which fall outside the zoom range specified by minimumZoom to maximumZo...
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
QgsTileRange tileRangeFromExtent(const QgsRectangle &mExtent) const
Returns tile range that fully covers the given extent.
Range of tiles in a tile matrix to be rendered.
int endColumn() const
Returns index of the last column in the range.
int endRow() const
Returns index of the last row in the range.
int startRow() const
Returns index of the first row in the range.
int startColumn() const
Returns index of the first column in the range.
Stores coordinates of a tile in a tile matrix set.
int zoomLevel() const
Returns tile's zoom level (Z)
int column() const
Returns tile's column index (X)
int row() const
Returns tile's row index (Y)
@ RenderMillimeters
Millimeters.
Basic labeling configuration for vector tile layers.
The default vector tile renderer implementation.
static QList< QgsVectorTileBasicRendererStyle > simpleStyleWithRandomColors()
Returns a list of styles to render all layers, using random colors.
Base class for labeling configuration classes for vector tile layers.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads labeling properties from given XML element.
This class provides map rendering functionality for vector tile layers.
Implements a map layer that is dedicated to rendering of vector tiles.
QgsVectorTileLayer(const QString &path=QString(), const QString &baseName=QString(), const QgsVectorTileLayer::LayerOptions &options=QgsVectorTileLayer::LayerOptions())
Constructs a new vector tile layer.
QByteArray getRawTile(QgsTileXYZ tileID)
Fetches raw tile data for the give tile coordinates.
bool readXml(const QDomNode &layerNode, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const override
Write the style for the layer into the document provided.
void setRenderer(QgsVectorTileRenderer *r)
Sets renderer for the map layer.
bool loadDefaultStyleAndSubLayers(QString &error, QStringList &warnings, QList< QgsMapLayer * > &subLayers)
Loads the default style for the layer, and returns true if the style was successfully loaded.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const FINAL
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
QString sourceType() const
Returns type of the data source.
bool writeXml(QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
void selectByGeometry(const QgsGeometry &geometry, const QgsSelectionContext &context, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, Qgis::SelectGeometryRelationship relationship=Qgis::SelectGeometryRelationship::Intersect, Qgis::SelectionFlags flags=Qgis::SelectionFlags(), QgsRenderContext *renderContext=nullptr)
Selects features found within the search geometry (in layer's coordinates).
void setLabeling(QgsVectorTileLabeling *labeling)
Sets labeling for the map layer.
QList< QgsFeature > selectedFeatures() const
Returns the list of features currently selected in the layer.
QgsVectorTileLabeling * labeling() const
Returns currently assigned labeling.
~QgsVectorTileLayer() override
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) override
Read the symbology for the current layer from the DOM node supplied.
int sourceMinZoom() const
Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QString loadDefaultStyle(bool &resultFlag) override
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
Qgis::MapLayerProperties properties() const override
Returns the map layer properties of this layer.
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const FINAL
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
int sourceMaxZoom() const
Returns maximum zoom level at which source has any valid tiles (negative = unconstrained)
QgsVectorTileRenderer * renderer() const
Returns currently assigned renderer.
void removeSelection()
Clear selection.
QgsDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QString loadDefaultMetadata(bool &resultFlag) override
Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a rec...
QString sourcePath() const
Returns URL/path of the data source (syntax different to each data source type)
void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
QgsVectorTileMatrixSet & tileMatrixSet()
Returns the vector tile matrix set.
void selectionChanged()
Emitted whenever the selected features in the layer are changed.
QgsVectorTileLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
static QList< QgsVectorTileRawData > blockingFetchTileRawData(const QString &sourceType, const QString &sourcePath, const QgsTileMatrix &tileMatrix, const QPointF &viewCenter, const QgsTileRange &range, const QString &authid, const QgsHttpHeaders &headers, QgsFeedback *feedback=nullptr)
Returns raw tile data for the specified range of tiles. Blocks the caller until all tiles are fetched...
This class is responsible for decoding raw tile data written with Mapbox Vector Tiles encoding.
QStringList layerFieldNames(const QString &layerName) const
Returns a list of all field names in a tile. It can only be called after a successful decode()
QStringList layers() const
Returns a list of sub-layer names in a tile. It can only be called after a successful decode()
QgsVectorTileFeatures layerFeatures(const QMap< QString, QgsFields > &perLayerFields, const QgsCoordinateTransform &ct, const QSet< QString > *layerSubset=nullptr) const
Returns decoded features grouped by sub-layers.
bool decode(QgsTileXYZ tileID, const QByteArray &rawTileData)
Tries to decode raw tile data, returns true on success.
bool fromEsriJson(const QVariantMap &json)
Initializes the tile structure settings from an ESRI REST VectorTileService json map.
static QgsVectorTileMatrixSet fromWebMercator(int minimumZoom=0, int maximumZoom=14)
Returns a vector tile structure corresponding to the standard web mercator/GoogleCRS84Quad setup.
Abstract base class for all vector tile renderer implementations.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
static bool checkXYZUrlTemplate(const QString &url)
Checks whether the URL template string is correct (contains {x}, {y} / {-y}, {z} placeholders)
static QgsFields makeQgisFields(const QSet< QString > &flds)
Returns QgsFields instance based on the set of field names.
Utility class for reading and writing ESRI VTPK files.
QgsLayerMetadata layerMetadata() const
Reads layer metadata from the VTPK file.
bool open()
Tries to open the file, returns true on success.
QgsMapLayerType
Types of layers that can be added to a map.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
#define QgsDebugMsgLevel(str, level)
#define QgsSetRequestInitiatorClass(request, _class)
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.
Setting options for loading vector tile layers.