23#include <nlohmann/json.hpp>
88#include <QTemporaryFile>
90#include <QXmlStreamReader>
92using namespace Qt::StringLiterals;
119 : mContext( context )
121 mProject = mContext.project();
123 mWmsParameters = mContext.parameters();
124 mWmsParameters.dump();
129 removeTemporaryLayers();
135 std::unique_ptr<QgsWmsRestorer> restorer;
136 restorer = std::make_unique<QgsWmsRestorer>( mContext );
139 QList<QgsMapLayer *> layers = mContext.layersToRender();
142 const qreal dpmm = mContext.dotsPerMm();
147 const auto layersToRender = mContext.layersToRender();
148 for (
const auto &layer : std::as_const( layersToRender ) )
151 if ( layer->dataProvider()->name() ==
"wms"_L1 )
155 const auto image { layerNode->getLegendGraphicBlocking() };
156 if ( !image.isNull() )
159 if ( mContext.isValidWidthHeight( image.width(), image.height() ) )
161 const double w = image.width() / dpmm;
162 const double h = image.height() / dpmm;
163 const QSizeF newWmsSize { w, h };
176 if ( !mWmsParameters.bbox().isEmpty() )
180 std::unique_ptr<QImage> tmp( createImage( mContext.mapSize(
false ) ) );
181 configureMapSettings( tmp.get(), mapSettings );
187 context = configureDefaultRenderContext();
191 std::unique_ptr<QImage> image;
192 const QSizeF minSize = renderer.
minimumSize( &context );
193 const QSize size(
static_cast<int>( minSize.width() * dpmm ),
static_cast<int>( minSize.height() * dpmm ) );
194 if ( !mContext.isValidWidthHeight( size.width(), size.height() ) )
198 image.reset( createImage( size ) );
201 QPainter painter( image.get() );
204 if ( painter.renderHints() & QPainter::SmoothPixmapTransform )
206 if ( painter.renderHints() & QPainter::LosslessImageRendering )
216 return image.release();
222 std::unique_ptr<QgsWmsRestorer> restorer;
223 restorer = std::make_unique<QgsWmsRestorer>( mContext );
226 QList<QgsMapLayer *> layers = mContext.layersToRender();
230 const QSize size( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt() );
232 if ( !mContext.isValidWidthHeight( size.width(), size.height() ) )
236 std::unique_ptr<QImage> image( createImage( size ) );
239 const qreal dpmm = mContext.dotsPerMm();
240 std::unique_ptr<QPainter> painter;
241 painter = std::make_unique<QPainter>( image.get() );
242 painter->setRenderHint( QPainter::Antialiasing,
true );
243 painter->scale( dpmm, dpmm );
254 nodeModel.
drawSymbol( settings, &ctx, size.height() / dpmm );
257 return image.release();
263 std::unique_ptr<QgsWmsRestorer> restorer;
264 restorer = std::make_unique<QgsWmsRestorer>( mContext );
267 QList<QgsMapLayer *> layers = mContext.layersToRender();
283 std::unique_ptr<QgsWmsRestorer> restorer;
284 restorer = std::make_unique<QgsWmsRestorer>( mContext );
287 QList<QgsMapLayer *> layers = mContext.layersToRender();
296 QJsonObject jsonSymbol {
legendNode.exportSymbolToJson( settings, renderContext ) };
303 if ( vLayer->renderer() )
307 const QString ruleExp { vLayer->renderer()->legendKeyToExpression( ruleKey, vLayer, ok ) };
310 jsonSymbol[u
"rule"_s] = ruleExp;
319 void QgsRenderer::runHitTest(
const QgsMapSettings &mapSettings, HitTest &hitTest )
const
323 for (
const QString &
id : mapSettings.
layerIds() )
340 runHitTestLayer( vl, usedSymbols, context );
344 void QgsRenderer::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context )
const
346 std::unique_ptr<QgsFeatureRenderer> r( vl->
renderer()->
clone() );
348 r->startRender( context, vl->
fields() );
350 QgsFeatureRequest request( context.
extent() );
352 QgsFeatureIterator fi = vl->
getFeatures( request );
356 if ( moreSymbolsPerFeature )
358 for ( QgsSymbol *s : r->originalSymbolsForFeature( f, context ) )
364 r->stopRender( context );
370 if ( !mContext.isValidWidthHeight() )
376 std::unique_ptr<QgsWmsRestorer> restorer;
377 restorer = std::make_unique<QgsWmsRestorer>( mContext );
382 QList<QgsMapLayer *> layers = mContext.layersToRender();
386 std::unique_ptr<QPainter> painter;
387 std::unique_ptr<QImage> image( createImage( mContext.mapSize() ) );
390 configureMapSettings( image.get(), mapSettings );
397 runHitTest( mapSettings,
symbols );
405 std::unique_ptr<QgsWmsRestorer> restorer;
406 restorer = std::make_unique<QgsWmsRestorer>( mContext );
409 const QString templateName = mWmsParameters.composerTemplate();
410 if ( templateName.isEmpty() )
433 std::unique_ptr<QgsPrintLayout> layout( sourceLayout->
clone() );
437 QStringList atlasPk = mWmsParameters.atlasPk();
438 if ( !atlasPk.isEmpty() )
440 atlas = layout->atlas();
441 if ( !atlas || !atlas->
enabled() )
454 if ( atlasPk.size() == 1 && atlasPk.at( 0 ) ==
"*"_L1 )
458 if ( atlas->
count() > maxAtlasFeatures )
466 if ( pkIndexes.size() == 0 )
468 QgsDebugMsgLevel( u
"Atlas print: layer %1 has no primary key attributes"_s.arg( cLayer->
name() ), 2 );
472 const int pkIndexesSize { std::max<int>( pkIndexes.size(), 1 ) };
474 QStringList pkAttributeNames;
475 for (
int pkIndex : std::as_const( pkIndexes ) )
477 pkAttributeNames.append( cLayer->
fields().
at( pkIndex ).
name() );
480 const int nAtlasFeatures = atlasPk.size() / pkIndexesSize;
481 if ( nAtlasFeatures * pkIndexesSize != atlasPk.size() )
487 if ( nAtlasFeatures > maxAtlasFeatures )
491 QString(
"%1 atlas features have been requested, but the project configuration only allows printing %2 atlas features at a time" ).arg( nAtlasFeatures ).arg( maxAtlasFeatures )
495 QString filterString;
496 int currentAtlasPk = 0;
498 for (
int i = 0; i < nAtlasFeatures; ++i )
502 filterString.append(
" OR " );
505 filterString.append(
"( " );
508 if ( pkAttributeNames.isEmpty() )
510 filterString.append( u
"$id = %1"_s.arg( atlasPk.at( currentAtlasPk ) ) );
515 for (
int j = 0; j < pkIndexes.size(); ++j )
519 filterString.append(
" AND " );
526 filterString.append(
" )" );
534 if ( !errorString.isEmpty() )
536 throw QgsException( u
"An error occurred during the Atlas print: %1"_s.arg( errorString ) );
544 QList<QgsMapLayer *> layers = mContext.layersToRender();
548 auto image = std::make_unique<QImage>();
549 configureMapSettings( image.get(), mapSettings );
555 configurePrintLayout( layout.get(), mapSettings, atlas );
559 const QList<QgsMapLayer *> lyrs = mapSettings.
layers();
561#ifdef HAVE_SERVER_PYTHON_PLUGINS
562 mContext.accessControl()->resolveFilterFeatures( lyrs );
566 QHash<const QgsVectorLayer *, QStringList> fltrs;
571 fltrs.insert( vl, dimensionFilter( vl ) );
583 QTemporaryFile tempOutputFile( QDir::tempPath() +
'/' + u
"XXXXXX.%1"_s.arg( extension ) );
584 if ( !tempOutputFile.open() )
586 throw QgsException( u
"Could not open temporary file for the GetPrint request."_s );
594 if ( !mWmsParameters.dpi().isEmpty() )
597 double dpi( mWmsParameters.dpi().toDouble( &ok ) );
599 exportSettings.
dpi = dpi;
612 atlasSvgExport.
exportToSvg( tempOutputFile.fileName(), exportSettings );
618 exporter.
exportToSvg( tempOutputFile.fileName(), exportSettings );
627 double dpi( layout->renderContext().dpi() );
628 if ( !mWmsParameters.dpi().isEmpty() )
631 double _dpi = mWmsParameters.dpi().toDouble( &ok );
635 exportSettings.
dpi = dpi;
641 QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
646 const QSize imageSize = QSize(
static_cast<int>( width.
length() * dpi / 25.4 ),
static_cast<int>( height.
length() * dpi / 25.4 ) );
648 const QString paramWidth = mWmsParameters.width();
649 const QString paramHeight = mWmsParameters.height();
654 if ( !paramWidth.isEmpty() && !paramHeight.isEmpty() )
656 exportSettings.
imageSize = QSize( paramWidth.toInt(), paramHeight.toInt() );
658 else if ( !paramWidth.isEmpty() && paramHeight.isEmpty() )
660 exportSettings.
imageSize = QSize( paramWidth.toInt(),
static_cast<double>( paramWidth.toInt() ) / imageSize.width() * imageSize.height() );
662 else if ( paramWidth.isEmpty() && !paramHeight.isEmpty() )
664 exportSettings.
imageSize = QSize(
static_cast<double>( paramHeight.toInt() ) / imageSize.height() * imageSize.width(), paramHeight.toInt() );
672 exportSettings.
pages.append( 0 );
680 atlasPngExport.
exportToImage( tempOutputFile.fileName(), exportSettings );
684 throw QgsServiceException( u
"Bad request"_s, u
"Atlas error: empty atlas."_s, QString(), 400 );
690 exporter.
exportToImage( tempOutputFile.fileName(), exportSettings );
698 if ( !mWmsParameters.dpi().isEmpty() )
701 double dpi( mWmsParameters.dpi().toDouble( &ok ) );
703 exportSettings.
dpi = dpi;
708 exportSettings.
rasterizeWholeImage = layout->customProperty( u
"rasterize"_s,
false ).toBool();
710 QVector<qreal> requestMapScales = mWmsParameters.pdfPredefinedMapScales();
711 if ( requestMapScales.size() > 0 )
720 QStringList exportThemes = mWmsParameters.pdfExportMapThemes();
721 if ( exportThemes.size() > 0 )
725 exportSettings.
writeGeoPdf = mWmsParameters.writeGeospatialPdf();
731 if ( mWmsParameters.pdfLosslessImageCompression() )
735 if ( mWmsParameters.pdfDisableTiledRasterRendering() )
748 exporter.
exportToPdf( tempOutputFile.fileName(), exportSettings );
758 handlePrintErrors( atlas->
layout() );
762 handlePrintErrors( layout.get() );
765 return tempOutputFile.readAll();
772 QList<QgsLayoutItemMap *> maps;
778 for (
const auto &map : std::as_const( maps ) )
784 if ( cMapParams.
mLayers.isEmpty() )
789 if ( !atlas || !map->atlasDriven() )
795 c->removeLayoutItem( map );
804 QgsRectangle r( cMapParams.
mExtent );
812 if ( cMapParams.
mScale > 0 )
814 map->setScale(
static_cast<double>( cMapParams.
mScale ) );
820 map->setMapRotation( cMapParams.
mRotation );
824 if ( !map->keepLayerSet() )
826 QList<QgsMapLayer *> layerSet;
828 for (
const auto &layer : std::as_const( cMapParams.
mLayers ) )
830 if ( mContext.isValidGroup( layer.mNickname ) )
832 QList<QgsMapLayer *> layersFromGroup;
834 const QList<QgsMapLayer *> cLayersFromGroup = mContext.layersFromGroup( layer.mNickname );
835 for ( QgsMapLayer *layerFromGroup : cLayersFromGroup )
837 if ( !layerFromGroup )
842 layersFromGroup.push_front( layerFromGroup );
845 if ( !layersFromGroup.isEmpty() )
847 layerSet.append( layersFromGroup );
852 QgsMapLayer *mlayer = mContext.layer( layer.mNickname );
859 setLayerStyle( mlayer, layer.mStyle );
864 std::reverse( layerSet.begin(), layerSet.end() );
869 QMap<QString, QString> layersStyle;
870 if ( map->followVisibilityPreset() )
880 const QString presetName = map->followVisibilityPresetName();
881 if ( layerSet.isEmpty() )
884 const QgsExpressionContext ex { map->createExpressionContext() };
885 layerSet = map->layersToRender( &ex );
888 map->setFollowVisibilityPreset(
false );
892 for (
const auto &layerMapThemeRecord : std::as_const( mapThemeRecords ) )
894 if ( layerSet.contains( layerMapThemeRecord.layer() ) )
896 layersStyle.insert( layerMapThemeRecord.layer()->id(), layerMapThemeRecord.layer()->styleManager()->style( layerMapThemeRecord.currentStyle ).xmlData() );
902 const QList<QgsMapLayer *> highlights = highlightLayers( cMapParams.
mHighlightLayers );
903 for (
const auto &hl : std::as_const( highlights ) )
905 layerSet.prepend( hl );
908 map->setLayers( layerSet );
909 map->setKeepLayerSet(
true );
913 if ( !layersStyle.isEmpty() )
915 map->setLayerStyleOverrides( layersStyle );
916 map->setKeepLayerStyles(
true );
923 map->grid()->setIntervalX(
static_cast<double>( cMapParams.
mGridX ) );
924 map->grid()->setIntervalY(
static_cast<double>( cMapParams.
mGridY ) );
929 QList<QgsLayoutItemLabel *> labels;
930 c->layoutItems<QgsLayoutItemLabel>( labels );
931 for (
const auto &label : std::as_const( labels ) )
934 const QString labelId = label->id();
935 const QString labelParam = mWmsParameters.layoutParameter( labelId, ok );
940 if ( labelParam.isEmpty() )
944 c->removeItem( label );
949 label->setText( labelParam );
953 QList<QgsLayoutItemHtml *> htmls;
954 c->layoutObjects<QgsLayoutItemHtml>( htmls );
955 for (
const auto &html : std::as_const( htmls ) )
957 if ( html->frameCount() == 0 )
960 QgsLayoutFrame *htmlFrame = html->frame( 0 );
962 const QString htmlId = htmlFrame->
id();
963 const QString htmlValue = mWmsParameters.layoutParameter( htmlId, ok );
973 if ( htmlValue.isEmpty() )
975 c->removeMultiFrame( html );
982 QUrl newUrl( htmlValue );
983 html->setUrl( newUrl );
987 html->setHtml( htmlValue );
994 QList<QgsLayoutItemLegend *> legends;
995 c->layoutItems<QgsLayoutItemLegend>( legends );
996 for (
const auto &legend : std::as_const( legends ) )
998 switch ( legend->syncMode() )
1005 const QgsLayoutItemMap *map = legend->linkedMap();
1014 QgsLegendModel *model = legend->model();
1015 QStringList layerSet;
1016 QList<QgsMapLayer *> mapLayers;
1017 if ( map->
layers().isEmpty() )
1021 mapLayers = mProject->mapLayers(
true ).values();
1025 mapLayers = map->
layers();
1027 const QList<QgsMapLayer *> layerList = mapLayers;
1028 for (
const auto &layer : layerList )
1029 layerSet << layer->id();
1032 QgsLayerTree *root = model->
rootGroup();
1039 for (
const auto &layerId : layerIds )
1041 QgsLayerTreeLayer *nodeLayer = root->
findLayer( layerId );
1046 if ( !layerSet.contains( layerId ) )
1048 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
1052 QgsMapLayer *layer = nodeLayer->
layer();
1055 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
1073 if ( !mContext.isValidWidthHeight() )
1078 if ( mContext.socketFeedback() && mContext.socketFeedback()->isCanceled() )
1084 std::unique_ptr<QgsWmsRestorer> restorer;
1085 restorer = std::make_unique<QgsWmsRestorer>( mContext );
1088 QList<QgsMapLayer *> layers = mContext.layersToRender();
1095 std::unique_ptr<QPainter> painter;
1096 std::unique_ptr<QImage> image( createImage( mContext.mapSize() ) );
1099 configureMapSettings( image.get(), mapSettings );
1105 QPainter *renderedPainter = layersRendering( mapSettings, image.get() );
1106 if ( !renderedPainter )
1111 painter.reset( renderedPainter );
1114 annotationsRendering( painter.get(), mapSettings );
1120 QImage *scaledImage = scaleImage( image.get() );
1122 image.reset( scaledImage );
1125 if ( mContext.socketFeedback() && mContext.socketFeedback()->isCanceled() )
1135 QList<QgsMapLayer *> layers = mContext.layersToRender();
1139 const QStringList attributes = mWmsParameters.dxfLayerAttributes();
1140 QList<QgsDxfExport::DxfLayer> dxfLayers;
1152 int layerAttribute = -1;
1153 if ( attributes.size() > layerIdx )
1162 QgsRectangle mapExtent = mWmsParameters.bboxAsRectangle();
1164 QString crs = mWmsParameters.crs();
1165 if ( crs.compare( u
"CRS:84"_s, Qt::CaseInsensitive ) == 0 )
1167 crs = u
"EPSG:4326"_s;
1170 else if ( crs.isEmpty() )
1172 crs = u
"EPSG:4326"_s;
1206 auto dxf = std::make_unique<QgsDxfExport>();
1207 dxf->setExtent( mapExtent );
1208 dxf->setDestinationCrs( outputCRS );
1209 dxf->addLayers( dxfLayers );
1210 dxf->setLayerTitleAsName( mWmsParameters.dxfUseLayerTitleAsName() );
1211 dxf->setSymbologyExport( mWmsParameters.dxfMode() );
1214 dxf->setSymbologyScale( mWmsParameters.dxfScale() );
1217 dxf->setForce2d( mWmsParameters.isForce2D() );
1219 if ( mWmsParameters.noMText() )
1222 if ( mWmsParameters.exportLinesWithZeroWidth() )
1227 dxf->setFlags( flags );
1235 ms.
setExtent( mWmsParameters.bboxAsRectangle() );
1236 ms.
setLayers( mContext.layersToRender() );
1238 ms.
setOutputSize( QSize( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt() ) );
1242 if ( mWmsParameters.pdfExportMetadata() )
1253 const bool geospatialPdf = mWmsParameters.pdfAppendGeoreference();
1254 auto pdf = std::make_unique<QgsMapRendererTask>( ms, tmpFileName, u
"PDF"_s,
false,
QgsTask::Hidden, geospatialPdf, pdfExportDetails );
1255 if ( mWmsParameters.pdfAppendGeoreference() )
1257 pdf->setSaveWorldFile(
true );
1265 if ( i < 0 || i > mapSettings.
outputSize().width() )
1272 if ( j < 0 || j > mapSettings.
outputSize().height() )
1289 if ( mWmsParameters.queryLayersNickname().isEmpty() )
1295 const bool ijDefined = !mWmsParameters.i().isEmpty() && !mWmsParameters.j().isEmpty();
1296 const bool xyDefined = !mWmsParameters.x().isEmpty() && !mWmsParameters.y().isEmpty();
1297 const bool filtersDefined = !mWmsParameters.filters().isEmpty();
1298 const bool filterGeomDefined = !mWmsParameters.filterGeom().isEmpty();
1300 if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
1304 if ( mWmsParameters.j().isEmpty() )
1317 std::unique_ptr<QImage> outputImage( createImage( mContext.mapSize() ) );
1320 std::unique_ptr<QgsWmsRestorer> restorer;
1321 restorer = std::make_unique<QgsWmsRestorer>( mContext );
1325 bool mandatoryCrsParam =
true;
1326 if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.crs().isEmpty() )
1328 mandatoryCrsParam =
false;
1334 configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
1339 const double scaleDenominator = scaleCalc.
calculate( mWmsParameters.bboxAsRectangle(), outputImage->width() );
1351#ifdef HAVE_SERVER_PYTHON_PLUGINS
1352 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
1355 QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );
1360 ba = convertFeatureInfoToText( result );
1362 ba = convertFeatureInfoToHtml( result );
1364 ba = convertFeatureInfoToJson( layers, result, mapSettings.
destinationCrs() );
1366 ba = result.toByteArray();
1371 QImage *QgsRenderer::createImage(
const QSize &size )
const
1373 std::unique_ptr<QImage> image;
1381 image = std::make_unique<QImage>( size, QImage::Format_ARGB32_Premultiplied );
1386 image = std::make_unique<QImage>( size, QImage::Format_RGB32 );
1391 if ( image->isNull() )
1393 throw QgsException( u
"createImage: image could not be created, check for out of memory conditions"_s );
1396 const int dpm =
static_cast<int>( mContext.dotsPerMm() * 1000.0 );
1397 image->setDotsPerMeterX( dpm );
1398 image->setDotsPerMeterY( dpm );
1400 return image.release();
1403 void QgsRenderer::configureMapSettings(
const QPaintDevice *paintDevice, QgsMapSettings &mapSettings,
bool mandatoryCrsParam )
1407 throw QgsException( u
"configureMapSettings: no paint device"_s );
1410 mapSettings.
setOutputSize( QSize( paintDevice->width(), paintDevice->height() ) );
1413 mapSettings.
setOutputDpi( mContext.dotsPerMm() * 25.4 );
1416 QgsRectangle mapExtent = mWmsParameters.bboxAsRectangle();
1417 if ( !mWmsParameters.bbox().isEmpty() && mapExtent.
isEmpty() )
1422 QString crs = mWmsParameters.crs();
1423 if ( crs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 )
1425 crs = QString(
"EPSG:4326" );
1428 else if ( crs.isEmpty() && !mandatoryCrsParam )
1430 crs = QString(
"EPSG:4326" );
1433 QgsCoordinateReferenceSystem outputCRS;
1440 QgsWmsParameter parameter;
1442 if ( mWmsParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
1453 throw QgsBadRequestException( code, parameter );
1462 if ( mWmsParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) && outputCRS.
hasAxisInverted() )
1470 mapSettings.
setExtentBuffer( mContext.mapTileBuffer( paintDevice->width() ) );
1476 bool transparent = mWmsParameters.transparentAsBool();
1477 QColor backgroundColor = mWmsParameters.backgroundColorAsColor();
1484 else if ( backgroundColor.isValid() )
1490 QgsExpressionContext context = mProject->createExpressionContext();
1507 if ( mContext.settings().logProfile() )
1517 const QString timeString { mWmsParameters.dimensionValues().value( u
"TIME"_s, QString() ) };
1518 if ( !timeString.isEmpty() )
1520 bool isValidTemporalRange {
true };
1523 const QDateTime dt { QDateTime::fromString( timeString, Qt::DateFormat::ISODateWithMs ) };
1534 catch (
const QgsServerApiBadRequestException &ex )
1536 isValidTemporalRange =
false;
1541 if ( isValidTemporalRange )
1550 QgsRenderContext QgsRenderer::configureDefaultRenderContext( QPainter *painter )
1556 QgsDistanceArea distanceArea = QgsDistanceArea();
1557 distanceArea.
setSourceCrs( QgsCoordinateReferenceSystem( mWmsParameters.crs() ), mProject->transformContext() );
1563 QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers,
const QgsMapSettings &mapSettings,
const QImage *outputImage,
const QString &version )
const
1565 const QStringList queryLayers = mContext.flattenedQueryLayers( mContext.parameters().queryLayersNickname() );
1567 bool ijDefined = ( !mWmsParameters.i().isEmpty() && !mWmsParameters.j().isEmpty() );
1569 bool xyDefined = ( !mWmsParameters.x().isEmpty() && !mWmsParameters.y().isEmpty() );
1571 bool filtersDefined = !mWmsParameters.filters().isEmpty();
1573 bool filterGeomDefined = !mWmsParameters.filterGeom().isEmpty();
1575 int featureCount = mWmsParameters.featureCountAsInt();
1576 if ( featureCount < 1 )
1581 int i = mWmsParameters.iAsInt();
1582 int j = mWmsParameters.jAsInt();
1583 if ( xyDefined && !ijDefined )
1585 i = mWmsParameters.xAsInt();
1586 j = mWmsParameters.yAsInt();
1588 int width = mWmsParameters.widthAsInt();
1589 int height = mWmsParameters.heightAsInt();
1590 if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
1592 i *= ( outputImage->width() /
static_cast<double>( width ) );
1593 j *= ( outputImage->height() /
static_cast<double>( height ) );
1597 std::unique_ptr<QgsRectangle> featuresRect;
1598 std::unique_ptr<QgsGeometry> filterGeom;
1599 std::unique_ptr<QgsPointXY> infoPoint;
1601 if ( i != -1 && j != -1 )
1603 infoPoint = std::make_unique<QgsPointXY>();
1604 infoPointToMapCoordinates( i, j, infoPoint.get(), mapSettings );
1606 else if ( filtersDefined )
1608 featuresRect = std::make_unique<QgsRectangle>();
1611 if ( filterGeomDefined )
1613 filterGeom = std::make_unique<QgsGeometry>(
QgsGeometry::fromWkt( mWmsParameters.filterGeom() ) );
1616 QDomDocument result;
1617 const QDomNode header = result.createProcessingInstruction( u
"xml"_s, u
"version=\"1.0\" encoding=\"UTF-8\""_s );
1618 result.appendChild( header );
1620 QDomElement getFeatureInfoElement;
1624 getFeatureInfoElement = result.createElement( u
"wfs:FeatureCollection"_s );
1625 getFeatureInfoElement.setAttribute( u
"xmlns:wfs"_s, u
"http://www.opengis.net/wfs"_s );
1626 getFeatureInfoElement.setAttribute( u
"xmlns:ogc"_s, u
"http://www.opengis.net/ogc"_s );
1627 getFeatureInfoElement.setAttribute( u
"xmlns:gml"_s, u
"http://www.opengis.net/gml"_s );
1628 getFeatureInfoElement.setAttribute( u
"xmlns:ows"_s, u
"http://www.opengis.net/ows"_s );
1629 getFeatureInfoElement.setAttribute( u
"xmlns:xlink"_s, u
"http://www.w3.org/1999/xlink"_s );
1630 getFeatureInfoElement.setAttribute( u
"xmlns:qgs"_s, u
"http://qgis.org/gml"_s );
1631 getFeatureInfoElement.setAttribute( u
"xmlns:xsi"_s, u
"http://www.w3.org/2001/XMLSchema-instance"_s );
1632 getFeatureInfoElement.setAttribute( u
"xsi:schemaLocation"_s, u
"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://qgis.org/gml"_s );
1637 if ( featureInfoElemName.isEmpty() )
1639 featureInfoElemName = u
"GetFeatureInfoResponse"_s;
1642 if ( featureInfoElemNs.isEmpty() )
1644 getFeatureInfoElement = result.createElement( featureInfoElemName );
1648 getFeatureInfoElement = result.createElementNS( featureInfoElemNs, featureInfoElemName );
1652 if ( !featureInfoSchema.isEmpty() )
1654 getFeatureInfoElement.setAttribute( u
"xmlns:xsi"_s, u
"http://www.w3.org/2001/XMLSchema-instance"_s );
1655 getFeatureInfoElement.setAttribute( u
"xsi:schemaLocation"_s, featureInfoSchema );
1658 result.appendChild( getFeatureInfoElement );
1668 for (
const QString &queryLayer : queryLayers )
1670 bool validLayer =
false;
1671 bool queryableLayer =
true;
1672 for ( QgsMapLayer *layer : std::as_const( layers ) )
1674 if ( queryLayer == mContext.layerNickname( *layer ) )
1678 if ( !queryableLayer )
1683 QDomElement layerElement;
1686 layerElement = getFeatureInfoElement;
1690 layerElement = result.createElement( u
"Layer"_s );
1691 QString layerName = queryLayer;
1694 QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.constFind( layerName );
1695 if ( layerAliasIt != layerAliasMap.constEnd() )
1697 layerName = layerAliasIt.value();
1700 layerElement.setAttribute( u
"name"_s, layerName );
1701 const QString layerTitle = layer->serverProperties()->title();
1702 if ( !layerTitle.isEmpty() )
1704 layerElement.setAttribute( u
"title"_s, layerTitle );
1708 layerElement.setAttribute( u
"title"_s, layerName );
1710 getFeatureInfoElement.appendChild( layerElement );
1713 layerElement.setAttribute( u
"id"_s, layer->id() );
1719 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
1722 ( void ) featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, featuresRect.get(), filterGeom.get() );
1728 QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
1744 layerElement = result.createElement( u
"gml:featureMember"_s );
1745 getFeatureInfoElement.appendChild( layerElement );
1747 ( void ) featureInfoFromRasterLayer( rasterLayer, mapSettings, &layerInfoPoint, renderContext, result, layerElement, version );
1751 QgsMeshLayer *meshLayer = qobject_cast<QgsMeshLayer *>( layer );
1759 ( void ) featureInfoFromMeshLayer( meshLayer, mapSettings, &layerInfoPoint, renderContext, result, layerElement, version );
1763 if ( !validLayer && !mContext.isValidLayer( queryLayer ) && !mContext.isValidGroup( queryLayer ) )
1766 param.mValue = queryLayer;
1769 else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.isValidGroup( queryLayer ) ) )
1772 param.mValue = queryLayer;
1774 bool hasGroupAndQueryable {
false };
1775 if ( !mContext.parameters().queryLayersNickname().contains( queryLayer ) )
1778 const QStringList constNicks { mContext.parameters().queryLayersNickname() };
1779 for (
const QString &ql : constNicks )
1781 if ( mContext.layerGroups().contains( ql ) )
1783 const QList<QgsMapLayer *> constLayers { mContext.layerGroups()[ql] };
1784 for (
const QgsMapLayer *ml : constLayers )
1786 if ( ( !ml->serverProperties()->shortName().isEmpty() && ml->serverProperties()->shortName() == queryLayer ) || ( ml->name() == queryLayer ) )
1792 hasGroupAndQueryable =
true;
1801 if ( !hasGroupAndQueryable )
1808 if ( featuresRect && !featuresRect->isNull() )
1812 QDomElement bBoxElem = result.createElement( u
"gml:boundedBy"_s );
1813 QDomElement boxElem;
1814 int gmlVersion = mWmsParameters.infoFormatVersion();
1815 if ( gmlVersion < 3 )
1827 boxElem.setAttribute( u
"srsName"_s, crs.
authid() );
1829 bBoxElem.appendChild( boxElem );
1830 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1834 QDomElement bBoxElem = result.createElement( u
"BoundingBox"_s );
1836 bBoxElem.setAttribute( u
"minx"_s,
qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1837 bBoxElem.setAttribute( u
"maxx"_s,
qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1838 bBoxElem.setAttribute( u
"miny"_s,
qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1839 bBoxElem.setAttribute( u
"maxy"_s,
qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
1840 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1846 convertFeatureInfoToSia2045( result );
1852 bool QgsRenderer::featureInfoFromVectorLayer(
1853 QgsVectorLayer *layer,
1854 const QgsPointXY *infoPoint,
1856 QDomDocument &infoDocument,
1857 QDomElement &layerElement,
1858 const QgsMapSettings &mapSettings,
1859 QgsRenderContext &renderContext,
1860 const QString &version,
1861 QgsRectangle *featureBBox,
1862 QgsGeometry *filterGeom
1870 QgsFeatureRequest fReq;
1873 std::unique_ptr<QgsGeometry> layerFilterGeom;
1876 layerFilterGeom = std::make_unique<QgsGeometry>( *filterGeom );
1881 QgsRectangle mapRect = mapSettings.
extent();
1885 QgsRectangle searchRect;
1890 searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
1892 else if ( layerFilterGeom )
1894 searchRect = layerFilterGeom->boundingBox();
1896 else if ( !mWmsParameters.bbox().isEmpty() )
1898 searchRect = layerRect;
1904 QgsAttributes featureAttributes;
1905 int featureCounter = 0;
1907 const QgsFields fields = layer->
fields();
1924 if ( layerFilterGeom )
1926 fReq.
setFilterExpression( QString(
"intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
1930 mFeatureFilter.filterFeatures( layer, fReq );
1933#ifdef HAVE_SERVER_PYTHON_PLUGINS
1935 mContext.accessControl()->filterFeatures( layer, fReq );
1938 QStringList attributes;
1939 for (
const QgsField &field : fields )
1941 attributes.append( field.name() );
1943 attributes = mContext.accessControl()->layerAttributes( layer, attributes );
1947 QgsFeatureIterator fit = layer->
getFeatures( fReq );
1951 r2->startRender( renderContext, layer->
fields() );
1954 bool featureBBoxInitialized =
false;
1963 if ( featureCounter > nFeatures )
1978 bool render = r2->willRenderFeature( feature, renderContext );
1991 if ( !featureBBoxInitialized && featureBBox->
isEmpty() )
1994 featureBBoxInitialized =
true;
2003 QgsCoordinateReferenceSystem outputCrs = layer->
crs();
2012 int gmlVersion = mWmsParameters.infoFormatVersion();
2013 QString typeName = mContext.layerNickname( *layer );
2014 QDomElement elem = createFeatureGML(
2023#ifdef HAVE_SERVER_PYTHON_PLUGINS
2028 QDomElement featureMemberElem = infoDocument.createElement( u
"gml:featureMember"_s );
2029 featureMemberElem.appendChild( elem );
2030 layerElement.appendChild( featureMemberElem );
2035 QDomElement featureElement = infoDocument.createElement( u
"Feature"_s );
2037 layerElement.appendChild( featureElement );
2043 writeAttributesTabLayout(
2051#ifdef HAVE_SERVER_PYTHON_PLUGINS
2059 for (
int i = 0; i < featureAttributes.count(); ++i )
2061 writeVectorLayerAttribute(
2069#ifdef HAVE_SERVER_PYTHON_PLUGINS
2081 QDomElement maptipElem = infoDocument.createElement( u
"Attribute"_s );
2082 maptipElem.setAttribute( u
"name"_s, u
"maptip"_s );
2086 featureElement.appendChild( maptipElem );
2090 if ( displayExpression.
isValid() && mWmsParameters.withDisplayName() )
2092 QDomElement displayElem = infoDocument.createElement( u
"Attribute"_s );
2093 displayElem.setAttribute( u
"name"_s, u
"displayName"_s );
2096 displayExpression.
prepare( &context );
2097 displayElem.setAttribute( u
"value"_s, displayExpression.
evaluate( &context ).toString() );
2098 featureElement.appendChild( displayElem );
2104 QDomElement bBoxElem = infoDocument.createElement( u
"BoundingBox"_s );
2105 bBoxElem.setAttribute( version ==
"1.1.1"_L1 ?
"SRS" :
"CRS", outputCrs.
authid() );
2110 featureElement.appendChild( bBoxElem );
2116 QgsGeometry geom = feature.
geometry();
2119 if ( layer->
crs() != outputCrs )
2121 QgsCoordinateTransform transform = mapSettings.
layerTransform( layer );
2126 if ( segmentizeWktGeometry )
2128 const QgsAbstractGeometry *abstractGeom = geom.
constGet();
2133 QgsAbstractGeometry *segmentizedGeom = abstractGeom->
segmentize();
2134 geom.
set( segmentizedGeom );
2138 QDomElement geometryElement = infoDocument.createElement( u
"Attribute"_s );
2139 geometryElement.setAttribute( u
"name"_s, u
"geometry"_s );
2140 geometryElement.setAttribute( u
"value"_s, geom.
asWkt( mContext.precision() ) );
2141 geometryElement.setAttribute( u
"type"_s, u
"derived"_s );
2142 featureElement.appendChild( geometryElement );
2149 r2->stopRender( renderContext );
2155 void QgsRenderer::writeAttributesTabGroup(
2156 const QgsAttributeEditorElement *group,
2157 QgsVectorLayer *layer,
2158 const QgsFields &fields,
2159 QgsAttributes &featureAttributes,
2161 QDomElement &parentElem,
2162 QgsRenderContext &renderContext,
2163 QStringList *attributes
2166 const QgsAttributeEditorContainer *container =
dynamic_cast<const QgsAttributeEditorContainer *
>( group );
2169 QString groupName = container->
name();
2170 QDomElement nameElem;
2172 if ( !groupName.isEmpty() )
2174 nameElem = doc.createElement( groupName );
2175 parentElem.appendChild( nameElem );
2178 const QList<QgsAttributeEditorElement *> children = container->
children();
2179 for (
const QgsAttributeEditorElement *child : children )
2183 writeAttributesTabGroup( child, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext );
2187 const QgsAttributeEditorField *editorField =
dynamic_cast<const QgsAttributeEditorField *
>( child );
2193 writeVectorLayerAttribute( idx, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext, attributes );
2201 void QgsRenderer::writeAttributesTabLayout(
2202 QgsEditFormConfig &config, QgsVectorLayer *layer,
const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext, QStringList *attributes
2206 if ( !editorContainer )
2211 writeAttributesTabGroup( editorContainer, layer, fields, featureAttributes, doc, featureElem, renderContext, attributes );
2214 void QgsRenderer::writeVectorLayerAttribute(
2215 int attributeIndex, QgsVectorLayer *layer,
const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext, QStringList *attributes
2218#ifndef HAVE_SERVER_PYTHON_PLUGINS
2219 Q_UNUSED( attributes );
2232#ifdef HAVE_SERVER_PYTHON_PLUGINS
2234 if ( attributes && !attributes->contains( fields.
at( attributeIndex ).
name() ) )
2241 QDomElement attributeElement = doc.createElement( u
"Attribute"_s );
2242 attributeElement.setAttribute( u
"name"_s, attributeName );
2245 featureElem.appendChild( attributeElement );
2248 bool QgsRenderer::featureInfoFromMeshLayer(
2249 QgsMeshLayer *layer,
const QgsMapSettings &mapSettings,
const QgsPointXY *infoPoint,
const QgsRenderContext &renderContext, QDomDocument &infoDocument, QDomElement &layerElement,
const QString &version
2253 Q_UNUSED( mapSettings )
2262 const QString dateFormat = u
"yyyy-MM-ddTHH:mm:ss"_s;
2264 QList<QgsMeshDatasetIndex> datasetIndexList;
2273 layerRange =
static_cast<QgsMeshLayerTemporalProperties *
>( layer->
temporalProperties() )->timeExtent();
2275 if ( activeScalarGroup >= 0 )
2277 QgsMeshDatasetIndex indice;
2279 datasetIndexList.append( indice );
2282 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
2285 for (
int groupIndex : allGroup )
2287 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
2293 if ( activeScalarGroup >= 0 )
2295 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
2298 for (
int groupIndex : allGroup )
2300 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
2303 datasetIndexList.append( groupIndex );
2310 double scalarDoubleValue = 0.0;
2312 for (
const QgsMeshDatasetIndex &index : datasetIndexList )
2314 if ( !index.isValid() )
2318 QMap<QString, QString> derivedAttributes;
2320 QMap<QString, QString> attribute;
2324 const QgsMeshDatasetValue scalarValue = layer->
datasetValue( index, *infoPoint, searchRadius );
2325 scalarDoubleValue = scalarValue.
scalar();
2326 attribute.insert( u
"Scalar Value"_s, std::isnan( scalarDoubleValue ) ? u
"no data"_s : QLocale().toString( scalarDoubleValue ) );
2331 const QgsMeshDatasetValue vectorValue = layer->
datasetValue( index, *infoPoint, searchRadius );
2332 const double vectorX = vectorValue.
x();
2333 const double vectorY = vectorValue.
y();
2334 if ( std::isnan( vectorX ) || std::isnan( vectorY ) )
2336 attribute.insert( u
"Vector Value"_s, u
"no data"_s );
2340 attribute.insert( u
"Vector Magnitude"_s, QLocale().toString( vectorValue.
scalar() ) );
2341 derivedAttributes.insert( u
"Vector x-component"_s, QLocale().toString( vectorY ) );
2342 derivedAttributes.insert( u
"Vector y-component"_s, QLocale().toString( vectorX ) );
2349 derivedAttributes.insert( u
"Time Step"_s, layer->
formatTime( meta.
time() ) );
2350 derivedAttributes.insert( u
"Source"_s, groupMeta.
uri() );
2352 const QString resultName = groupMeta.
name();
2354 QDomElement attributeElement = infoDocument.createElement( u
"Attribute"_s );
2355 attributeElement.setAttribute( u
"name"_s, resultName );
2360 value = QString::number( scalarDoubleValue );
2363 attributeElement.setAttribute( u
"value"_s, value );
2364 layerElement.appendChild( attributeElement );
2368 QDomElement attributeElementTime = infoDocument.createElement( u
"Attribute"_s );
2369 attributeElementTime.setAttribute( u
"name"_s, u
"Time"_s );
2372 value = range.
begin().toString( dateFormat );
2376 value = range.
begin().toString( dateFormat ) +
'/' + range.
end().toString( dateFormat );
2378 attributeElementTime.setAttribute( u
"value"_s, value );
2379 layerElement.appendChild( attributeElementTime );
2385 bool QgsRenderer::featureInfoFromRasterLayer(
2386 QgsRasterLayer *layer,
const QgsMapSettings &mapSettings,
const QgsPointXY *infoPoint,
const QgsRenderContext &renderContext, QDomDocument &infoDocument, QDomElement &layerElement,
const QString &version
2407 QgsRasterIdentifyResult identifyResult;
2410 const QgsRectangle extent { mapSettings.
extent() };
2414 throw QgsBadRequestException(
2425 if ( !identifyResult.
isValid() )
2428 QMap<int, QVariant> attributes = identifyResult.
results();
2434 QgsCoordinateReferenceSystem layerCrs = layer->
crs();
2435 int gmlVersion = mWmsParameters.infoFormatVersion();
2436 QString typeName = mContext.layerNickname( *layer );
2442 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
2444 fields.
append( QgsField( layer->
bandName( it.key() ), QMetaType::Type::Double ) );
2445 feature.
setAttribute( index++, QString::number( it.value().toDouble() ) );
2448 QDomElement elem = createFeatureGML( &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
2449 layerElement.appendChild( elem );
2453 const auto values = identifyResult.
results();
2454 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
2456 QVariant value = it.value();
2457 if ( value.userType() == QMetaType::Type::Bool && !value.toBool() )
2463 if ( value.userType() == QMetaType::Type::QString )
2471 for (
const QgsFeatureStore &featureStore : featureStoreList )
2474 for (
const QgsFeature &feature : storeFeatures )
2476 QDomElement elem = createFeatureGML( &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
2477 layerElement.appendChild( elem );
2487 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
2489 QDomElement attributeElement = infoDocument.createElement( u
"Attribute"_s );
2490 attributeElement.setAttribute( u
"name"_s, layer->
bandName( it.key() ) );
2495 value = QString::number( it.value().toDouble() );
2498 attributeElement.setAttribute( u
"value"_s, value );
2499 layerElement.appendChild( attributeElement );
2504 const auto values = identifyResult.
results();
2505 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
2507 QVariant value = it.value();
2508 if ( value.userType() == QMetaType::Type::Bool && !value.toBool() )
2514 if ( value.userType() == QMetaType::Type::QString )
2521 for (
const QgsFeatureStore &featureStore : featureStoreList )
2524 for (
const QgsFeature &feature : storeFeatures )
2526 for (
const auto &fld : feature.
fields() )
2528 const auto val { feature.
attribute( fld.name() ) };
2529 if ( val.isValid() )
2531 QDomElement attributeElement = infoDocument.createElement( u
"Attribute"_s );
2532 attributeElement.setAttribute( u
"name"_s, fld.name() );
2533 attributeElement.setAttribute( u
"value"_s, val.toString() );
2534 layerElement.appendChild( attributeElement );
2545 QDomElement maptipElem = infoDocument.createElement( u
"Attribute"_s );
2546 maptipElem.setAttribute( u
"name"_s, u
"maptip"_s );
2549 scope->
addVariable( QgsExpressionContextScope::StaticVariable( u
"layer_cursor_point"_s, QVariant::fromValue(
QgsGeometry::fromPointXY( QgsPointXY( infoPoint->
x(), infoPoint->
y() ) ) ) ) );
2552 layerElement.appendChild( maptipElem );
2558 bool QgsRenderer::testFilterStringSafety(
const QString &filter )
const
2561 if ( filter.contains(
";"_L1 ) )
2566 QStringList tokens = filter.split(
' ', Qt::SkipEmptyParts );
2567 groupStringList( tokens, u
"'"_s );
2568 groupStringList( tokens, u
"\""_s );
2570 for (
auto tokenIt = tokens.constBegin(); tokenIt != tokens.constEnd(); ++tokenIt )
2573 if ( tokenIt->compare(
','_L1 ) == 0
2574 || tokenIt->compare(
'('_L1 ) == 0
2575 || tokenIt->compare(
')'_L1 ) == 0
2576 || tokenIt->compare(
'='_L1 ) == 0
2577 || tokenIt->compare(
"!="_L1 ) == 0
2578 || tokenIt->compare(
'<'_L1 ) == 0
2579 || tokenIt->compare(
"<="_L1 ) == 0
2580 || tokenIt->compare(
'>'_L1 ) == 0
2581 || tokenIt->compare(
">="_L1 ) == 0
2582 || tokenIt->compare(
'%'_L1 ) == 0
2583 || tokenIt->compare(
"IS"_L1, Qt::CaseInsensitive ) == 0
2584 || tokenIt->compare(
"NOT"_L1, Qt::CaseInsensitive ) == 0
2585 || tokenIt->compare(
"NULL"_L1, Qt::CaseInsensitive ) == 0
2586 || tokenIt->compare(
"AND"_L1, Qt::CaseInsensitive ) == 0
2587 || tokenIt->compare(
"OR"_L1, Qt::CaseInsensitive ) == 0
2588 || tokenIt->compare(
"IN"_L1, Qt::CaseInsensitive ) == 0
2589 || tokenIt->compare(
"LIKE"_L1, Qt::CaseInsensitive ) == 0
2590 || tokenIt->compare(
"ILIKE"_L1, Qt::CaseInsensitive ) == 0
2591 || tokenIt->compare(
"DMETAPHONE"_L1, Qt::CaseInsensitive ) == 0
2592 || tokenIt->compare(
"SOUNDEX"_L1, Qt::CaseInsensitive ) == 0
2593 || mContext.settings().allowedExtraSqlTokens().contains( *tokenIt, Qt::CaseSensitivity::CaseInsensitive ) )
2600 ( void ) tokenIt->toDouble( &isNumeric );
2609 if ( *tokenIt ==
"''"_L1 )
2615 if ( tokenIt->size() > 2
2616 && ( *tokenIt )[0] == QChar(
'\'' )
2617 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'\'' )
2618 && ( *tokenIt )[1] != QChar(
'\'' )
2619 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'\'' ) )
2625 if ( tokenIt->size() > 2 && ( *tokenIt )[0] == QChar(
'"' ) && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'"' ) && ( *tokenIt )[1] != QChar(
'"' ) && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'"' ) )
2636 void QgsRenderer::groupStringList( QStringList &list,
const QString &groupString )
2639 bool groupActive =
false;
2640 int startGroup = -1;
2641 QString concatString;
2643 for (
int i = 0; i < list.size(); ++i )
2645 QString &str = list[i];
2646 if ( str.startsWith( groupString ) )
2650 concatString.clear();
2655 if ( i != startGroup )
2657 concatString.append(
" " );
2659 concatString.append( str );
2662 if ( str.endsWith( groupString ) )
2665 groupActive =
false;
2667 if ( startGroup != -1 )
2669 list[startGroup] = concatString;
2670 for (
int j = startGroup + 1; j <= endGroup; ++j )
2672 list.removeAt( startGroup + 1 );
2677 concatString.clear();
2683 void QgsRenderer::convertFeatureInfoToSia2045( QDomDocument &doc )
const
2685 QDomDocument SIAInfoDoc;
2686 QDomElement infoDocElement = doc.documentElement();
2687 QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement,
false ).toElement();
2688 SIAInfoDoc.appendChild( SIAInfoDocElement );
2690 QString currentAttributeName;
2691 QString currentAttributeValue;
2692 QDomElement currentAttributeElem;
2693 QString currentLayerName;
2694 QDomElement currentLayerElem;
2695 QDomNodeList layerNodeList = infoDocElement.elementsByTagName( u
"Layer"_s );
2696 for (
int i = 0; i < layerNodeList.size(); ++i )
2698 currentLayerElem = layerNodeList.at( i ).toElement();
2699 currentLayerName = currentLayerElem.attribute( u
"name"_s );
2701 QDomElement currentFeatureElem;
2703 QDomNodeList featureList = currentLayerElem.elementsByTagName( u
"Feature"_s );
2704 if ( featureList.isEmpty() )
2707 QDomNodeList attributeList = currentLayerElem.elementsByTagName( u
"Attribute"_s );
2708 QDomElement rasterLayerElem;
2709 if ( !attributeList.isEmpty() )
2711 rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
2713 for (
int j = 0; j < attributeList.size(); ++j )
2715 currentAttributeElem = attributeList.at( j ).toElement();
2716 currentAttributeName = currentAttributeElem.attribute( u
"name"_s );
2717 currentAttributeValue = currentAttributeElem.attribute( u
"value"_s );
2718 QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2719 QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2720 outAttributeElem.appendChild( outAttributeText );
2721 rasterLayerElem.appendChild( outAttributeElem );
2723 if ( !attributeList.isEmpty() )
2725 SIAInfoDocElement.appendChild( rasterLayerElem );
2731 QSet<QString> layerPropertyAttributes;
2732 QString currentLayerId = currentLayerElem.attribute( u
"id"_s );
2733 if ( !currentLayerId.isEmpty() )
2735 QgsMapLayer *currentLayer = mProject->mapLayer( currentLayerId );
2738 QString WMSPropertyAttributesString = currentLayer->
customProperty( u
"WMSPropertyAttributes"_s ).toString();
2739 if ( !WMSPropertyAttributesString.isEmpty() )
2741 QStringList propertyList = WMSPropertyAttributesString.split( u
"//"_s );
2742 for (
auto propertyIt = propertyList.constBegin(); propertyIt != propertyList.constEnd(); ++propertyIt )
2744 layerPropertyAttributes.insert( *propertyIt );
2750 QDomElement propertyRefChild;
2751 for (
int j = 0; j < featureList.size(); ++j )
2753 QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
2754 currentFeatureElem = featureList.at( j ).toElement();
2755 QDomNodeList attributeList = currentFeatureElem.elementsByTagName( u
"Attribute"_s );
2757 for (
int k = 0; k < attributeList.size(); ++k )
2759 currentAttributeElem = attributeList.at( k ).toElement();
2760 currentAttributeName = currentAttributeElem.attribute( u
"name"_s );
2761 currentAttributeValue = currentAttributeElem.attribute( u
"value"_s );
2762 if ( layerPropertyAttributes.contains( currentAttributeName ) )
2764 QDomElement propertyElem = SIAInfoDoc.createElement( u
"property"_s );
2765 QDomElement identifierElem = SIAInfoDoc.createElement( u
"identifier"_s );
2766 QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
2767 identifierElem.appendChild( identifierText );
2768 QDomElement valueElem = SIAInfoDoc.createElement( u
"value"_s );
2769 QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
2770 valueElem.appendChild( valueText );
2771 propertyElem.appendChild( identifierElem );
2772 propertyElem.appendChild( valueElem );
2773 if ( propertyRefChild.isNull() )
2775 SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
2776 propertyRefChild = propertyElem;
2780 SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
2785 QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2786 QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2787 SIAAttributeElem.appendChild( SIAAttributeText );
2788 SIAFeatureElem.appendChild( SIAAttributeElem );
2791 SIAInfoDocElement.appendChild( SIAFeatureElem );
2798 QByteArray QgsRenderer::convertFeatureInfoToHtml(
const QDomDocument &doc )
const
2801 QString featureInfoString = u
" <!DOCTYPE html>"_s;
2804 featureInfoString.append( QStringLiteral( R
"HTML(
2807 <title>Information</title>
2808 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2811 font-family: "Open Sans", "Calluna Sans", "Gill Sans MT", "Calibri", "Trebuchet MS", sans-serif;
2818 border: 1px solid black;
2819 border-collapse: collapse;
2840 const QDomNodeList layerList = doc.elementsByTagName( u
"Layer"_s );
2843 for (
int i = 0; i < layerList.size(); ++i )
2845 const QDomElement layerElem = layerList.at( i ).toElement();
2848 const QDomNodeList featureNodeList = layerElem.elementsByTagName( u
"Feature"_s );
2849 const QDomElement currentFeatureElement;
2851 if ( !featureNodeList.isEmpty() )
2855 const QString featureInfoLayerTitleString = u
" <div class='layer-title'>%1</div>"_s.arg( layerElem.attribute( u
"title"_s ).toHtmlEscaped() );
2856 featureInfoString.append( featureInfoLayerTitleString );
2859 for (
int j = 0; j < featureNodeList.size(); ++j )
2861 const QDomElement featureElement = featureNodeList.at( j ).toElement();
2864 featureInfoString.append( QStringLiteral( R
"HTML(
2869 const QDomNodeList attributeNodeList = featureElement.elementsByTagName( u
"Attribute"_s );
2870 for (
int k = 0; k < attributeNodeList.size(); ++k )
2872 const QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2873 const QString name = attributeElement.attribute( u
"name"_s ).toHtmlEscaped();
2874 QString value = attributeElement.attribute( u
"value"_s );
2875 if ( name !=
"maptip"_L1 )
2877 value = value.toHtmlEscaped();
2882 const QString featureInfoAttributeString = QStringLiteral( R
"HTML(
2887 .arg( name, value );
2889 featureInfoString.append( featureInfoAttributeString );
2891 else if ( name ==
"maptip"_L1 )
2893 featureInfoString.append( QStringLiteral( R
"HTML(
2901 featureInfoString.append( QStringLiteral( R
"HTML(
2908 const QDomNodeList attributeNodeList = layerElem.elementsByTagName( u
"Attribute"_s );
2911 if ( !attributeNodeList.isEmpty() )
2915 const QString featureInfoLayerTitleString = u
" <div class='layer-title'>%1</div>"_s.arg( layerElem.attribute( u
"title"_s ).toHtmlEscaped() );
2916 featureInfoString.append( featureInfoLayerTitleString );
2918 featureInfoString.append( QStringLiteral( R
"HTML(
2922 for (
int j = 0; j < attributeNodeList.size(); ++j )
2924 const QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2925 const QString name = attributeElement.attribute( u
"name"_s ).toHtmlEscaped();
2926 QString value = attributeElement.attribute( u
"value"_s );
2927 if ( value.isEmpty() )
2929 value = u
"no data"_s;
2931 if ( name !=
"maptip"_L1 )
2933 value = value.toHtmlEscaped();
2938 const QString featureInfoAttributeString = QStringLiteral( R
"HTML(
2943 .arg( name, value );
2946 featureInfoString.append( featureInfoAttributeString );
2948 else if ( name ==
"maptip"_L1 )
2950 featureInfoString.append( QStringLiteral( R
"HTML(
2958 featureInfoString.append( QStringLiteral( R
"HTML(
2968 featureInfoString.append( QStringLiteral( R
"HTML(
2972 return featureInfoString.toUtf8();
2975 QByteArray QgsRenderer::convertFeatureInfoToText(
const QDomDocument &doc )
const
2977 QString featureInfoString;
2980 featureInfoString.append(
"GetFeatureInfo results\n" );
2981 featureInfoString.append(
"\n" );
2983 QDomNodeList layerList = doc.elementsByTagName( u
"Layer"_s );
2986 for (
int i = 0; i < layerList.size(); ++i )
2988 QDomElement layerElem = layerList.at( i ).toElement();
2990 featureInfoString.append(
"Layer '" + layerElem.attribute( u
"name"_s ) +
"'\n" );
2993 QDomNodeList featureNodeList = layerElem.elementsByTagName( u
"Feature"_s );
2994 QDomElement currentFeatureElement;
2996 if ( !featureNodeList.isEmpty() )
2998 for (
int j = 0; j < featureNodeList.size(); ++j )
3000 QDomElement featureElement = featureNodeList.at( j ).toElement();
3001 featureInfoString.append(
"Feature " + featureElement.attribute( u
"id"_s ) +
"\n" );
3004 QDomNodeList attributeNodeList = featureElement.elementsByTagName( u
"Attribute"_s );
3005 for (
int k = 0; k < attributeNodeList.size(); ++k )
3007 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
3008 featureInfoString.append( attributeElement.attribute( u
"name"_s ) +
" = '" + attributeElement.attribute( u
"value"_s ) +
"'\n" );
3014 QDomNodeList attributeNodeList = layerElem.elementsByTagName( u
"Attribute"_s );
3015 for (
int j = 0; j < attributeNodeList.size(); ++j )
3017 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
3018 QString value = attributeElement.attribute( u
"value"_s );
3019 if ( value.isEmpty() )
3021 value = u
"no data"_s;
3023 featureInfoString.append( attributeElement.attribute( u
"name"_s ) +
" = '" + value +
"'\n" );
3027 featureInfoString.append(
"\n" );
3030 return featureInfoString.toUtf8();
3033 QByteArray QgsRenderer::convertFeatureInfoToJson(
const QList<QgsMapLayer *> &layers,
const QDomDocument &doc,
const QgsCoordinateReferenceSystem &destCRS )
const
3035 json jsonCollection {
3036 {
"type",
"FeatureCollection" },
3037 {
"features", json::array() },
3041 const bool withDisplayName = mWmsParameters.withDisplayName();
3043 const QDomNodeList layerList = doc.elementsByTagName( u
"Layer"_s );
3044 for (
int i = 0; i < layerList.size(); ++i )
3046 const QDomElement layerElem = layerList.at( i ).toElement();
3047 const QString layerName = layerElem.attribute( u
"name"_s );
3049 QgsMapLayer *layer =
nullptr;
3050 for ( QgsMapLayer *l : layers )
3052 if ( mContext.layerNickname( *l ).compare( layerName ) == 0 )
3063 QStringList requestedWmsNames = mContext.acceptableLayersToRender().value( layer );
3064 requestedWmsNames.removeAll( layerName );
3065 QString requestedWmsName;
3066 if ( !requestedWmsNames.isEmpty() )
3068 requestedWmsName = requestedWmsNames.first();
3073 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
3078 const QDomNodeList featuresNode = layerElem.elementsByTagName( u
"Feature"_s );
3079 if ( featuresNode.isEmpty() )
3082 QMap<QgsFeatureId, QString> fidMap;
3083 QMap<QgsFeatureId, QString> fidDisplayNameMap;
3085 for (
int j = 0; j < featuresNode.size(); ++j )
3087 const QDomElement featureNode = featuresNode.at( j ).toElement();
3088 const QString fid = featureNode.attribute( u
"id"_s );
3091 if ( expression.isEmpty() )
3093 feature = vl->
getFeature( fid.toLongLong() );
3097 QgsFeatureRequest request { QgsExpression( expression ) };
3102 fidMap.insert( feature.
id(), fid );
3107 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
3108 for (
int k = 0; k < attrs.count(); k++ )
3110 const QDomElement elm = attrs.at( k ).toElement();
3111 if ( elm.attribute( u
"name"_s ).compare(
"geometry" ) == 0 )
3113 wkt = elm.attribute(
"value" );
3118 if ( !wkt.isEmpty() )
3126 if ( withDisplayName )
3128 QString displayName;
3129 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
3130 for (
int k = 0; k < attrs.count(); k++ )
3132 const QDomElement elm = attrs.at( k ).toElement();
3133 if ( elm.attribute( u
"name"_s ).compare(
"displayName" ) == 0 )
3135 displayName = elm.attribute(
"value" );
3139 fidDisplayNameMap.insert( feature.
id(), displayName );
3142 features << feature;
3145 if ( !attributes.isEmpty() )
3148 const QDomNodeList attributesNode = featureNode.elementsByTagName( u
"Attribute"_s );
3149 for (
int k = 0; k < attributesNode.size(); ++k )
3151 const QDomElement attributeElement = attributesNode.at( k ).toElement();
3152 const QString fieldName = attributeElement.attribute( u
"name"_s );
3153 attributes << feature.fieldNameIndex( fieldName );
3158 QgsJsonExporter exporter( vl );
3159 exporter.setAttributeDisplayName(
true );
3160 exporter.setAttributes( attributes );
3161 exporter.setIncludeGeometry( withGeometry );
3162 exporter.setTransformGeometries(
false );
3166 for (
const auto &feature : std::as_const( features ) )
3168 const QString
id = u
"%1.%2"_s.arg( layerName ).arg( fidMap.value( feature.id() ) );
3169 QVariantMap extraProperties;
3170 if ( withDisplayName )
3172 extraProperties.insert( u
"display_name"_s, fidDisplayNameMap.value( feature.id() ) );
3174 QVariantMap extraMembers;
3178 if ( !requestedWmsName.isEmpty() )
3183 jsonCollection[
"features"].push_back( exporter.exportFeatureToJsonObject( feature, extraProperties,
id, extraMembers ) );
3188 auto properties = json::object();
3189 const QDomNodeList attributesNode = layerElem.elementsByTagName( u
"Attribute"_s );
3190 for (
int j = 0; j < attributesNode.size(); ++j )
3192 const QDomElement attrElmt = attributesNode.at( j ).toElement();
3193 const QString name = attrElmt.attribute( u
"name"_s );
3195 QString value = attrElmt.attribute( u
"value"_s );
3196 if ( value.isEmpty() )
3201 properties[name.toStdString()] = value.toStdString();
3204 json jsonFeature = { {
"type",
"Feature" }, {
MEMBERNAME_FEATURETYPE, layerName.toStdString() }, {
"id", layerName.toStdString() }, {
"properties", properties } };
3206 if ( !requestedWmsName.isEmpty() )
3210 jsonCollection[
"features"].push_back( jsonFeature );
3215 return QByteArray::fromStdString( jsonCollection.dump( 2 ) );
3217 return QByteArray::fromStdString( jsonCollection.dump() );
3221 QDomElement QgsRenderer::createFeatureGML(
3222 const QgsFeature *feat, QgsVectorLayer *layer, QDomDocument &doc, QgsCoordinateReferenceSystem &crs,
const QgsMapSettings &mapSettings,
const QString &typeName,
bool withGeom,
int version, QStringList *attributes
3226 QDomElement typeNameElement = doc.createElement(
"qgs:" + typeName );
3233 typeNameElement.setAttribute( u
"fid"_s, u
"%1.%2"_s.arg( typeName, fid ) );
3235 QgsCoordinateTransform transform;
3236 if ( layer && layer->
crs() != crs )
3241 QgsGeometry geom = feat->
geometry();
3243 QgsExpressionContext expressionContext;
3249 QgsEditFormConfig editConfig { layer ? layer->
editFormConfig() : QgsEditFormConfig() };
3263 catch ( QgsCsException &e )
3269 QDomElement bbElem = doc.createElement( u
"gml:boundedBy"_s );
3270 QDomElement boxElem;
3282 boxElem.setAttribute( u
"srsName"_s, crs.
authid() );
3284 bbElem.appendChild( boxElem );
3285 typeNameElement.appendChild( bbElem );
3289 std::function<bool(
const QString &,
const QgsAttributeEditorElement * )> findAttributeInTree;
3290 findAttributeInTree = [&findAttributeInTree, &layer](
const QString &attributeName,
const QgsAttributeEditorElement *group ) ->
bool {
3291 const QgsAttributeEditorContainer *container =
dynamic_cast<const QgsAttributeEditorContainer *
>( group );
3294 const QList<QgsAttributeEditorElement *> children = container->
children();
3295 for (
const QgsAttributeEditorElement *child : children )
3297 switch ( child->type() )
3301 if ( findAttributeInTree( attributeName, child ) )
3309 if ( child->name() == attributeName )
3317 const QgsAttributeEditorRelation *relationEditor =
static_cast<const QgsAttributeEditorRelation *
>( child );
3318 if ( relationEditor )
3320 const QgsRelation &relation { relationEditor->
relation() };
3324 for (
const auto &idx : std::as_const( referencedFields ) )
3326 const QgsField f { layer->
fields().
at( idx ) };
3327 if ( f.
name() == attributeName )
3336 for (
const auto &idx : std::as_const( referencingFields ) )
3338 const QgsField f { layer->
fields().
at( idx ) };
3339 if ( f.
name() == attributeName )
3356 if ( withGeom && !geom.
isNull() )
3365 QDomElement geomElem = doc.createElement( u
"qgs:geometry"_s );
3366 QDomElement gmlElem;
3376 if ( !gmlElem.isNull() )
3380 gmlElem.setAttribute( u
"srsName"_s, crs.
authid() );
3382 geomElem.appendChild( gmlElem );
3383 typeNameElement.appendChild( geomElem );
3388 QgsAttributes featureAttributes = feat->
attributes();
3389 QgsFields fields = feat->
fields();
3390 for (
int i = 0; i < fields.
count(); ++i )
3392 QString attributeName = fields.
at( i ).
name();
3399 if ( attributes && !attributes->contains( attributeName ) )
3404 if ( honorFormConfig )
3407 if ( !editorContainer || !findAttributeInTree( attributeName, editorContainer ) )
3413 QDomElement fieldElem = doc.createElement(
"qgs:" + attributeName.replace(
' ',
'_' ) );
3414 QString fieldTextString = featureAttributes.at( i ).toString();
3419 QDomText fieldText = doc.createTextNode( fieldTextString );
3420 fieldElem.appendChild( fieldText );
3421 typeNameElement.appendChild( fieldElem );
3432 QDomElement fieldElem = doc.createElement( u
"qgs:maptip"_s );
3433 QDomText maptipText = doc.createTextNode( fieldTextString );
3434 fieldElem.appendChild( maptipText );
3435 typeNameElement.appendChild( fieldElem );
3439 return typeNameElement;
3442 QString QgsRenderer::replaceValueMapAndRelation( QgsVectorLayer *vl,
int idx,
const QVariant &attributeVal )
3446 QString value( fieldFormatter->
representValue( vl, idx, setup.
config(), QVariant(), attributeVal ) );
3448 if ( setup.
config().value( u
"AllowMulti"_s ).toBool() && value.startsWith(
'{'_L1 ) && value.endsWith(
'}'_L1 ) )
3450 value = value.mid( 1, value.size() - 2 );
3455 QgsRectangle QgsRenderer::featureInfoSearchRect( QgsVectorLayer *ml,
const QgsMapSettings &mapSettings,
const QgsRenderContext &rct,
const QgsPointXY &infoPoint )
const
3459 return QgsRectangle();
3462 double mapUnitTolerance = 0.0;
3465 if ( !mWmsParameters.polygonTolerance().isEmpty() && mWmsParameters.polygonToleranceAsInt() > 0 )
3471 mapUnitTolerance = mapSettings.
extent().
width() / 400.0;
3476 if ( !mWmsParameters.lineTolerance().isEmpty() && mWmsParameters.lineToleranceAsInt() > 0 )
3482 mapUnitTolerance = mapSettings.
extent().
width() / 200.0;
3487 if ( !mWmsParameters.pointTolerance().isEmpty() && mWmsParameters.pointToleranceAsInt() > 0 )
3493 mapUnitTolerance = mapSettings.
extent().
width() / 100.0;
3500 QgsRectangle mapRectangle( infoPoint.
x() - mapUnitTolerance, infoPoint.
y() - mapUnitTolerance, infoPoint.
x() + mapUnitTolerance, infoPoint.
y() + mapUnitTolerance );
3504 QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
3506 QList<QgsMapLayer *> highlightLayers;
3509 QString crs = mWmsParameters.crs();
3510 for (
const QgsWmsParametersHighlightLayer ¶m : params )
3513 QDomDocument sldDoc;
3517 if ( !sldDoc.setContent( param.mSld,
true, &errorMsg, &errorLine, &errorColumn ) )
3524 std::unique_ptr<QgsFeatureRenderer> renderer;
3525 QDomElement el = sldDoc.documentElement();
3535 QString url = typeName +
"?crs=" + crs;
3536 if ( !param.mLabel.isEmpty() )
3538 url +=
"&field=label:string";
3543 auto layer = std::make_unique<QgsVectorLayer>( url, param.mName,
"memory"_L1, options );
3550 QgsFeature fet( layer->
fields() );
3551 if ( !param.mLabel.isEmpty() )
3553 fet.setAttribute( 0, param.mLabel );
3556 QgsPalLayerSettings palSettings;
3561 palSettings.
dist = param.mLabelDistance;
3570 switch ( param.mGeom.type() )
3581 QgsPointXY pt = param.mGeom.asPoint();
3583 QVariant x( pt.
x() );
3586 QVariant y( pt.
y() );
3598 QgsGeometry point = param.mGeom.pointOnSurface();
3599 QgsPointXY pt = point.
asPoint();
3603 QVariant x( pt.
x() );
3607 QVariant y( pt.
y() );
3611 QVariant hali(
"Center" );
3615 QVariant vali(
"Half" );
3627 QgsTextFormat textFormat;
3628 QgsTextBufferSettings bufferSettings;
3630 if ( param.mColor.isValid() )
3632 textFormat.
setColor( param.mColor );
3635 if ( param.mSize > 0 )
3637 textFormat.
setSize( param.mSize );
3645 if ( !param.mFont.isEmpty() )
3647 textFormat.
setFont( param.mFont );
3650 if ( param.mBufferColor.isValid() )
3652 bufferSettings.
setColor( param.mBufferColor );
3655 if ( param.mBufferSize > 0 )
3658 bufferSettings.
setSize(
static_cast<double>( param.mBufferSize ) );
3664 QgsVectorLayerSimpleLabeling *simpleLabeling =
new QgsVectorLayerSimpleLabeling( palSettings );
3668 fet.setGeometry( param.mGeom );
3677 highlightLayers.append( layer.release() );
3681 mTemporaryLayers.append( highlightLayers );
3682 return highlightLayers;
3685 void QgsRenderer::removeTemporaryLayers()
3687 qDeleteAll( mTemporaryLayers );
3688 mTemporaryLayers.clear();
3691 QPainter *QgsRenderer::layersRendering(
const QgsMapSettings &mapSettings, QImage *image )
const
3693 QPainter *painter =
nullptr;
3695 QgsFeatureFilterProviderGroup filters;
3697#ifdef HAVE_SERVER_PYTHON_PLUGINS
3698 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
3701 QgsMapRendererJobProxy renderJob( mContext.settings().parallelRendering(), mContext.settings().maxThreads(), &filters );
3703 renderJob.render( mapSettings, image, mContext.socketFeedback() );
3704 painter = renderJob.takePainter();
3706 logRenderingErrors( renderJob.errors() );
3708 if ( !renderJob.errors().isEmpty() && !mContext.settings().ignoreRenderingErrors() )
3710 const QgsMapRendererJob::Error e = renderJob.errors().at( 0 );
3712 QString layerWMSName;
3713 QgsMapLayer *errorLayer = mProject->mapLayer( e.
layerID );
3716 layerWMSName = mContext.layerNickname( *errorLayer );
3719 QString errorMessage = u
"Rendering error : '%1'"_s.arg( e.
message );
3720 if ( !layerWMSName.isEmpty() )
3722 errorMessage = u
"Rendering error : '%1' in layer '%2'"_s.arg( e.
message, layerWMSName );
3724 throw QgsException( errorMessage );
3730 void QgsRenderer::setLayerOpacity( QgsMapLayer *layer,
int opacity )
const
3732 if ( opacity >= 0 && opacity <= 255 )
3734 switch ( layer->
type() )
3738 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
3743 QgsAbstractVectorLayerLabeling *labeling { vl->
labeling() };
3751 QgsRasterLayer *rl = qobject_cast<QgsRasterLayer *>( layer );
3752 QgsRasterRenderer *rasterRenderer = rl->
renderer();
3753 rasterRenderer->
setOpacity( opacity / 255. );
3759 QgsVectorTileLayer *vl = qobject_cast<QgsVectorTileLayer *>( layer );
3775 void QgsRenderer::setLayerFilter( QgsMapLayer *layer,
const QList<QgsWmsParametersFilter> &filters )
3779 QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( layer );
3780 QStringList expList;
3781 for (
const QgsWmsParametersFilter &filter : filters )
3786 QDomDocument filterXml;
3788 QXmlStreamReader xmlReader( filter.mFilter );
3789 xmlReader.addExtraNamespaceDeclaration( QXmlStreamNamespaceDeclaration( u
"fes"_s, u
"http://www.opengis.net/fes/2.0"_s ) );
3790 xmlReader.addExtraNamespaceDeclaration( QXmlStreamNamespaceDeclaration( u
"ogc"_s, u
"http://www.opengis.net/ogc"_s ) );
3791 if ( QDomDocument::ParseResult result = filterXml.setContent( &xmlReader, QDomDocument::ParseOption::UseNamespaceProcessing ); !result )
3793 throw QgsBadRequestException(
3795 u
"Filter string rejected. Error %1:%2 : %3. The XML string was: %4"_s.arg( QString::number( result.errorLine ), QString::number( result.errorColumn ), result.errorMessage, filter.mFilter )
3799 QDomElement filterElem = filterXml.firstChildElement();
3804 expList << filterExp->dump();
3810 if ( !testFilterStringSafety( filter.mFilter ) )
3812 throw QgsSecurityException(
3814 "The filter string %1"
3815 " has been rejected because of security reasons."
3816 " Note: Text strings have to be enclosed in single or double quotes."
3817 " A space between each word / special character is mandatory."
3818 " Allowed Keywords and special characters are"
3819 " IS,NOT,NULL,AND,OR,IN,=,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX%2."
3820 " Not allowed are semicolons in the filter expression."
3822 .arg( filter.mFilter, mContext.settings().allowedExtraSqlTokens().isEmpty() ? QString() : mContext.settings().allowedExtraSqlTokens().join(
',' ).prepend(
',' ) )
3826 QString newSubsetString = filter.mFilter;
3829 newSubsetString.prepend(
") AND (" );
3830 newSubsetString.append(
")" );
3831 newSubsetString.prepend( filteredLayer->
subsetString() );
3832 newSubsetString.prepend(
"(" );
3842 expList.append( dimensionFilter( filteredLayer ) );
3846 if ( expList.size() == 1 )
3850 else if ( expList.size() > 1 )
3852 exp = u
"( %1 )"_s.arg( expList.join(
" ) AND ( "_L1 ) );
3854 if ( !exp.isEmpty() )
3856 auto expression = std::make_unique<QgsExpression>( exp );
3860 mFeatureFilter.setFilter( filteredLayer, *expression );
3867 QStringList QgsRenderer::dimensionFilter( QgsVectorLayer *layer )
const
3869 QStringList expList;
3871 QgsMapLayerServerProperties *serverProperties =
static_cast<QgsMapLayerServerProperties *
>( layer->
serverProperties() );
3872 const QList<QgsMapLayerServerProperties::WmsDimensionInfo> wmsDims = serverProperties->
wmsDimensions();
3873 if ( wmsDims.isEmpty() )
3878 QMap<QString, QString> dimParamValues = mContext.parameters().dimensionValues();
3879 for (
const QgsMapLayerServerProperties::WmsDimensionInfo &dim : wmsDims )
3888 if ( fieldIndex == -1 )
3893 int endFieldIndex = -1;
3894 if ( !dim.endFieldName.isEmpty() )
3896 endFieldIndex = layer->
fields().
indexOf( dim.endFieldName );
3897 if ( endFieldIndex == -1 )
3903 if ( !dimParamValues.contains( dim.name.toUpper() ) )
3907 if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::AllValues )
3911 else if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::ReferenceValue )
3913 defValue = dim.referenceValue;
3918 QSet<QVariant> uniqueValues = layer->
uniqueValues( fieldIndex );
3919 if ( endFieldIndex != -1 )
3921 uniqueValues.unite( layer->
uniqueValues( endFieldIndex ) );
3924 QList<QVariant> values = qgis::setToList( uniqueValues );
3925 std::sort( values.begin(), values.end() );
3926 if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::MinValue )
3928 defValue = values.first();
3930 else if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::MaxValue )
3932 defValue = values.last();
3936 if ( endFieldIndex == -1 )
3942 QStringList expElems;
3951 expList << expElems.join(
' ' );
3957 QgsField dimField = layer->
fields().
at( fieldIndex );
3959 QString dimParamValue = dimParamValues[dim.name.toUpper()];
3961 QStringList dimExplist;
3963 QStringList dimValues = dimParamValue.split(
',' );
3964 for (
int i = 0; i < dimValues.size(); ++i )
3966 QString dimValue = dimValues[i];
3968 if ( dimValue.size() > 1 )
3970 dimValue = dimValue.trimmed();
3973 if ( dimValue.contains(
'/' ) )
3975 QStringList rangeValues = dimValue.split(
'/' );
3977 if ( rangeValues.size() != 2 )
3982 QVariant rangeMin = QVariant( rangeValues[0] );
3983 QVariant rangeMax = QVariant( rangeValues[1] );
3994 QStringList expElems;
3995 if ( endFieldIndex == -1 )
4030 dimExplist << expElems.join(
' ' );
4034 QVariant dimVariant = QVariant( dimValue );
4040 if ( endFieldIndex == -1 )
4049 QStringList expElems;
4058 dimExplist << expElems.join(
' ' );
4063 if ( dimExplist.size() == 1 )
4065 expList << dimExplist;
4067 else if ( dimExplist.size() > 1 )
4069 expList << u
"( %1 )"_s.arg( dimExplist.join(
" ) OR ( "_L1 ) );
4076 void QgsRenderer::setLayerSelection( QgsMapLayer *layer,
const QStringList &fids )
const
4080 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
4082 QgsFeatureRequest request;
4086 if ( selectedIds.empty() )
4097 void QgsRenderer::setLayerAccessControlFilter( QgsMapLayer *layer )
const
4099#ifdef HAVE_SERVER_PYTHON_PLUGINS
4106 void QgsRenderer::updateExtent(
const QgsMapLayer *layer, QgsMapSettings &mapSettings )
const
4109 QgsRectangle mapExtent = mapSettings.
extent();
4117 void QgsRenderer::annotationsRendering( QPainter *painter,
const QgsMapSettings &mapSettings )
const
4119 const QgsAnnotationManager *annotationManager = mProject->annotationManager();
4120 const QList<QgsAnnotation *> annotations = annotationManager->
annotations();
4124 renderContext.
setFeedback( mContext.socketFeedback() );
4126 for ( QgsAnnotation *annotation : annotations )
4128 if ( mContext.socketFeedback() && mContext.socketFeedback()->isCanceled() )
4130 if ( !annotation || !annotation->isVisible() )
4136 if ( annotation->hasFixedMapPosition() )
4138 QgsPointXY mapPos = annotation->mapPosition();
4139 if ( mapSettings.
destinationCrs() != annotation->mapPositionCrs() )
4144 mapPos = coordTransform.transform( mapPos );
4146 catch (
const QgsCsException &e )
4152 offsetX = devicePos.
x();
4153 offsetY = devicePos.
y();
4157 const QPointF relativePos = annotation->relativePosition();
4158 offsetX = mapSettings.
outputSize().width() * relativePos.x();
4159 offsetY = mapSettings.
outputSize().height() * relativePos.y();
4163 painter->translate( offsetX, offsetY );
4164 annotation->render( renderContext );
4169 QImage *QgsRenderer::scaleImage(
const QImage *image )
const
4174 QImage *scaledImage =
nullptr;
4175 const int width = mWmsParameters.widthAsInt();
4176 const int height = mWmsParameters.heightAsInt();
4177 if ( width != image->width() || height != image->height() )
4179 scaledImage =
new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
4187 QgsMapRendererJob::Errors::const_iterator it = errors.constBegin();
4188 for ( ; it != errors.constEnd(); ++it )
4190 QString msg = QString(
"Rendering error: %1" ).arg( it->message );
4191 if ( !it->layerID.isEmpty() )
4193 msg += QString(
" in layer %1" ).arg( it->layerID );
4199 void QgsRenderer::handlePrintErrors(
const QgsLayout *layout )
const
4206 QList<QgsLayoutItemMap *> mapList;
4210 QList<QgsLayoutItemMap *>::const_iterator mapIt = mapList.constBegin();
4211 for ( ; mapIt != mapList.constEnd(); ++mapIt )
4213 logRenderingErrors( ( *mapIt )->renderingErrors() );
4216 if ( mContext.settings().ignoreRenderingErrors() )
4221 mapIt = mapList.constBegin();
4222 for ( ; mapIt != mapList.constEnd(); ++mapIt )
4224 if ( !( *mapIt )->renderingErrors().isEmpty() )
4226 const QgsMapRendererJob::Error e = ( *mapIt )->renderingErrors().at( 0 );
4227 throw QgsException( u
"Rendering error : '%1' in layer %2"_s.arg( e.
message, e.
layerID ) );
4234 const bool useSld = !mContext.parameters().sldBody().isEmpty();
4236 for (
auto layer : layers )
4238 const QgsWmsParametersLayer param = mContext.parameters( *layer );
4240 if ( !mContext.layersToRender().contains( layer ) )
4245 if ( mContext.isExternalLayer( param.mNickname ) )
4249 setLayerOpacity( layer, param.mOpacity );
4256 setLayerSld( layer, mContext.sld( *layer ) );
4260 setLayerStyle( layer, mContext.style( *layer ) );
4265 setLayerOpacity( layer, param.mOpacity );
4270 setLayerFilter( layer, param.mFilter );
4275 setLayerAccessControlFilter( layer );
4280 setLayerSelection( layer, param.mSelection );
4283 if ( settings && mContext.updateExtent() )
4285 updateExtent( layer, *settings );
4291 layers = highlightLayers( mWmsParameters.highlightLayersParameters() ) << layers;
4295 void QgsRenderer::setLayerStyle( QgsMapLayer *layer,
const QString &style )
const
4297 if ( style.isEmpty() )
4309 void QgsRenderer::setLayerSld( QgsMapLayer *layer,
const QDomElement &sld )
const
4314 QString sldStyleName =
"__sld_style";
4315 while ( styles.contains( sldStyleName ) )
4317 sldStyleName.append(
'@' );
4325 QgsLegendSettings QgsRenderer::legendSettings()
4328 QgsLegendSettings settings = mWmsParameters.legendSettings();
4330 if ( !mWmsParameters.bbox().isEmpty() )
4332 QgsMapSettings mapSettings;
4334 std::unique_ptr<QImage> tmp( createImage( mContext.mapSize(
false ) ) );
4335 configureMapSettings( tmp.get(), mapSettings );
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'...
@ VisibleLayers
Synchronize to map layers. The legend will include layers which are included in the linked map only.
@ AllProjectLayers
Synchronize to all project layers.
@ Manual
No automatic synchronization of legend layers. The legend will be manually populated.
@ 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.
@ Critical
Critical/error 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)...
static const double DEFAULT_SEARCH_RADIUS_MM
Identify search radius in mm.
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)...
@ DisableTiledRasterLayerRenders
If set, then raster layers will not be drawn as separate tiles. This may improve the appearance in ex...
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ DrawSelection
Draw selection.
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.
virtual void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.
QList< QgsAnnotation * > annotations() const
Returns a list of all annotations contained in the manager.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
QString name() const
Returns the name of this element.
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...
A server filter to apply a dimension filter to a request.
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.
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.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
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.
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.
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.
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 convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Qgis::FieldConfigurationFlags configurationFlags
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).
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.
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.
@ RuleKey
Rule key of the node (QString).
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.
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.
@ ManualHtml
HTML content is manually set for the item.
@ Url
Using this mode item fetches its content via a url.
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.
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.
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 JSON export flags to jsonRenderFlags.
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
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 Q_INVOKABLE 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.
QList< QgsMapRendererJob::Error > Errors
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.
QStringList layerIds(bool expandGroupLayers=false) const
Returns the list of layer IDs which will be rendered in the map.
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 setSelectiveMaskingSourceSets(const QVector< QgsSelectiveMaskingSourceSet > &sets)
Sets a list of all selective masking source sets defined for the map.
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...
QString ellipsoid() const
Returns ellipsoid's acronym.
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.
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.
double y() const
Returns y value.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
double x() const
Returns x value.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
QgsMeshDatasetIndex activeVectorDatasetAtTime(const QgsDateTimeRange &timeRange, int group=-1) const
Returns dataset index from active vector group depending on the time range If the temporal properties...
void updateTriangularMesh(const QgsCoordinateTransform &transform=QgsCoordinateTransform())
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh.
QgsMeshDatasetIndex staticVectorDatasetIndex(int group=-1) const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
QList< int > enabledDatasetGroupsIndexes() const
Returns the list of indexes of enables dataset groups handled by the layer.
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset metadata.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMeshDatasetIndex datasetIndexAtTime(const QgsDateTimeRange &timeRange, int datasetGroupIndex) const
Returns dataset index from datasets group depending on the time range.
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, int valueIndex) const
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange, int group=-1) const
Returns dataset index from active scalar group depending on the time range.
QgsTriangularMesh * triangularMesh(double minimumTriangleSize=0) const
Returns triangular mesh (nullptr before rendering or calling to updateMesh).
QgsMeshDatasetIndex staticScalarDatasetIndex(int group=-1) const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
QString formatTime(double hours)
Returns (date) time in hours formatted to human readable form.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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.
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.
QgsMapThemeCollection * mapThemeCollection
QgsProjectMetadata metadata
QgsCoordinateTransformContext transformContext
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.
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.
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.
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.
QList< int > referencedFields
QgsVectorLayer * referencedLayer
QgsVectorLayer * referencingLayer
QList< int > referencingFields
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.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
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.
void setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Scoped object for temporary scaling of a QgsRenderContext for millimeter based rendering.
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 bool wmsHTMLFeatureInfoUseOnlyMaptip(const QgsProject &project)
Returns if only the maptip should be used for HTML feature info response so that the HTML response to...
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.
const QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > wmsDimensions() const
Returns the QGIS Server WMS Dimension list.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
@ 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.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
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.
T begin() const
Returns the beginning of the range.
T end() const
Returns the upper bound of the range.
bool isInstant() const
Returns true if the range consists only of a single instant.
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.
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.
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.
Represents a vector layer which manages a vector based dataset.
void setLabeling(QgsAbstractVectorLayerLabeling *labeling)
Sets labeling configuration.
Q_INVOKABLE 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,...
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.
Q_INVOKABLE Qgis::WkbType wkbType() const final
Returns the WKBType or WKBUnknown in case of error.
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.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QString displayExpression
QgsEditorWidgetSetup editorWidgetSetup(int index) const
Returns the editor widget setup for the field at the specified index.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, bool validateIds=false)
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 QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const final
Calculates a list of unique values contained within an attribute in the layer.
Q_INVOKABLE QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
static Q_INVOKABLE 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 Q_INVOKABLE 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 transparentAsBool() const
Returns TRANSPARENT parameter as a bool or its default value if not defined.
QString formatAsString() const
Returns FORMAT parameter as a string.
QgsWmsParametersComposerMap composerMapParameters(int mapId) const
Returns the requested parameters for a composer map parameter.
DxfFormatOption
Options for DXF format.
QColor backgroundColorAsColor() const
Returns BGCOLOR parameter as a QColor or its default value if not defined.
Format format() const
Returns format.
Format
Output format for the response.
Rendering context for the WMS renderer.
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
Median cut implementation.
constexpr const char * MEMBERNAME_QGIS_REQUESTEDWMSNAME
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
constexpr const char * MEMBERNAME_FEATURETYPE
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.
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.
Encapsulates the properties of a vector layer containing features that will be exported to the DXF fi...
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.
Qgis::LayoutRenderFlags 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.
Qgis::LayoutRenderFlags 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.
Qgis::LayoutRenderFlags 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.
QList< QgsWmsParametersLayer > mLayers
QList< QgsWmsParametersHighlightLayer > mHighlightLayers