78#include <QTemporaryFile>
81#include <nlohmann/json.hpp>
105 : mContext( context )
110 mWmsParameters.
dump();
115 removeTemporaryLayers();
121 std::unique_ptr<QgsWmsRestorer> restorer;
134 for (
const auto &layer : std::as_const( layersToRender ) )
137 if ( layer->dataProvider()->name() == QLatin1String(
"wms" ) )
141 const auto image { layerNode->getLegendGraphicBlocking() };
142 if ( !image.isNull() )
147 const double w = image.width() / dpmm;
148 const double h = image.height() / dpmm;
149 const QSizeF newWmsSize { w, h };
162 if ( !mWmsParameters.
bbox().isEmpty() )
166 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
167 configureMapSettings( tmp.get(), mapSettings );
173 context = configureDefaultRenderContext();
177 std::unique_ptr<QImage> image;
178 const QSizeF minSize = renderer.
minimumSize( &context );
179 const QSize size(
static_cast<int>( minSize.width() * dpmm ),
static_cast<int>( minSize.height() * dpmm ) );
184 image.reset( createImage( size ) );
187 QPainter painter( image.get() );
190 if ( painter.renderHints() & QPainter::SmoothPixmapTransform )
192 if ( painter.renderHints() & QPainter::LosslessImageRendering )
202 return image.release();
208 std::unique_ptr<QgsWmsRestorer> restorer;
222 std::unique_ptr<QImage> image( createImage( size ) );
226 std::unique_ptr<QPainter> painter;
227 painter.reset(
new QPainter( image.get() ) );
228 painter->setRenderHint( QPainter::Antialiasing,
true );
229 painter->scale( dpmm, dpmm );
240 nodeModel.
drawSymbol( settings, &ctx, size.height() / dpmm );
243 return image.release();
249 std::unique_ptr<QgsWmsRestorer> restorer;
269 std::unique_ptr<QgsWmsRestorer> restorer;
289 if ( vLayer->renderer() )
293 const QString ruleExp { vLayer->renderer()->legendKeyToExpression( ruleKey, vLayer, ok ) };
296 jsonSymbol[QStringLiteral(
"rule" )] = ruleExp;
305 void QgsRenderer::runHitTest(
const QgsMapSettings &mapSettings, HitTest &hitTest )
const
309 for (
const QString &
id : mapSettings.layerIds() )
326 runHitTestLayer( vl, usedSymbols, context );
332 std::unique_ptr<QgsFeatureRenderer> r( vl->
renderer()->
clone() );
334 r->startRender( context, vl->
fields() );
342 if ( moreSymbolsPerFeature )
344 for (
QgsSymbol *s : r->originalSymbolsForFeature( f, context ) )
350 r->stopRender( context );
362 std::unique_ptr<QgsWmsRestorer> restorer;
372 std::unique_ptr<QPainter> painter;
373 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
376 configureMapSettings( image.get(), mapSettings );
383 runHitTest( mapSettings,
symbols );
391 std::unique_ptr<QgsWmsRestorer> restorer;
396 if ( templateName.isEmpty() )
419 std::unique_ptr<QgsPrintLayout> layout( sourceLayout->
clone() );
423 QStringList atlasPk = mWmsParameters.
atlasPk();
424 if ( !atlasPk.isEmpty() )
426 atlas = layout->atlas();
427 if ( !atlas || !atlas->
enabled() )
440 if ( atlasPk.size() == 1 && atlasPk.at( 0 ) == QLatin1String(
"*" ) )
444 if ( atlas->
count() > maxAtlasFeatures )
452 if ( pkIndexes.size() == 0 )
454 QgsDebugMsgLevel( QStringLiteral(
"Atlas print: layer %1 has no primary key attributes" ).arg( cLayer->
name() ), 2 );
458 const int pkIndexesSize { std::max<int>( pkIndexes.size(), 1 ) };
460 QStringList pkAttributeNames;
461 for (
int pkIndex : std::as_const( pkIndexes ) )
463 pkAttributeNames.append( cLayer->
fields().
at( pkIndex ).
name() );
466 const int nAtlasFeatures = atlasPk.size() / pkIndexesSize;
467 if ( nAtlasFeatures * pkIndexesSize != atlasPk.size() )
473 if ( nAtlasFeatures > maxAtlasFeatures )
478 QString filterString;
479 int currentAtlasPk = 0;
481 for (
int i = 0; i < nAtlasFeatures; ++i )
485 filterString.append(
" OR " );
488 filterString.append(
"( " );
491 if ( pkAttributeNames.isEmpty() )
493 filterString.append( QStringLiteral(
"$id = %1" ).arg( atlasPk.at( currentAtlasPk ) ) );
498 for (
int j = 0; j < pkIndexes.size(); ++j )
502 filterString.append(
" AND " );
509 filterString.append(
" )" );
517 if ( !errorString.isEmpty() )
519 throw QgsException( QStringLiteral(
"An error occurred during the Atlas print: %1" ).arg( errorString ) );
531 auto image = std::make_unique<QImage>();
532 configureMapSettings( image.get(), mapSettings );
538 configurePrintLayout( layout.get(), mapSettings, atlas );
542 const QList<QgsMapLayer *> lyrs = mapSettings.
layers();
544#ifdef HAVE_SERVER_PYTHON_PLUGINS
545 mContext.accessControl()->resolveFilterFeatures( lyrs );
549 QHash<const QgsVectorLayer *, QStringList> fltrs;
554 fltrs.insert( vl, dimensionFilter( vl ) );
566 QTemporaryFile tempOutputFile( QDir::tempPath() +
'/' + QStringLiteral(
"XXXXXX.%1" ).arg( extension ) );
567 if ( !tempOutputFile.open() )
569 throw QgsException( QStringLiteral(
"Could not open temporary file for the GetPrint request." ) );
577 if ( !mWmsParameters.
dpi().isEmpty() )
580 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
582 exportSettings.
dpi = dpi;
595 atlasSvgExport.
exportToSvg( tempOutputFile.fileName(), exportSettings );
601 exporter.
exportToSvg( tempOutputFile.fileName(), exportSettings );
610 double dpi( layout->renderContext().dpi() );
611 if ( !mWmsParameters.
dpi().isEmpty() )
614 double _dpi = mWmsParameters.
dpi().toDouble( &ok );
618 exportSettings.
dpi = dpi;
624 QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
629 const QSize imageSize = QSize(
static_cast<int>( width.
length() * dpi / 25.4 ),
static_cast<int>( height.
length() * dpi / 25.4 ) );
631 const QString paramWidth = mWmsParameters.
width();
632 const QString paramHeight = mWmsParameters.
height();
637 if ( !paramWidth.isEmpty() && !paramHeight.isEmpty() )
639 exportSettings.
imageSize = QSize( paramWidth.toInt(), paramHeight.toInt() );
641 else if ( !paramWidth.isEmpty() && paramHeight.isEmpty() )
643 exportSettings.
imageSize = QSize( paramWidth.toInt(),
static_cast<double>( paramWidth.toInt() ) / imageSize.width() * imageSize.height() );
645 else if ( paramWidth.isEmpty() && !paramHeight.isEmpty() )
647 exportSettings.
imageSize = QSize(
static_cast<double>( paramHeight.toInt() ) / imageSize.height() * imageSize.width(), paramHeight.toInt() );
655 exportSettings.
pages.append( 0 );
663 atlasPngExport.
exportToImage( tempOutputFile.fileName(), exportSettings );
667 throw QgsServiceException( QStringLiteral(
"Bad request" ), QStringLiteral(
"Atlas error: empty atlas." ), QString(), 400 );
673 exporter.
exportToImage( tempOutputFile.fileName(), exportSettings );
681 if ( !mWmsParameters.
dpi().isEmpty() )
684 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
686 exportSettings.
dpi = dpi;
691 exportSettings.
rasterizeWholeImage = layout->customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
694 if ( requestMapScales.size() > 0 )
704 if ( exportThemes.size() > 0 )
731 exporter.
exportToPdf( tempOutputFile.fileName(), exportSettings );
741 handlePrintErrors( atlas->
layout() );
745 handlePrintErrors( layout.get() );
748 return tempOutputFile.readAll();
755 QList<QgsLayoutItemMap *> maps;
761 for (
const auto &map : std::as_const( maps ) )
767 if ( cMapParams.
mLayers.isEmpty() )
772 if ( !atlas || !map->atlasDriven() )
778 c->removeLayoutItem( map );
795 if ( cMapParams.
mScale > 0 )
797 map->setScale(
static_cast<double>( cMapParams.
mScale ) );
803 map->setMapRotation( cMapParams.
mRotation );
807 if ( !map->keepLayerSet() )
809 QList<QgsMapLayer *> layerSet;
811 for (
const auto &layer : std::as_const( cMapParams.mLayers ) )
815 QList<QgsMapLayer *> layersFromGroup;
817 const QList<QgsMapLayer *> cLayersFromGroup = mContext.
layersFromGroup( layer.mNickname );
818 for (
QgsMapLayer *layerFromGroup : cLayersFromGroup )
820 if ( !layerFromGroup )
825 layersFromGroup.push_front( layerFromGroup );
828 if ( !layersFromGroup.isEmpty() )
830 layerSet.append( layersFromGroup );
842 setLayerStyle( mlayer, layer.mStyle );
847 std::reverse( layerSet.begin(), layerSet.end() );
852 QMap<QString, QString> layersStyle;
853 if ( map->followVisibilityPreset() )
863 const QString presetName = map->followVisibilityPresetName();
864 if ( layerSet.isEmpty() )
868 layerSet = map->layersToRender( &ex );
871 map->setFollowVisibilityPreset(
false );
875 for (
const auto &layerMapThemeRecord : std::as_const( mapThemeRecords ) )
877 if ( layerSet.contains( layerMapThemeRecord.layer() ) )
879 layersStyle.insert( layerMapThemeRecord.layer()->id(), layerMapThemeRecord.layer()->styleManager()->style( layerMapThemeRecord.currentStyle ).xmlData() );
885 const QList<QgsMapLayer *> highlights = highlightLayers( cMapParams.
mHighlightLayers );
886 for (
const auto &hl : std::as_const( highlights ) )
888 layerSet.prepend( hl );
891 map->setLayers( layerSet );
892 map->setKeepLayerSet(
true );
896 if ( !layersStyle.isEmpty() )
898 map->setLayerStyleOverrides( layersStyle );
899 map->setKeepLayerStyles(
true );
906 map->grid()->setIntervalX(
static_cast<double>( cMapParams.
mGridX ) );
907 map->grid()->setIntervalY(
static_cast<double>( cMapParams.
mGridY ) );
912 QList<QgsLayoutItemLabel *> labels;
914 for (
const auto &label : std::as_const( labels ) )
917 const QString labelId = label->
id();
918 const QString labelParam = mWmsParameters.
layoutParameter( labelId, ok );
923 if ( labelParam.isEmpty() )
927 c->removeItem( label );
932 label->setText( labelParam );
936 QList<QgsLayoutItemHtml *> htmls;
938 for (
const auto &html : std::as_const( htmls ) )
940 if ( html->frameCount() == 0 )
945 const QString htmlId = htmlFrame->
id();
946 const QString htmlValue = mWmsParameters.
layoutParameter( htmlId, ok );
956 if ( htmlValue.isEmpty() )
958 c->removeMultiFrame( html );
965 QUrl newUrl( htmlValue );
966 html->setUrl( newUrl );
970 html->setHtml( htmlValue );
977 QList<QgsLayoutItemLegend *> legends;
979 for (
const auto &legend : std::as_const( legends ) )
981 if ( legend->autoUpdateModel() )
991 legend->setAutoUpdateModel(
false );
995 QStringList layerSet;
996 QList<QgsMapLayer *> mapLayers;
997 if ( map->
layers().isEmpty() )
1001 mapLayers = mProject->
mapLayers(
true ).values();
1005 mapLayers = map->
layers();
1007 const QList<QgsMapLayer *> layerList = mapLayers;
1008 for (
const auto &layer : layerList )
1009 layerSet << layer->id();
1021 for (
const auto &layerId : layerIds )
1028 if ( !layerSet.contains( layerId ) )
1030 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
1037 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
1061 std::unique_ptr<QgsWmsRestorer> restorer;
1072 std::unique_ptr<QPainter> painter;
1073 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
1076 configureMapSettings( image.get(), mapSettings );
1082 QPainter *renderedPainter = layersRendering( mapSettings, image.get() );
1083 if ( !renderedPainter )
1088 painter.reset( renderedPainter );
1091 annotationsRendering( painter.get(), mapSettings );
1097 QImage *scaledImage = scaleImage( image.get() );
1099 image.reset( scaledImage );
1117 QList<QgsDxfExport::DxfLayer> dxfLayers;
1129 int layerAttribute = -1;
1130 if ( attributes.size() > layerIdx )
1141 QString
crs = mWmsParameters.
crs();
1142 if (
crs.compare( QStringLiteral(
"CRS:84" ), Qt::CaseInsensitive ) == 0 )
1144 crs = QStringLiteral(
"EPSG:4326" );
1147 else if (
crs.isEmpty() )
1149 crs = QStringLiteral(
"EPSG:4326" );
1183 auto dxf = std::make_unique<QgsDxfExport>();
1184 dxf->setExtent( mapExtent );
1185 dxf->setDestinationCrs( outputCRS );
1186 dxf->addLayers( dxfLayers );
1188 dxf->setSymbologyExport( mWmsParameters.
dxfMode() );
1191 dxf->setSymbologyScale( mWmsParameters.
dxfScale() );
1194 dxf->setForce2d( mWmsParameters.
isForce2D() );
1196 if ( mWmsParameters.
noMText() )
1204 dxf->setFlags( flags );
1231 auto pdf = std::make_unique<QgsMapRendererTask>( ms, tmpFileName, QStringLiteral(
"PDF" ),
false,
QgsTask::Hidden, geospatialPdf, pdfExportDetails );
1234 pdf->setSaveWorldFile(
true );
1242 if ( i < 0 || i > mapSettings.
outputSize().width() )
1249 if ( j < 0 || j > mapSettings.
outputSize().height() )
1272 const bool ijDefined = !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty();
1273 const bool xyDefined = !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty();
1274 const bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1275 const bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1277 if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
1281 if ( mWmsParameters.
j().isEmpty() )
1294 std::unique_ptr<QImage> outputImage( createImage( mContext.
mapSize() ) );
1297 std::unique_ptr<QgsWmsRestorer> restorer;
1302 bool mandatoryCrsParam =
true;
1303 if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.
crs().isEmpty() )
1305 mandatoryCrsParam =
false;
1311 configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
1327#ifdef HAVE_SERVER_PYTHON_PLUGINS
1328 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
1331 QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );
1336 ba = convertFeatureInfoToText( result );
1338 ba = convertFeatureInfoToHtml( result );
1340 ba = convertFeatureInfoToJson( layers, result, mapSettings.
destinationCrs() );
1342 ba = result.toByteArray();
1347 QImage *QgsRenderer::createImage(
const QSize &size )
const
1349 std::unique_ptr<QImage> image;
1357 image = std::make_unique<QImage>( size, QImage::Format_ARGB32_Premultiplied );
1362 image = std::make_unique<QImage>( size, QImage::Format_RGB32 );
1367 if ( image->isNull() )
1369 throw QgsException( QStringLiteral(
"createImage: image could not be created, check for out of memory conditions" ) );
1372 const int dpm =
static_cast<int>( mContext.
dotsPerMm() * 1000.0 );
1373 image->setDotsPerMeterX( dpm );
1374 image->setDotsPerMeterY( dpm );
1376 return image.release();
1379 void QgsRenderer::configureMapSettings(
const QPaintDevice *paintDevice,
QgsMapSettings &mapSettings,
bool mandatoryCrsParam )
1383 throw QgsException( QStringLiteral(
"configureMapSettings: no paint device" ) );
1386 mapSettings.
setOutputSize( QSize( paintDevice->width(), paintDevice->height() ) );
1393 if ( !mWmsParameters.
bbox().isEmpty() && mapExtent.
isEmpty() )
1398 QString
crs = mWmsParameters.
crs();
1399 if (
crs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 )
1401 crs = QString(
"EPSG:4326" );
1404 else if (
crs.isEmpty() && !mandatoryCrsParam )
1406 crs = QString(
"EPSG:4326" );
1416 QgsWmsParameter parameter;
1460 else if ( backgroundColor.isValid() )
1491 const QString timeString { mWmsParameters.
dimensionValues().value( QStringLiteral(
"TIME" ), QString() ) };
1492 if ( !timeString.isEmpty() )
1494 bool isValidTemporalRange {
true };
1497 const QDateTime dt { QDateTime::fromString( timeString, Qt::DateFormat::ISODateWithMs ) };
1510 isValidTemporalRange =
false;
1515 if ( isValidTemporalRange )
1524 QgsRenderContext QgsRenderer::configureDefaultRenderContext( QPainter *painter )
1537 QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers,
const QgsMapSettings &mapSettings,
const QImage *outputImage,
const QString &version )
const
1541 bool ijDefined = ( !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty() );
1543 bool xyDefined = ( !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty() );
1545 bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1547 bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1550 if ( featureCount < 1 )
1555 int i = mWmsParameters.
iAsInt();
1556 int j = mWmsParameters.
jAsInt();
1557 if ( xyDefined && !ijDefined )
1559 i = mWmsParameters.
xAsInt();
1560 j = mWmsParameters.
yAsInt();
1564 if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
1566 i *= ( outputImage->width() /
static_cast<double>( width ) );
1567 j *= ( outputImage->height() /
static_cast<double>( height ) );
1571 std::unique_ptr<QgsRectangle> featuresRect;
1572 std::unique_ptr<QgsGeometry> filterGeom;
1573 std::unique_ptr<QgsPointXY> infoPoint;
1575 if ( i != -1 && j != -1 )
1578 infoPointToMapCoordinates( i, j, infoPoint.get(), mapSettings );
1580 else if ( filtersDefined )
1585 if ( filterGeomDefined )
1590 QDomDocument result;
1591 const QDomNode header = result.createProcessingInstruction( QStringLiteral(
"xml" ), QStringLiteral(
"version=\"1.0\" encoding=\"UTF-8\"" ) );
1592 result.appendChild( header );
1594 QDomElement getFeatureInfoElement;
1598 getFeatureInfoElement = result.createElement( QStringLiteral(
"wfs:FeatureCollection" ) );
1599 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:wfs" ), QStringLiteral(
"http://www.opengis.net/wfs" ) );
1600 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1601 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1602 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
1603 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1604 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:qgs" ), QStringLiteral(
"http://qgis.org/gml" ) );
1605 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1606 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), QStringLiteral(
"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://qgis.org/gml" ) );
1611 if ( featureInfoElemName.isEmpty() )
1613 featureInfoElemName = QStringLiteral(
"GetFeatureInfoResponse" );
1616 if ( featureInfoElemNs.isEmpty() )
1618 getFeatureInfoElement = result.createElement( featureInfoElemName );
1622 getFeatureInfoElement = result.createElementNS( featureInfoElemNs, featureInfoElemName );
1626 if ( !featureInfoSchema.isEmpty() )
1628 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1629 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), featureInfoSchema );
1632 result.appendChild( getFeatureInfoElement );
1642 for (
const QString &queryLayer : queryLayers )
1644 bool validLayer =
false;
1645 bool queryableLayer =
true;
1646 for (
QgsMapLayer *layer : std::as_const( layers ) )
1652 if ( !queryableLayer )
1657 QDomElement layerElement;
1660 layerElement = getFeatureInfoElement;
1664 layerElement = result.createElement( QStringLiteral(
"Layer" ) );
1665 QString layerName = queryLayer;
1668 QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.constFind( layerName );
1669 if ( layerAliasIt != layerAliasMap.constEnd() )
1671 layerName = layerAliasIt.value();
1674 layerElement.setAttribute( QStringLiteral(
"name" ), layerName );
1675 const QString layerTitle = layer->serverProperties()->title();
1676 if ( !layerTitle.isEmpty() )
1678 layerElement.setAttribute( QStringLiteral(
"title" ), layerTitle );
1682 layerElement.setAttribute( QStringLiteral(
"title" ), layerName );
1684 getFeatureInfoElement.appendChild( layerElement );
1687 layerElement.setAttribute( QStringLiteral(
"id" ), layer->id() );
1693 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
1696 ( void ) featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, featuresRect.get(), filterGeom.get() );
1702 QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
1711 QgsPointXY layerInfoPoint = mapSettings.mapToLayerCoordinates( layer, *( infoPoint.get() ) );
1718 layerElement = result.createElement( QStringLiteral(
"gml:featureMember" ) );
1719 getFeatureInfoElement.appendChild( layerElement );
1722 ( void ) featureInfoFromRasterLayer( rasterLayer, mapSettings, &layerInfoPoint, renderContext, result, layerElement, version );
1730 param.mValue = queryLayer;
1733 else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.
isValidGroup( queryLayer ) ) )
1736 param.mValue = queryLayer;
1738 bool hasGroupAndQueryable {
false };
1743 for (
const QString &ql : constNicks )
1747 const QList<QgsMapLayer *> constLayers { mContext.
layerGroups()[ql] };
1750 if ( ( !ml->serverProperties()->shortName().isEmpty() && ml->serverProperties()->shortName() == queryLayer ) || ( ml->name() == queryLayer ) )
1756 hasGroupAndQueryable =
true;
1765 if ( !hasGroupAndQueryable )
1772 if ( featuresRect && !featuresRect->isNull() )
1776 QDomElement bBoxElem = result.createElement( QStringLiteral(
"gml:boundedBy" ) );
1777 QDomElement boxElem;
1779 if ( gmlVersion < 3 )
1791 boxElem.setAttribute( QStringLiteral(
"srsName" ),
crs.
authid() );
1793 bBoxElem.appendChild( boxElem );
1794 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1798 QDomElement bBoxElem = result.createElement( QStringLiteral(
"BoundingBox" ) );
1799 bBoxElem.setAttribute( QStringLiteral(
"CRS" ), mapSettings.destinationCrs().authid() );
1800 bBoxElem.setAttribute( QStringLiteral(
"minx" ),
qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1801 bBoxElem.setAttribute( QStringLiteral(
"maxx" ),
qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1802 bBoxElem.setAttribute( QStringLiteral(
"miny" ),
qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1803 bBoxElem.setAttribute( QStringLiteral(
"maxy" ),
qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
1804 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1810 convertFeatureInfoToSia2045( result );
1826 std::unique_ptr<QgsGeometry> layerFilterGeom;
1829 layerFilterGeom.reset(
new QgsGeometry( *filterGeom ) );
1843 searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
1845 else if ( layerFilterGeom )
1847 searchRect = layerFilterGeom->boundingBox();
1849 else if ( !mWmsParameters.
bbox().isEmpty() )
1851 searchRect = layerRect;
1858 int featureCounter = 0;
1877 if ( layerFilterGeom )
1879 fReq.
setFilterExpression( QString(
"intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
1884#ifdef HAVE_SERVER_PYTHON_PLUGINS
1885 mContext.accessControl()->filterFeatures( layer, fReq );
1887 QStringList attributes;
1888 for (
const QgsField &field : fields )
1890 attributes.append( field.name() );
1892 attributes = mContext.accessControl()->layerAttributes( layer, attributes );
1900 r2->startRender( renderContext, layer->
fields() );
1903 bool featureBBoxInitialized =
false;
1912 if ( featureCounter > nFeatures )
1927 bool render = r2->willRenderFeature( feature, renderContext );
1940 if ( !featureBBoxInitialized && featureBBox->
isEmpty() )
1943 featureBBoxInitialized =
true;
1963 QDomElement elem = createFeatureGML(
1965#ifdef HAVE_SERVER_PYTHON_PLUGINS
1970 QDomElement featureMemberElem = infoDocument.createElement( QStringLiteral(
"gml:featureMember" ) );
1971 featureMemberElem.appendChild( elem );
1972 layerElement.appendChild( featureMemberElem );
1977 QDomElement featureElement = infoDocument.createElement( QStringLiteral(
"Feature" ) );
1979 layerElement.appendChild( featureElement );
1985 writeAttributesTabLayout( editConfig, layer, fields, featureAttributes, infoDocument, featureElement, renderContext
1986#ifdef HAVE_SERVER_PYTHON_PLUGINS
1994 for (
int i = 0; i < featureAttributes.count(); ++i )
1996 writeVectorLayerAttribute( i, layer, fields, featureAttributes, infoDocument, featureElement, renderContext
1997#ifdef HAVE_SERVER_PYTHON_PLUGINS
2009 QDomElement maptipElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2010 maptipElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"maptip" ) );
2014 featureElement.appendChild( maptipElem );
2020 QDomElement displayElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2021 displayElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"displayName" ) );
2024 displayExpression.
prepare( &context );
2025 displayElem.setAttribute( QStringLiteral(
"value" ), displayExpression.
evaluate( &context ).toString() );
2026 featureElement.appendChild( displayElem );
2032 QDomElement bBoxElem = infoDocument.createElement( QStringLiteral(
"BoundingBox" ) );
2033 bBoxElem.setAttribute( version == QLatin1String(
"1.1.1" ) ?
"SRS" :
"CRS",
outputCrs.authid() );
2038 featureElement.appendChild( bBoxElem );
2054 if ( segmentizeWktGeometry )
2062 geom.
set( segmentizedGeom );
2066 QDomElement geometryElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2067 geometryElement.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"geometry" ) );
2068 geometryElement.setAttribute( QStringLiteral(
"value" ), geom.
asWkt( mContext.
precision() ) );
2069 geometryElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"derived" ) );
2070 featureElement.appendChild( geometryElement );
2077 r2->stopRender( renderContext );
2088 QString groupName = container->
name();
2089 QDomElement nameElem;
2091 if ( !groupName.isEmpty() )
2093 nameElem = doc.createElement( groupName );
2094 parentElem.appendChild( nameElem );
2097 const QList<QgsAttributeEditorElement *> children = container->
children();
2102 writeAttributesTabGroup( child, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext );
2112 writeVectorLayerAttribute( idx, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext, attributes );
2123 if ( !editorContainer )
2128 writeAttributesTabGroup( editorContainer, layer, fields, featureAttributes, doc, featureElem, renderContext, attributes );
2131 void QgsRenderer::writeVectorLayerAttribute(
int attributeIndex,
QgsVectorLayer *layer,
const QgsFields &fields,
QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem,
QgsRenderContext &renderContext, QStringList *attributes )
const
2133#ifndef HAVE_SERVER_PYTHON_PLUGINS
2134 Q_UNUSED( attributes );
2147#ifdef HAVE_SERVER_PYTHON_PLUGINS
2149 if ( attributes && !attributes->contains( fields.
at( attributeIndex ).
name() ) )
2156 QDomElement attributeElement = doc.createElement( QStringLiteral(
"Attribute" ) );
2157 attributeElement.setAttribute( QStringLiteral(
"name" ), attributeName );
2160 featureElem.appendChild( attributeElement );
2182 :
Qgis::RasterIdentifyFormat::Value
2201 if ( !identifyResult.
isValid() )
2204 QMap<int, QVariant> attributes = identifyResult.
results();
2218 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
2221 feature.
setAttribute( index++, QString::number( it.value().toDouble() ) );
2224 QDomElement elem = createFeatureGML(
2225 &feature,
nullptr, infoDocument, layerCrs, mapSettings,
typeName,
false, gmlVersion,
nullptr
2227 layerElement.appendChild( elem );
2231 const auto values = identifyResult.
results();
2232 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
2234 QVariant value = it.value();
2235 if ( value.userType() == QMetaType::Type::Bool && !value.toBool() )
2241 if ( value.userType() == QMetaType::Type::QString )
2252 for (
const QgsFeature &feature : storeFeatures )
2254 QDomElement elem = createFeatureGML(
2255 &feature,
nullptr, infoDocument, layerCrs, mapSettings,
typeName,
false, gmlVersion,
nullptr
2257 layerElement.appendChild( elem );
2267 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
2269 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2270 attributeElement.setAttribute( QStringLiteral(
"name" ), layer->
bandName( it.key() ) );
2275 value = QString::number( it.value().toDouble() );
2278 attributeElement.setAttribute( QStringLiteral(
"value" ), value );
2279 layerElement.appendChild( attributeElement );
2284 const auto values = identifyResult.
results();
2285 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
2287 QVariant value = it.value();
2288 if ( value.userType() == QMetaType::Type::Bool && !value.toBool() )
2294 if ( value.userType() == QMetaType::Type::QString )
2304 for (
const QgsFeature &feature : storeFeatures )
2306 for (
const auto &fld : feature.fields() )
2308 const auto val { feature.
attribute( fld.name() ) };
2309 if ( val.isValid() )
2311 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2312 attributeElement.setAttribute( QStringLiteral(
"name" ), fld.name() );
2313 attributeElement.setAttribute( QStringLiteral(
"value" ), val.toString() );
2314 layerElement.appendChild( attributeElement );
2325 QDomElement maptipElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2326 maptipElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"maptip" ) );
2330 context.appendScope( scope );
2332 layerElement.appendChild( maptipElem );
2338 bool QgsRenderer::testFilterStringSafety(
const QString &filter )
const
2341 if ( filter.contains( QLatin1String(
";" ) ) )
2346 QStringList tokens = filter.split(
' ', Qt::SkipEmptyParts );
2347 groupStringList( tokens, QStringLiteral(
"'" ) );
2348 groupStringList( tokens, QStringLiteral(
"\"" ) );
2350 for (
auto tokenIt = tokens.constBegin(); tokenIt != tokens.constEnd(); ++tokenIt )
2353 if ( tokenIt->compare( QLatin1String(
"," ) ) == 0
2354 || tokenIt->compare( QLatin1String(
"(" ) ) == 0
2355 || tokenIt->compare( QLatin1String(
")" ) ) == 0
2356 || tokenIt->compare( QLatin1String(
"=" ) ) == 0
2357 || tokenIt->compare( QLatin1String(
"!=" ) ) == 0
2358 || tokenIt->compare( QLatin1String(
"<" ) ) == 0
2359 || tokenIt->compare( QLatin1String(
"<=" ) ) == 0
2360 || tokenIt->compare( QLatin1String(
">" ) ) == 0
2361 || tokenIt->compare( QLatin1String(
">=" ) ) == 0
2362 || tokenIt->compare( QLatin1String(
"%" ) ) == 0
2363 || tokenIt->compare( QLatin1String(
"IS" ), Qt::CaseInsensitive ) == 0
2364 || tokenIt->compare( QLatin1String(
"NOT" ), Qt::CaseInsensitive ) == 0
2365 || tokenIt->compare( QLatin1String(
"NULL" ), Qt::CaseInsensitive ) == 0
2366 || tokenIt->compare( QLatin1String(
"AND" ), Qt::CaseInsensitive ) == 0
2367 || tokenIt->compare( QLatin1String(
"OR" ), Qt::CaseInsensitive ) == 0
2368 || tokenIt->compare( QLatin1String(
"IN" ), Qt::CaseInsensitive ) == 0
2369 || tokenIt->compare( QLatin1String(
"LIKE" ), Qt::CaseInsensitive ) == 0
2370 || tokenIt->compare( QLatin1String(
"ILIKE" ), Qt::CaseInsensitive ) == 0
2371 || tokenIt->compare( QLatin1String(
"DMETAPHONE" ), Qt::CaseInsensitive ) == 0
2372 || tokenIt->compare( QLatin1String(
"SOUNDEX" ), Qt::CaseInsensitive ) == 0
2380 ( void ) tokenIt->toDouble( &isNumeric );
2389 if ( *tokenIt == QLatin1String(
"''" ) )
2395 if ( tokenIt->size() > 2
2396 && ( *tokenIt )[0] == QChar(
'\'' )
2397 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'\'' )
2398 && ( *tokenIt )[1] != QChar(
'\'' )
2399 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'\'' ) )
2405 if ( tokenIt->size() > 2
2406 && ( *tokenIt )[0] == QChar(
'"' )
2407 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'"' )
2408 && ( *tokenIt )[1] != QChar(
'"' )
2409 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'"' ) )
2420 void QgsRenderer::groupStringList( QStringList &list,
const QString &groupString )
2423 bool groupActive =
false;
2424 int startGroup = -1;
2425 QString concatString;
2427 for (
int i = 0; i < list.size(); ++i )
2429 QString &str = list[i];
2430 if ( str.startsWith( groupString ) )
2434 concatString.clear();
2439 if ( i != startGroup )
2441 concatString.append(
" " );
2443 concatString.append( str );
2446 if ( str.endsWith( groupString ) )
2449 groupActive =
false;
2451 if ( startGroup != -1 )
2453 list[startGroup] = concatString;
2454 for (
int j = startGroup + 1; j <= endGroup; ++j )
2456 list.removeAt( startGroup + 1 );
2461 concatString.clear();
2467 void QgsRenderer::convertFeatureInfoToSia2045( QDomDocument &doc )
const
2469 QDomDocument SIAInfoDoc;
2470 QDomElement infoDocElement = doc.documentElement();
2471 QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement,
false ).toElement();
2472 SIAInfoDoc.appendChild( SIAInfoDocElement );
2474 QString currentAttributeName;
2475 QString currentAttributeValue;
2476 QDomElement currentAttributeElem;
2477 QString currentLayerName;
2478 QDomElement currentLayerElem;
2479 QDomNodeList layerNodeList = infoDocElement.elementsByTagName( QStringLiteral(
"Layer" ) );
2480 for (
int i = 0; i < layerNodeList.size(); ++i )
2482 currentLayerElem = layerNodeList.at( i ).toElement();
2483 currentLayerName = currentLayerElem.attribute( QStringLiteral(
"name" ) );
2485 QDomElement currentFeatureElem;
2487 QDomNodeList featureList = currentLayerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2488 if ( featureList.isEmpty() )
2491 QDomNodeList attributeList = currentLayerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2492 QDomElement rasterLayerElem;
2493 if ( !attributeList.isEmpty() )
2495 rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
2497 for (
int j = 0; j < attributeList.size(); ++j )
2499 currentAttributeElem = attributeList.at( j ).toElement();
2500 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
2501 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
2502 QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2503 QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2504 outAttributeElem.appendChild( outAttributeText );
2505 rasterLayerElem.appendChild( outAttributeElem );
2507 if ( !attributeList.isEmpty() )
2509 SIAInfoDocElement.appendChild( rasterLayerElem );
2515 QSet<QString> layerPropertyAttributes;
2516 QString currentLayerId = currentLayerElem.attribute( QStringLiteral(
"id" ) );
2517 if ( !currentLayerId.isEmpty() )
2522 QString WMSPropertyAttributesString = currentLayer->
customProperty( QStringLiteral(
"WMSPropertyAttributes" ) ).toString();
2523 if ( !WMSPropertyAttributesString.isEmpty() )
2525 QStringList propertyList = WMSPropertyAttributesString.split( QStringLiteral(
"//" ) );
2526 for (
auto propertyIt = propertyList.constBegin(); propertyIt != propertyList.constEnd(); ++propertyIt )
2528 layerPropertyAttributes.insert( *propertyIt );
2534 QDomElement propertyRefChild;
2535 for (
int j = 0; j < featureList.size(); ++j )
2537 QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
2538 currentFeatureElem = featureList.at( j ).toElement();
2539 QDomNodeList attributeList = currentFeatureElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2541 for (
int k = 0; k < attributeList.size(); ++k )
2543 currentAttributeElem = attributeList.at( k ).toElement();
2544 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
2545 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
2546 if ( layerPropertyAttributes.contains( currentAttributeName ) )
2548 QDomElement propertyElem = SIAInfoDoc.createElement( QStringLiteral(
"property" ) );
2549 QDomElement identifierElem = SIAInfoDoc.createElement( QStringLiteral(
"identifier" ) );
2550 QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
2551 identifierElem.appendChild( identifierText );
2552 QDomElement valueElem = SIAInfoDoc.createElement( QStringLiteral(
"value" ) );
2553 QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
2554 valueElem.appendChild( valueText );
2555 propertyElem.appendChild( identifierElem );
2556 propertyElem.appendChild( valueElem );
2557 if ( propertyRefChild.isNull() )
2559 SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
2560 propertyRefChild = propertyElem;
2564 SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
2569 QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2570 QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2571 SIAAttributeElem.appendChild( SIAAttributeText );
2572 SIAFeatureElem.appendChild( SIAAttributeElem );
2575 SIAInfoDocElement.appendChild( SIAFeatureElem );
2582 QByteArray QgsRenderer::convertFeatureInfoToHtml(
const QDomDocument &doc )
const
2585 QString featureInfoString = QStringLiteral(
" <!DOCTYPE html>" );
2588 featureInfoString.append( QStringLiteral( R
"HTML(
2591 <title>Information</title>
2592 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2595 font-family: "Open Sans", "Calluna Sans", "Gill Sans MT", "Calibri", "Trebuchet MS", sans-serif;
2602 border: 1px solid black;
2603 border-collapse: collapse;
2624 const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2627 for (
int i = 0; i < layerList.size(); ++i )
2629 const QDomElement layerElem = layerList.at( i ).toElement();
2632 const QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2633 const QDomElement currentFeatureElement;
2635 if ( !featureNodeList.isEmpty() )
2639 const QString featureInfoLayerTitleString = QStringLiteral(
" <div class='layer-title'>%1</div>" ).arg( layerElem.attribute( QStringLiteral(
"title" ) ).toHtmlEscaped() );
2640 featureInfoString.append( featureInfoLayerTitleString );
2643 for (
int j = 0; j < featureNodeList.size(); ++j )
2645 const QDomElement featureElement = featureNodeList.at( j ).toElement();
2648 featureInfoString.append( QStringLiteral( R
"HTML(
2653 const QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2654 for (
int k = 0; k < attributeNodeList.size(); ++k )
2656 const QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2657 const QString name = attributeElement.attribute( QStringLiteral(
"name" ) ).toHtmlEscaped();
2658 QString value = attributeElement.attribute( QStringLiteral(
"value" ) );
2659 if ( name != QLatin1String(
"maptip" ) )
2661 value = value.toHtmlEscaped();
2666 const QString featureInfoAttributeString = QStringLiteral( R
"HTML(
2671 .arg( name, value );
2673 featureInfoString.append( featureInfoAttributeString );
2675 else if ( name == QLatin1String(
"maptip" ) )
2677 featureInfoString.append( QStringLiteral( R
"HTML(
2685 featureInfoString.append( QStringLiteral( R
"HTML(
2692 const QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2695 if ( !attributeNodeList.isEmpty() )
2699 const QString featureInfoLayerTitleString = QStringLiteral(
" <div class='layer-title'>%1</div>" ).arg( layerElem.attribute( QStringLiteral(
"title" ) ).toHtmlEscaped() );
2700 featureInfoString.append( featureInfoLayerTitleString );
2702 featureInfoString.append( QStringLiteral( R
"HTML(
2706 for (
int j = 0; j < attributeNodeList.size(); ++j )
2708 const QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2709 const QString name = attributeElement.attribute( QStringLiteral(
"name" ) ).toHtmlEscaped();
2710 QString value = attributeElement.attribute( QStringLiteral(
"value" ) );
2711 if ( value.isEmpty() )
2713 value = QStringLiteral(
"no data" );
2715 if ( name != QLatin1String(
"maptip" ) )
2717 value = value.toHtmlEscaped();
2722 const QString featureInfoAttributeString = QStringLiteral( R
"HTML(
2727 .arg( name, value );
2730 featureInfoString.append( featureInfoAttributeString );
2732 else if ( name == QLatin1String(
"maptip" ) )
2734 featureInfoString.append( QStringLiteral( R
"HTML(
2742 featureInfoString.append( QStringLiteral( R
"HTML(
2752 featureInfoString.append( QStringLiteral( R
"HTML(
2756 return featureInfoString.toUtf8();
2759 QByteArray QgsRenderer::convertFeatureInfoToText(
const QDomDocument &doc )
const
2761 QString featureInfoString;
2764 featureInfoString.append(
"GetFeatureInfo results\n" );
2765 featureInfoString.append(
"\n" );
2767 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2770 for (
int i = 0; i < layerList.size(); ++i )
2772 QDomElement layerElem = layerList.at( i ).toElement();
2774 featureInfoString.append(
"Layer '" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"'\n" );
2777 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2778 QDomElement currentFeatureElement;
2780 if ( !featureNodeList.isEmpty() )
2782 for (
int j = 0; j < featureNodeList.size(); ++j )
2784 QDomElement featureElement = featureNodeList.at( j ).toElement();
2785 featureInfoString.append(
"Feature " + featureElement.attribute( QStringLiteral(
"id" ) ) +
"\n" );
2788 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2789 for (
int k = 0; k < attributeNodeList.size(); ++k )
2791 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2792 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2798 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2799 for (
int j = 0; j < attributeNodeList.size(); ++j )
2801 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2802 QString value = attributeElement.attribute( QStringLiteral(
"value" ) );
2803 if ( value.isEmpty() )
2805 value = QStringLiteral(
"no data" );
2807 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" + value +
"'\n" );
2811 featureInfoString.append(
"\n" );
2814 return featureInfoString.toUtf8();
2817 QByteArray QgsRenderer::convertFeatureInfoToJson(
const QList<QgsMapLayer *> &layers,
const QDomDocument &doc,
const QgsCoordinateReferenceSystem &destCRS )
const
2820 {
"type",
"FeatureCollection" },
2821 {
"features", json::array() },
2826 const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2827 for (
int i = 0; i < layerList.size(); ++i )
2829 const QDomElement layerElem = layerList.at( i ).toElement();
2830 const QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
2835 if ( mContext.
layerNickname( *l ).compare( layerName ) == 0 )
2851 const QDomNodeList featuresNode = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2852 if ( featuresNode.isEmpty() )
2855 QMap<QgsFeatureId, QString> fidMap;
2856 QMap<QgsFeatureId, QString> fidDisplayNameMap;
2858 for (
int j = 0; j < featuresNode.size(); ++j )
2860 const QDomElement featureNode = featuresNode.at( j ).toElement();
2861 const QString fid = featureNode.attribute( QStringLiteral(
"id" ) );
2864 if ( expression.isEmpty() )
2866 feature = vl->
getFeature( fid.toLongLong() );
2875 fidMap.insert( feature.
id(), fid );
2880 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
2881 for (
int k = 0; k < attrs.count(); k++ )
2883 const QDomElement elm = attrs.at( k ).toElement();
2884 if ( elm.attribute( QStringLiteral(
"name" ) ).compare(
"geometry" ) == 0 )
2886 wkt = elm.attribute(
"value" );
2891 if ( !wkt.isEmpty() )
2899 if ( withDisplayName )
2901 QString displayName;
2902 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
2903 for (
int k = 0; k < attrs.count(); k++ )
2905 const QDomElement elm = attrs.at( k ).toElement();
2906 if ( elm.attribute( QStringLiteral(
"name" ) ).compare(
"displayName" ) == 0 )
2908 displayName = elm.attribute(
"value" );
2912 fidDisplayNameMap.insert( feature.
id(), displayName );
2915 features << feature;
2918 if ( !attributes.isEmpty() )
2921 const QDomNodeList attributesNode = featureNode.elementsByTagName( QStringLiteral(
"Attribute" ) );
2922 for (
int k = 0; k < attributesNode.size(); ++k )
2924 const QDomElement attributeElement = attributesNode.at( k ).toElement();
2925 const QString fieldName = attributeElement.
attribute( QStringLiteral(
"name" ) );
2926 attributes << feature.fieldNameIndex( fieldName );
2932 exporter.setAttributeDisplayName(
true );
2933 exporter.setAttributes( attributes );
2934 exporter.setIncludeGeometry( withGeometry );
2935 exporter.setTransformGeometries(
false );
2939 for (
const auto &feature : std::as_const( features ) )
2941 const QString
id = QStringLiteral(
"%1.%2" ).arg( layerName ).arg( fidMap.value( feature.id() ) );
2942 QVariantMap extraProperties;
2943 if ( withDisplayName )
2945 extraProperties.insert( QStringLiteral(
"display_name" ), fidDisplayNameMap.value( feature.id() ) );
2947 json[
"features"].push_back( exporter.exportFeatureToJsonObject( feature, extraProperties,
id ) );
2952 auto properties = json::object();
2953 const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2954 for (
int j = 0; j < attributesNode.size(); ++j )
2956 const QDomElement attrElmt = attributesNode.at( j ).toElement();
2957 const QString name = attrElmt.attribute( QStringLiteral(
"name" ) );
2959 QString value = attrElmt.attribute( QStringLiteral(
"value" ) );
2960 if ( value.isEmpty() )
2962 value = QStringLiteral(
"null" );
2965 properties[name.toStdString()] = value.toStdString();
2968 json[
"features"].push_back(
2969 { {
"type",
"Feature" },
2970 {
"id", layerName.toStdString() },
2971 {
"properties", properties }
2978 return QByteArray::fromStdString( json.dump( 2 ) );
2980 return QByteArray::fromStdString( json.dump() );
2984 QDomElement QgsRenderer::createFeatureGML(
2993 QStringList *attributes
2997 QDomElement typeNameElement = doc.createElement(
"qgs:" +
typeName );
3004 typeNameElement.setAttribute( QStringLiteral(
"fid" ), QStringLiteral(
"%1.%2" ).arg(
typeName, fid ) );
3007 if ( layer && layer->
crs() !=
crs )
3041 QDomElement bbElem = doc.createElement( QStringLiteral(
"gml:boundedBy" ) );
3042 QDomElement boxElem;
3054 boxElem.setAttribute( QStringLiteral(
"srsName" ),
crs.
authid() );
3056 bbElem.appendChild( boxElem );
3057 typeNameElement.appendChild( bbElem );
3062 findAttributeInTree = [&findAttributeInTree, &layer](
const QString &attributeName,
const QgsAttributeEditorElement *group ) ->
bool {
3066 const QList<QgsAttributeEditorElement *> children = container->
children();
3069 switch ( child->type() )
3073 if ( findAttributeInTree( attributeName, child ) )
3081 if ( child->name() == attributeName )
3090 if ( relationEditor )
3093 if ( relation.referencedLayer() == layer )
3096 for (
const auto &idx : std::as_const( referencedFields ) )
3099 if ( f.name() == attributeName )
3105 else if ( relation.referencingLayer() == layer )
3107 const QgsAttributeList &referencingFields { relation.referencingFields() };
3108 for (
const auto &idx : std::as_const( referencingFields ) )
3111 if ( f.name() == attributeName )
3137 QDomElement geomElem = doc.createElement( QStringLiteral(
"qgs:geometry" ) );
3138 QDomElement gmlElem;
3148 if ( !gmlElem.isNull() )
3152 gmlElem.setAttribute( QStringLiteral(
"srsName" ),
crs.
authid() );
3154 geomElem.appendChild( gmlElem );
3155 typeNameElement.appendChild( geomElem );
3162 for (
int i = 0; i < fields.
count(); ++i )
3164 QString attributeName = fields.
at( i ).
name();
3171 if ( attributes && !attributes->contains( attributeName ) )
3176 if ( honorFormConfig )
3179 if ( !editorContainer || !findAttributeInTree( attributeName, editorContainer ) )
3185 QDomElement fieldElem = doc.createElement(
"qgs:" + attributeName.replace(
' ',
'_' ) );
3186 QString fieldTextString = featureAttributes.at( i ).toString();
3191 QDomText fieldText = doc.createTextNode( fieldTextString );
3192 fieldElem.appendChild( fieldText );
3193 typeNameElement.appendChild( fieldElem );
3204 QDomElement fieldElem = doc.createElement( QStringLiteral(
"qgs:maptip" ) );
3205 QDomText maptipText = doc.createTextNode( fieldTextString );
3206 fieldElem.appendChild( maptipText );
3207 typeNameElement.appendChild( fieldElem );
3211 return typeNameElement;
3214 QString QgsRenderer::replaceValueMapAndRelation(
QgsVectorLayer *vl,
int idx,
const QVariant &attributeVal )
3218 QString value( fieldFormatter->
representValue( vl, idx, setup.
config(), QVariant(), attributeVal ) );
3220 if ( setup.
config().value( QStringLiteral(
"AllowMulti" ) ).toBool() && value.startsWith( QLatin1Char(
'{' ) ) && value.endsWith( QLatin1Char(
'}' ) ) )
3222 value = value.mid( 1, value.size() - 2 );
3234 double mapUnitTolerance = 0.0;
3244 mapUnitTolerance = mapSettings.
extent().
width() / 400.0;
3256 mapUnitTolerance = mapSettings.
extent().
width() / 200.0;
3268 mapUnitTolerance = mapSettings.
extent().
width() / 100.0;
3275 QgsRectangle mapRectangle( infoPoint.
x() - mapUnitTolerance, infoPoint.
y() - mapUnitTolerance, infoPoint.
x() + mapUnitTolerance, infoPoint.
y() + mapUnitTolerance );
3279 QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
3281 QList<QgsMapLayer *> highlightLayers;
3284 QString
crs = mWmsParameters.
crs();
3285 for (
const QgsWmsParametersHighlightLayer ¶m : params )
3288 QDomDocument sldDoc;
3292 if ( !sldDoc.setContent( param.mSld,
true, &errorMsg, &errorLine, &errorColumn ) )
3299 std::unique_ptr<QgsFeatureRenderer> renderer;
3300 QDomElement el = sldDoc.documentElement();
3311 if ( !param.mLabel.isEmpty() )
3313 url +=
"&field=label:string";
3318 auto layer = std::make_unique<QgsVectorLayer>( url, param.mName, QLatin1String(
"memory" ), options );
3326 if ( !param.mLabel.isEmpty() )
3328 fet.setAttribute( 0, param.mLabel );
3336 palSettings.
dist = param.mLabelDistance;
3345 switch ( param.mGeom.type() )
3358 QVariant x( pt.
x() );
3361 QVariant y( pt.
y() );
3378 QVariant x( pt.
x() );
3382 QVariant y( pt.
y() );
3386 QVariant hali(
"Center" );
3390 QVariant vali(
"Half" );
3405 if ( param.mColor.isValid() )
3407 textFormat.
setColor( param.mColor );
3410 if ( param.mSize > 0 )
3412 textFormat.
setSize( param.mSize );
3420 if ( !param.mFont.isEmpty() )
3422 textFormat.
setFont( param.mFont );
3425 if ( param.mBufferColor.isValid() )
3427 bufferSettings.
setColor( param.mBufferColor );
3430 if ( param.mBufferSize > 0 )
3433 bufferSettings.
setSize(
static_cast<double>( param.mBufferSize ) );
3443 fet.setGeometry( param.mGeom );
3452 highlightLayers.append( layer.release() );
3456 mTemporaryLayers.append( highlightLayers );
3457 return highlightLayers;
3460 void QgsRenderer::removeTemporaryLayers()
3462 qDeleteAll( mTemporaryLayers );
3463 mTemporaryLayers.clear();
3466 QPainter *QgsRenderer::layersRendering(
const QgsMapSettings &mapSettings, QImage *image )
const
3468 QPainter *painter =
nullptr;
3472#ifdef HAVE_SERVER_PYTHON_PLUGINS
3473 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
3478 renderJob.render( mapSettings, image, mContext.
socketFeedback() );
3479 painter = renderJob.takePainter();
3481 if ( !renderJob.errors().isEmpty() )
3485 QString layerWMSName;
3492 QString errorMessage = QStringLiteral(
"Rendering error : '%1'" ).arg( e.
message );
3493 if ( !layerWMSName.isEmpty() )
3495 errorMessage = QStringLiteral(
"Rendering error : '%1' in layer '%2'" ).arg( e.
message, layerWMSName );
3503 void QgsRenderer::setLayerOpacity(
QgsMapLayer *layer,
int opacity )
const
3505 if ( opacity >= 0 && opacity <= 255 )
3507 switch ( layer->
type() )
3526 rasterRenderer->
setOpacity( opacity / 255. );
3548 void QgsRenderer::setLayerFilter(
QgsMapLayer *layer,
const QList<QgsWmsParametersFilter> &filters )
3552 QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( layer );
3553 QStringList expList;
3554 for (
const QgsWmsParametersFilter &filter : filters )
3559 QDomDocument filterXml;
3561 if ( !filterXml.setContent( filter.mFilter,
true, &errorMsg ) )
3565 QDomElement filterElem = filterXml.firstChildElement();
3570 expList << filterExp->dump();
3576 if ( !testFilterStringSafety( filter.mFilter ) )
3578 throw QgsSecurityException( QStringLiteral(
"The filter string %1"
3579 " has been rejected because of security reasons."
3580 " Note: Text strings have to be enclosed in single or double quotes."
3581 " A space between each word / special character is mandatory."
3582 " Allowed Keywords and special characters are"
3583 " IS,NOT,NULL,AND,OR,IN,=,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX%2."
3584 " Not allowed are semicolons in the filter expression." )
3586 filter.mFilter, mContext.
settings().
allowedExtraSqlTokens().isEmpty() ? QString() : mContext.settings().allowedExtraSqlTokens().join(
',' ).prepend(
',' )
3590 QString newSubsetString = filter.mFilter;
3593 newSubsetString.prepend(
") AND (" );
3594 newSubsetString.append(
")" );
3595 newSubsetString.prepend( filteredLayer->
subsetString() );
3596 newSubsetString.prepend(
"(" );
3606 expList.append( dimensionFilter( filteredLayer ) );
3610 if ( expList.size() == 1 )
3614 else if ( expList.size() > 1 )
3616 exp = QStringLiteral(
"( %1 )" ).arg( expList.join( QLatin1String(
" ) AND ( " ) ) );
3618 if ( !exp.isEmpty() )
3620 auto expression = std::make_unique<QgsExpression>( exp );
3623 mFeatureFilter.
setFilter( filteredLayer, *expression );
3629 QStringList QgsRenderer::dimensionFilter(
QgsVectorLayer *layer )
const
3631 QStringList expList;
3634 const QList<QgsMapLayerServerProperties::WmsDimensionInfo> wmsDims = serverProperties->
wmsDimensions();
3635 if ( wmsDims.isEmpty() )
3650 if ( fieldIndex == -1 )
3655 int endFieldIndex = -1;
3656 if ( !dim.endFieldName.isEmpty() )
3658 endFieldIndex = layer->
fields().
indexOf( dim.endFieldName );
3659 if ( endFieldIndex == -1 )
3665 if ( !dimParamValues.contains( dim.name.toUpper() ) )
3669 if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::AllValues )
3673 else if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::ReferenceValue )
3675 defValue = dim.referenceValue;
3680 QSet<QVariant> uniqueValues = layer->
uniqueValues( fieldIndex );
3681 if ( endFieldIndex != -1 )
3683 uniqueValues.unite( layer->
uniqueValues( endFieldIndex ) );
3686 QList<QVariant> values = qgis::setToList( uniqueValues );
3687 std::sort( values.begin(), values.end() );
3688 if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::MinValue )
3690 defValue = values.first();
3692 else if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::MaxValue )
3694 defValue = values.last();
3698 if ( endFieldIndex == -1 )
3704 QStringList expElems;
3709 expList << expElems.join(
' ' );
3717 QString dimParamValue = dimParamValues[dim.name.toUpper()];
3719 QStringList dimExplist;
3721 QStringList dimValues = dimParamValue.split(
',' );
3722 for (
int i = 0; i < dimValues.size(); ++i )
3724 QString dimValue = dimValues[i];
3726 if ( dimValue.size() > 1 )
3728 dimValue = dimValue.trimmed();
3731 if ( dimValue.contains(
'/' ) )
3733 QStringList rangeValues = dimValue.split(
'/' );
3735 if ( rangeValues.size() != 2 )
3740 QVariant rangeMin = QVariant( rangeValues[0] );
3741 QVariant rangeMax = QVariant( rangeValues[1] );
3752 QStringList expElems;
3753 if ( endFieldIndex == -1 )
3773 << QStringLiteral(
")" );
3775 dimExplist << expElems.join(
' ' );
3779 QVariant dimVariant = QVariant( dimValue );
3785 if ( endFieldIndex == -1 )
3794 QStringList expElems;
3799 dimExplist << expElems.join(
' ' );
3804 if ( dimExplist.size() == 1 )
3806 expList << dimExplist;
3808 else if ( dimExplist.size() > 1 )
3810 expList << QStringLiteral(
"( %1 )" ).arg( dimExplist.join( QLatin1String(
" ) OR ( " ) ) );
3817 void QgsRenderer::setLayerSelection(
QgsMapLayer *layer,
const QStringList &fids )
const
3827 if ( selectedIds.empty() )
3838 void QgsRenderer::setLayerAccessControlFilter(
QgsMapLayer *layer )
const
3840#ifdef HAVE_SERVER_PYTHON_PLUGINS
3858 void QgsRenderer::annotationsRendering( QPainter *painter,
const QgsMapSettings &mapSettings )
const
3861 const QList<QgsAnnotation *> annotations = annotationManager->
annotations();
3871 if ( !annotation || !annotation->isVisible() )
3877 if ( annotation->hasFixedMapPosition() )
3879 QgsPointXY mapPos = annotation->mapPosition();
3880 if ( mapSettings.
destinationCrs() != annotation->mapPositionCrs() )
3885 mapPos = coordTransform.transform( mapPos );
3893 offsetX = devicePos.
x();
3894 offsetY = devicePos.
y();
3898 const QPointF relativePos = annotation->relativePosition();
3899 offsetX = mapSettings.
outputSize().width() * relativePos.x();
3900 offsetY = mapSettings.
outputSize().height() * relativePos.y();
3904 painter->translate( offsetX, offsetY );
3905 annotation->render( renderContext );
3910 QImage *QgsRenderer::scaleImage(
const QImage *image )
const
3915 QImage *scaledImage =
nullptr;
3916 const int width = mWmsParameters.
widthAsInt();
3918 if ( width != image->width() || height != image->height() )
3920 scaledImage =
new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
3926 void QgsRenderer::handlePrintErrors(
const QgsLayout *layout )
const
3932 QList<QgsLayoutItemMap *> mapList;
3935 QList<QgsLayoutItemMap *>::const_iterator mapIt = mapList.constBegin();
3936 for ( ; mapIt != mapList.constEnd(); ++mapIt )
3938 if ( !( *mapIt )->renderingErrors().isEmpty() )
3950 for (
auto layer : layers )
3963 setLayerOpacity( layer, param.
mOpacity );
3970 setLayerSld( layer, mContext.
sld( *layer ) );
3974 setLayerStyle( layer, mContext.
style( *layer ) );
3979 setLayerOpacity( layer, param.
mOpacity );
3984 setLayerFilter( layer, param.
mFilter );
3989 setLayerAccessControlFilter( layer );
3994 setLayerSelection( layer, param.
mSelection );
3999 updateExtent( layer, *settings );
4009 void QgsRenderer::setLayerStyle(
QgsMapLayer *layer,
const QString &style )
const
4011 if ( style.isEmpty() )
4023 void QgsRenderer::setLayerSld(
QgsMapLayer *layer,
const QDomElement &sld )
const
4028 QString sldStyleName =
"__sld_style";
4029 while ( styles.contains( sldStyleName ) )
4031 sldStyleName.append(
'@' );
4044 if ( !mWmsParameters.
bbox().isEmpty() )
4048 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
4049 configureMapSettings( tmp.get(), mapSettings );
Provides global constants and enumerations for use throughout the application.
static QString version()
Version string.
@ MapOrientation
Signifies that the AboveLine and BelowLine flags should respect the map's orientation rather than the...
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
@ Millimeters
Millimeters.
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ DragAndDrop
"Drag and drop" layout. Needs to be configured.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ NoFlags
No flags are set.
@ Warning
Warning message.
@ Info
Information message.
QFlags< LabelLinePlacementFlag > LabelLinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
@ ShowRuleDetails
If set, the rule expression of a rule based renderer legend item will be added to the JSON.
@ IdentifyValue
Numerical values.
@ IdentifyFeature
WMS GML -> feature.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Antialiasing
Use antialiasing while drawing.
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
QFlags< LegendJsonRenderFlag > LegendJsonRenderFlags
static QString geoNone()
Constant that holds the string representation for "No ellipse/No CRS".
RasterIdentifyFormat
Raster identify formats.
@ Feature
WMS GML/JSON -> feature.
@ Value
Numerical pixel value.
@ HideFromWms
Field is not available if layer is served as WMS from QGIS server.
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
@ Reverse
Reverse/inverse transform (from destination to source)
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ RecordProfile
Enable run-time profiling while rendering.
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
Abstract base class for all geometries.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
virtual void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.
Manages storage of a set of QgsAnnotation annotation objects.
QList< QgsAnnotation * > annotations() const
Returns a list of all annotations contained in the manager.
Abstract base class for annotation items which are drawn over a map.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
A container for attribute editors, used to group them visually in the attribute form if it is set to ...
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
An abstract base class for any elements of a drag and drop form.
QString name() const
Returns the name of this element.
This element will load a field's widget onto the form.
This element will load a relation editor onto the form.
const QgsRelation & relation() const
Gets the id of the relation which shall be embedded.
Exception thrown in case of malformed requests.
Represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Qgis::DistanceUnit mapUnits
bool hasAxisInverted() const
Returns whether the axis order is inverted for the CRS compared to the order east/north (longitude/la...
Custom exception class for Coordinate Reference System related exceptions.
A server filter to apply a dimension filter to a request.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
@ FlagHairlineWidthExport
@ FlagNoMText
Export text as TEXT elements. If not set, text will be exported as MTEXT elements.
Defines a QGIS exception class.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString expression() const
Returns the original, unmodified expression string.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString replaceExpressionText(const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea=nullptr)
This function replaces each expression between [% and %] in the string with the result of its evaluat...
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value, QMetaType::Type fieldType=QMetaType::Type::UnknownType)
Create an expression allowing to evaluate if a field is equal to a value.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
QVariant evaluate()
Evaluate the feature and return the result.
bool isValid() const
Checks if this expression is valid.
A filter filter provider grouping several filter providers.
QgsFeatureFilterProviderGroup & addProvider(const QgsFeatureFilterProvider *provider)
Add another filter provider to the group.
void setFilter(const QgsVectorLayer *layer, const QgsExpression &expression)
Set a filter for the given layer.
void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures) const override
Filter the features of the layer.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
static QgsFeatureRenderer * loadSld(const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
Qgis::FeatureRequestFlags flags() const
Returns the flags which affect how features are fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsExpression * filterExpression() const
Returns the filter expression (if set).
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsCoordinateTransformContext transformContext() const
Returns the transform context, for use when a destinationCrs() has been set and reprojection is requi...
const QgsFeatureIds & filterFids() const
Returns the feature IDs that should be fetched.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
A container for features with the same fields and crs.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
Encapsulate a field in an attribute table or data source.
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Qgis::FieldConfigurationFlags configurationFlags
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
Q_INVOKABLE int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
A geometry is the spatial representation of a feature.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
Handles exporting QgsFeature features to GeoJSON features.
static void addCrsInfo(json &value, const QgsCoordinateReferenceSystem &crs)
Add crs information entry in json object regarding old GeoJSON specification format if it differs fro...
void setPlacementFlags(Qgis::LabelLinePlacementFlags flags)
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
void setOverlapHandling(Qgis::LabelOverlapHandling handling)
Sets the technique used to handle overlapping labels.
void setAllowDegradedPlacement(bool allow)
Sets whether labels can be placed in inferior fallback positions if they cannot otherwise be placed.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
void removeChildrenGroupWithoutLayers()
Remove all child group nodes without layers.
Layer tree node points to a map layer.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
An abstract interface for legend items returned from QgsMapLayerLegend implementation.
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
@ RuleKey
Rule key of the node (QString)
virtual QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const
Adds a symbol in base64 string within a JSON object with the key "icon".
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
A model representing the layer tree, including layers and groups of layers.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
QgsLayerTreeModelLegendNode * findLegendNode(const QString &layerId, const QString &ruleKey) const
Searches through the layer tree to find a legend node with a matching layer ID and rule key.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
Namespace with helper functions for layer tree operations.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Used to render QgsLayout as an atlas, by iterating over the features from an associated vector layer.
bool beginRender() override
Called when rendering begins, before iteration commences.
bool setFilterExpression(const QString &expression, QString &errorString)
Sets the expression used for filtering features in the coverage layer.
bool first()
Seeks to the first feature, returning false if no feature was found.
QgsLayout * layout() override
Returns the layout associated with the iterator.
bool enabled() const
Returns whether the atlas generation is enabled.
int count() const override
Returns the number of features to iterate over.
void setFilterFeatures(bool filtered)
Sets whether features should be filtered in the coverage layer.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
int updateFeatures()
Requeries the current atlas coverage layer and applies filtering and sorting.
Handles rendering and exports of layouts to various formats.
ExportResult exportToSvg(const QString &filePath, const QgsLayoutExporter::SvgExportSettings &settings)
Exports the layout as an SVG to the filePath, using the specified export settings.
ExportResult exportToImage(const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings)
Exports the layout to the filePath, using the specified export settings.
ExportResult exportToPdf(const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings)
Exports the layout as a PDF to the filePath, using the specified export settings.
Base class for frame items, which form a layout multiframe item.
A layout multiframe subclass for HTML content.
@ ManualHtml
HTML content is manually set for the item.
@ Url
Using this mode item fetches its content via a url.
A layout item subclass for text labels.
A layout item subclass for map legends.
Layout graphical items for displaying a map.
double scale() const
Returns the map scale.
QList< QgsMapLayer * > layers() const
Returns the stored layer set.
QString id() const
Returns the item's ID name.
Manages storage of a set of layouts.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
double length() const
Returns the length of the measurement.
int pageCount() const
Returns the number of pages in the collection.
Stores information relating to the current rendering settings for a layout.
void setFeatureFilterProvider(QgsFeatureFilterProvider *featureFilterProvider)
Sets feature filter provider to featureFilterProvider.
@ FlagDrawSelection
Draw selection.
@ FlagLosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ FlagDisableTiledRasterLayerRenders
If set, then raster layers will not be drawn as separate tiles. This may improve the appearance in ex...
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
double height() const
Returns the height of the size.
double width() const
Returns the width of the size.
static QVector< double > predefinedScales(const QgsLayout *layout)
Returns a list of predefined scales associated with a layout.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
Item model implementation based on layer tree model for layout legend.
Handles automatic layout and rendering of legends.
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend.
QJsonObject exportLegendToJson(const QgsRenderContext &context)
Renders the legend in a json object.
Q_DECL_DEPRECATED void drawLegend(QPainter *painter)
Draws the legend with given painter.
Stores the appearance and layout settings for legend drawing with QgsLegendRenderer.
Q_DECL_DEPRECATED void setMapScale(double scale)
Sets the legend map scale.
Q_DECL_DEPRECATED void setMapUnitsPerPixel(double mapUnitsPerPixel)
Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings.
void setJsonRenderFlags(const Qgis::LegendJsonRenderFlags &jsonRenderFlags)
Sets the the JSON export flags to jsonRenderFlags.
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Manages QGIS Server properties for a map layer.
QStringList styles() const
Returns list of all defined style names.
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
bool addStyleFromLayer(const QString &name)
Add style by cloning the current one.
Base class for all map layer types.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
virtual QgsRectangle extent() const
Returns the extent of the layer.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsCoordinateReferenceSystem crs
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
@ Identifiable
If the layer is identifiable using the identify map tool and as a WMS layer.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Contains configuration for rendering maps.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
void setSelectionColor(const QColor &color)
Sets the color that is used for drawing of selected vector features.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
double scale() const
Returns the calculated map scale.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
void setScaleMethod(Qgis::ScaleCalculationMethod method)
Sets the method to use for scale calculations for the map.
void setDpiTarget(double dpi)
Sets the target dpi (dots per inch) to be taken into consideration when rendering.
void setOutputDpi(double dpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
const QgsMapToPixel & mapToPixel() const
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Sets the coordinates of the rectangle which should be rendered.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QList< QgsMapThemeCollection::MapThemeLayerRecord > layerRecords() const
Returns a list of records for all visible layer belonging to the theme.
QgsMapThemeCollection::MapThemeRecord mapThemeState(const QString &name) const
Returns the recorded state of a map theme.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
static void applyAccessControlLayerFilters(const QgsAccessControl *accessControl, QgsMapLayer *mapLayer, QHash< QgsMapLayer *, QString > &originalLayerFilters)
Apply filter from AccessControl.
static QDomElement rectangleToGMLEnvelope(const QgsRectangle *env, QDomDocument &doc, int precision=17)
Exports the rectangle to GML3 Envelope.
static QDomElement geometryToGML(const QgsGeometry &geometry, QDomDocument &doc, QgsOgcUtils::GMLVersion gmlVersion, const QString &srsName, bool invertAxisOrientation, const QString &gmlIdBase, int precision=17)
Exports the geometry to GML.
static QgsExpression * expressionFromOgcFilter(const QDomElement &element, QgsVectorLayer *layer=nullptr)
Parse XML with OGC filter into QGIS expression.
static QDomElement rectangleToGMLBox(const QgsRectangle *box, QDomDocument &doc, int precision=17)
Exports the rectangle to GML2 Box.
Contains settings for how a map layer will be labeled.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
Qgis::LabelPlacement placement
Label placement mode.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
int priority
Label priority.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
double dist
Distance from feature to the label.
Property
Data definable properties.
@ PositionX
X-coordinate data defined label position.
@ LabelRotation
Label rotation.
@ PositionY
Y-coordinate data defined label position.
@ Vali
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
@ Hali
Horizontal alignment for data defined label position (Left, Center, Right)
QString fieldName
Name of field (or an expression) to use for label text.
void setY(double y)
Sets the y value of the point.
void setX(double x)
Sets the x value of the point.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
QgsPrintLayout * clone() const override
Creates a clone of the layout.
Describes the version of a project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsMapThemeCollection * mapThemeCollection
QgsAnnotationManager * annotationManager()
Returns pointer to the project's annotation manager.
QgsProjectMetadata metadata
QgsCoordinateTransformContext transformContext
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns project's global labeling engine settings.
Qgis::ScaleCalculationMethod scaleMethod
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
virtual QgsRasterIdentifyResult identify(const QgsPointXY &point, Qgis::RasterIdentifyFormat format, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Identify raster value(s) found on the point position.
Raster identify results container.
bool isValid() const
Returns true if valid.
QMap< int, QVariant > results() const
Returns the identify results.
virtual Qgis::RasterInterfaceCapabilities capabilities() const
Returns the capabilities supported by the interface.
Represents a raster layer.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Raster renderer pipe that applies colors to a raster.
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void invert()
Swap x/y coordinates in the rectangle.
Represents a relationship between two vector layers.
QgsAttributeList referencedFields() const
Returns a list of attributes used to form the referenced fields (most likely primary key) on the refe...
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
void setDistanceArea(const QgsDistanceArea &distanceArea)
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly during rendering to check if rendering should ...
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
Scoped object for temporary scaling of a QgsRenderContext for millimeter based rendering.
Bad request error API exception.
static QgsDateTimeRange parseTemporalDateTimeInterval(const QString &interval)
Parses a datetime interval and returns a QgsDateTimeRange.
Exception base class for server exceptions.
static QString getExpressionFromServerFid(const QString &serverFid, const QgsVectorDataProvider *provider)
Returns the expression feature id based on primary keys.
static QgsFeatureRequest updateFeatureRequestFromServerFids(QgsFeatureRequest &featureRequest, const QStringList &serverFids, const QgsVectorDataProvider *provider)
Returns the feature request based on feature ids build with primary keys.
static QString getServerFid(const QgsFeature &feature, const QgsAttributeList &pkAttributes)
Returns the feature id based on primary keys.
static QString wmsFeatureInfoSchema(const QgsProject &project)
Returns the schema URL for XML GetFeatureInfo request.
static bool wmsInfoFormatSia2045(const QgsProject &project)
Returns if the info format is SIA20145.
static QString wmsFeatureInfoDocumentElementNs(const QgsProject &project)
Returns the document element namespace for XML GetFeatureInfo request.
static QStringList wmsRestrictedComposers(const QgsProject &project)
Returns the restricted composer list.
static bool wmsFeatureInfoSegmentizeWktGeometry(const QgsProject &project)
Returns if the geometry has to be segmentize in GetFeatureInfo request.
static bool wmsFeatureInfoUseAttributeFormSettings(const QgsProject &project)
Returns if feature form settings should be considered for the format of the feature info response.
static QHash< QString, QString > wmsFeatureInfoLayerAliasMap(const QgsProject &project)
Returns the mapping between layer name and wms layer name for GetFeatureInfo request.
static bool wmsFeatureInfoAddWktGeometry(const QgsProject &project)
Returns if the geometry is displayed as Well Known Text in GetFeatureInfo request.
static double wmsDefaultMapUnitsPerMm(const QgsProject &project)
Returns the default number of map units per millimeters in case of the scale is not given.
static QString wmsFeatureInfoDocumentElement(const QgsProject &project)
Returns the document element name for XML GetFeatureInfo request.
static int wmsMaxAtlasFeatures(const QgsProject &project)
Returns the maximum number of atlas features which can be printed in a request.
int maxThreads() const
Returns the maximum number of threads to use.
bool logProfile() const
Returns true if profile information has to be added to the logs, default value is false.
QStringList allowedExtraSqlTokens() const
Returns the list of strings that represent the allowed extra SQL tokens accepted as components of a f...
bool parallelRendering() const
Returns parallel rendering setting.
const QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > wmsDimensions() const
Returns the QGIS Server WMS Dimension list.
Contains utility functions for working with symbols and symbol layers.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
Abstract base class for all rendered symbols.
@ Hidden
Hide task from GUI.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
Container for settings relating to a text buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Base class for vector data providers.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features to the sink.
Basic implementation of the labeling interface.
Represents a vector layer which manages a vector based dataset.
void setLabeling(QgsAbstractVectorLayerLabeling *labeling)
Sets labeling configuration.
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider,...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
void setLabelsEnabled(bool enabled)
Sets whether labels should be enabled for the layer.
Q_INVOKABLE void selectByExpression(const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
Selects matching features using an expression.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
void setRenderer(QgsFeatureRenderer *r)
Sets the feature renderer which will be invoked to represent this layer in 2D map views.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QString displayExpression
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsEditorWidgetSetup editorWidgetSetup(int index) const
Returns the editor widget setup for the field at the specified index.
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
Selects matching features using a list of feature IDs.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
QgsAttributeList primaryKeyAttributes() const
Returns the list of attributes which make up the layer's primary keys.
QgsEditFormConfig editFormConfig
Q_INVOKABLE QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
Implements a map layer that is dedicated to rendering of vector tiles.
static QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
Implementation of legend node interface for displaying WMS legend entries.
Exception thrown in case of malformed request.
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
QHash< QgsVectorLayer *, SymbolSet > HitTest
QByteArray getPrint()
Returns printed page as binary.
HitTest symbols()
Returns the hit test according to the current context.
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
QSet< QString > SymbolSet
void configureLayers(QList< QgsMapLayer * > &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
std::unique_ptr< QgsMapRendererTask > getPdf(const QString &tmpFileName)
Returns a configured pdf export task.
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
std::unique_ptr< QImage > getMap()
Returns the map as an image (or nullptr in case of error).
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model, const Qgis::LegendJsonRenderFlags &jsonRenderFlags=Qgis::LegendJsonRenderFlags())
Returns the map legend as a JSON object.
Exception class for WMS service exceptions.
ExceptionCode
Exception codes as defined in OGC scpecifications for WMS 1.1.1 and WMS 1.3.0.
@ QGIS_InvalidParameterValue
@ QGIS_MissingParameterValue
WMS parameter received from the client.
bool htmlInfoOnlyMapTip() const
Returns true if only maptip information is requested for HTML feature info response.
double dxfScale() const
Returns the DXF SCALE parameter.
bool transparentAsBool() const
Returns TRANSPARENT parameter as a bool or its default value if not defined.
QString x() const
Returns X parameter or an empty string if not defined.
QString formatAsString() const
Returns FORMAT parameter as a string.
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
QgsWmsParametersComposerMap composerMapParameters(int mapId) const
Returns the requested parameters for a composer map parameter.
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
bool withGeometry() const
Returns if the client wants the feature info response with geometry information.
DxfFormatOption
Options for DXF format.
QString pointTolerance() const
Returns FI_POINT_TOLERANCE parameter or an empty string if not defined.
QString filterGeom() const
Returns the filter geometry found in FILTER_GEOM parameter.
QString composerTemplate() const
Returns TEMPLATE parameter or an empty string if not defined.
Format infoFormat() const
Returns infoFormat.
QString y() const
Returns Y parameter or an empty string if not defined.
double dpiAsDouble() const
Returns DPI parameter as an int or its default value if not defined.
void dump() const
Dumps parameters.
int pointToleranceAsInt() const
Returns FI_POINT_TOLERANCE parameter as an integer.
bool withMapTip() const
withMapTip
QString polygonTolerance() const
Returns FI_POLYGON_TOLERANCE parameter or an empty string if not defined.
QString i() const
Returns I parameter or an empty string if not defined.
bool pdfLosslessImageCompression() const
Returns true if images embedded in pdf must be compressed using a lossless algorithm.
int lineToleranceAsInt() const
Returns FI_LINE_TOLERANCE parameter as an integer.
QString lineTolerance() const
Returns FI_LINE_TOLERANCE parameter or an empty string if not defined.
QStringList pdfExportMapThemes() const
Returns map themes for geospatial PDF export.
bool pdfExportMetadata() const
Returns true if metadata shall be added to the pdf.
QString j() const
Returns J parameter or an empty string if not defined.
int xAsInt() const
Returns X parameter as an int or its default value if not defined.
QString bbox() const
Returns BBOX if defined or an empty string.
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
QColor backgroundColorAsColor() const
Returns BGCOLOR parameter as a QColor or its default value if not defined.
Format format() const
Returns format.
QStringList atlasPk() const
Returns the ATLAS_PK parameter.
QList< QgsWmsParametersHighlightLayer > highlightLayersParameters() const
Returns parameters for each highlight layer.
int iAsInt() const
Returns I parameter as an int or its default value if not defined.
bool pdfAppendGeoreference() const
Returns true if georeference info shall be added to the pdf.
int polygonToleranceAsInt() const
Returns FI_POLYGON_TOLERANCE parameter as an integer.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
QString sldBody() const
Returns SLD_body if defined or an empty string.
bool pdfDisableTiledRasterRendering() const
Returns true if rasters shall be untiled in the pdf.
QString layoutParameter(const QString &id, bool &ok) const
Returns a layout parameter thanks to its id.
bool dxfUseLayerTitleAsName() const
Returns the DXF USE_TITLE_AS_LAYERNAME parameter.
bool pdfForceVectorOutput() const
Returns if pdf should be exported as vector.
bool writeGeospatialPdf() const
Returns if a geospatial PDF shall be exported.
bool pdfUseIso32000ExtensionFormatGeoreferencing() const
Returns true, if Iso32000 georeferencing shall be used.
QMap< QString, QString > dimensionValues() const
Returns the dimensions parameter.
bool withDisplayName() const
withDisplayName
int infoFormatVersion() const
Returns the infoFormat version for GML.
QgsLegendSettings legendSettings() const
Returns legend settings.
Qgis::TextRenderFormat pdfTextRenderFormat() const
Returns text render format for pdf export.
QStringList dxfLayerAttributes() const
Returns the DXF LAYERATTRIBUTES parameter.
Qgis::FeatureSymbologyExport dxfMode() const
Returns the DXF MODE parameter.
QString height() const
Returns HEIGHT parameter or an empty string if not defined.
QString crs() const
Returns CRS or an empty string if none is defined.
bool exportLinesWithZeroWidth() const
int featureCountAsInt() const
Returns FEATURE_COUNT as an integer.
int yAsInt() const
Returns Y parameter as an int or its default value if not defined.
QMap< T, QString > formatOptions() const
Returns the format options for an output format.
Format
Output format for the response.
QString width() const
Returns WIDTH parameter or an empty string if not defined.
QStringList filters() const
Returns the list of filters found in FILTER parameter.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
int jAsInt() const
Returns J parameter as an int or its default value if not defined.
QVector< qreal > pdfPredefinedMapScales() const
Returns list of map scales.
bool pdfSimplifyGeometries() const
Returns if geometries shall to be simplified.
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
Rendering context for the WMS renderer.
QSize mapSize(bool aspectRatio=true) const
Returns the size (in pixels) of the map to render, according to width and height WMS parameters as we...
bool isExternalLayer(const QString &name) const
Returns true if the layer is an external layer, false otherwise.
bool isValidGroup(const QString &name) const
Returns true if name is a group.
QStringList flattenedQueryLayers(const QStringList &layerNames) const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
QgsFeedback * socketFeedback() const
Returns the response feedback if any.
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
QgsMapLayer * layer(const QString &nickname) const
Returns the layer corresponding to the nickname, or a nullptr if not found or if the layer do not nee...
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
const QgsServerSettings & settings() const
Returns settings of the server.
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
QList< QgsMapLayer * > layersFromGroup(const QString &nickname) const
Returns the group's layers list corresponding to the nickname, or an empty list if not found.
QgsWmsParameters parameters() const
Returns WMS parameters.
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
QString style(const QgsMapLayer &layer) const
Returns a style's name for a specific layer.
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
double mapTileBuffer(int mapWidth) const
Returns the tile buffer in geographical units for the given map width in pixels.
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration.
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
const QgsProject * project() const
Returns the project.
int precision() const
Returns the precision to use according to the current configuration.
bool renderMapTiles() const
Returns true if WMS requests should use the QgsMapSettings::RenderMapTile flag, so that no visible ar...
RAII class to restore the rendering context configuration on destruction.
Median cut implementation.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define Q_NOWARN_DEPRECATED_POP
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
#define FID_TO_STRING(fid)
QVector< QgsFeatureStore > QgsFeatureStoreList
QList< int > QgsAttributeList
#define QgsDebugMsgLevel(str, level)
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs
QgsAbstractMetadataBase::KeywordMap keywords
Metadata keyword map.
QString creator
Metadata creator tag.
QString author
Metadata author tag.
QString subject
Metadata subject tag.
QString title
Metadata title tag.
QDateTime creationDateTime
Metadata creation datetime.
QString producer
Metadata producer tag.
bool useIso32000ExtensionFormatGeoreferencing
true if ISO32000 extension format georeferencing should be used.
Layers and optional attribute index to split into multiple layers using attribute value as layer name...
Single variable definition for use within a QgsExpressionContextScope.
QPainter * painter
Painter.
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.
Contains settings relating to exporting layouts to raster images.
QList< int > pages
List of specific pages to export, or an empty list to export all pages.
QSize imageSize
Manual size in pixels for output image.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
Contains settings relating to exporting layouts to PDF.
bool useIso32000ExtensionFormatGeoreferencing
true if ISO3200 extension format georeferencing should be used.
bool forceVectorOutput
Set to true to force vector object exports, even when the resultant appearance will differ from the l...
bool rasterizeWholeImage
Set to true to force whole layout to be rasterized while exporting.
QStringList exportThemes
Optional list of map themes to export as Geospatial PDF layer groups.
bool appendGeoreference
Indicates whether PDF export should append georeference data.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
bool writeGeoPdf
true if geospatial PDF files should be created, instead of normal PDF files.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
bool simplifyGeometries
Indicates whether vector geometries should be simplified to avoid redundant extraneous detail,...
Qgis::TextRenderFormat textRenderFormat
Text rendering format, which controls how text should be rendered in the export (e....
Contains settings relating to exporting layouts to SVG.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
Setting to define QGIS Server WMS Dimension.
Setting options for loading vector layers.
QList< QgsWmsParametersLayer > mLayers
QList< QgsWmsParametersHighlightLayer > mHighlightLayers
QList< QgsWmsParametersFilter > mFilter