76#include <QTemporaryFile>
79#include <nlohmann/json.hpp>
103 : mContext( context )
108 mWmsParameters.
dump();
113 removeTemporaryLayers();
119 std::unique_ptr<QgsWmsRestorer> restorer;
132 if ( !mWmsParameters.
bbox().isEmpty() )
136 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
137 configureMapSettings( tmp.get(), mapSettings );
143 context = configureDefaultRenderContext();
147 std::unique_ptr<QImage> image;
149 const QSizeF minSize = renderer.
minimumSize( &context );
150 const QSize size(
static_cast<int>( minSize.width() * dpmm ),
static_cast<int>( minSize.height() * dpmm ) );
155 image.reset( createImage( size ) );
158 QPainter painter( image.get() );
161 if ( painter.renderHints() & QPainter::SmoothPixmapTransform )
163 if ( painter.renderHints() & QPainter::LosslessImageRendering )
173 return image.release();
179 std::unique_ptr<QgsWmsRestorer> restorer;
193 std::unique_ptr<QImage> image( createImage( size ) );
197 std::unique_ptr<QPainter> painter;
198 painter.reset(
new QPainter( image.get() ) );
199 painter->setRenderHint( QPainter::Antialiasing,
true );
200 painter->scale( dpmm, dpmm );
211 nodeModel.
drawSymbol( settings, &ctx, size.height() / dpmm );
214 return image.release();
220 std::unique_ptr<QgsWmsRestorer> restorer;
236 void QgsRenderer::runHitTest(
const QgsMapSettings &mapSettings, HitTest &hitTest )
const
240 for (
const QString &
id : mapSettings.layerIds() )
257 runHitTestLayer( vl, usedSymbols, context );
263 std::unique_ptr< QgsFeatureRenderer > r( vl->
renderer()->
clone() );
265 r->startRender( context, vl->
fields() );
273 if ( moreSymbolsPerFeature )
275 for (
QgsSymbol *s : r->originalSymbolsForFeature( f, context ) )
281 r->stopRender( context );
290 QStringLiteral(
"The requested map size is too large" ) );
294 std::unique_ptr<QgsWmsRestorer> restorer;
304 std::unique_ptr<QPainter> painter;
305 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
308 configureMapSettings( image.get(), mapSettings );
315 runHitTest( mapSettings,
symbols );
323 std::unique_ptr<QgsWmsRestorer> restorer;
328 if ( templateName.isEmpty() )
352 QStringLiteral(
"The template has no pages" ) );
355 std::unique_ptr<QgsPrintLayout> layout( sourceLayout->
clone() );
359 QStringList atlasPk = mWmsParameters.
atlasPk();
360 if ( !atlasPk.isEmpty() )
362 atlas = layout->atlas();
363 if ( !atlas || !atlas->
enabled() )
367 QStringLiteral(
"The template has no atlas enabled" ) );
374 QStringLiteral(
"The atlas has no coverage layer" ) );
378 if ( atlasPk.size() == 1 && atlasPk.at( 0 ) == QLatin1String(
"*" ) )
382 if ( atlas->
count() > maxAtlasFeatures )
385 QString(
"The project configuration allows printing maximum %1 atlas features at a time" ).arg( maxAtlasFeatures ) );
391 if ( pkIndexes.size() == 0 )
393 QgsDebugMsgLevel( QStringLiteral(
"Atlas print: layer %1 has no primary key attributes" ).arg( cLayer->
name() ), 2 );
397 const int pkIndexesSize {std::max< int >( pkIndexes.size(), 1 )};
399 QStringList pkAttributeNames;
400 for (
int pkIndex : std::as_const( pkIndexes ) )
402 pkAttributeNames.append( cLayer->
fields().
at( pkIndex ).
name() );
405 const int nAtlasFeatures = atlasPk.size() / pkIndexesSize;
406 if ( nAtlasFeatures * pkIndexesSize != atlasPk.size() )
409 QStringLiteral(
"Wrong number of ATLAS_PK parameters" ) );
413 if ( nAtlasFeatures > maxAtlasFeatures )
416 QString(
"%1 atlas features have been requested, but the project configuration only allows printing %2 atlas features at a time" )
417 .arg( nAtlasFeatures ).arg( maxAtlasFeatures ) );
420 QString filterString;
421 int currentAtlasPk = 0;
423 for (
int i = 0; i < nAtlasFeatures; ++i )
427 filterString.append(
" OR " );
430 filterString.append(
"( " );
433 if ( pkAttributeNames.isEmpty() )
435 filterString.append( QStringLiteral(
"$id = %1" ).arg( atlasPk.at( currentAtlasPk ) ) );
440 for (
int j = 0; j < pkIndexes.size(); ++j )
444 filterString.append(
" AND " );
451 filterString.append(
" )" );
460 if ( !errorString.isEmpty() )
462 throw QgsException( QStringLiteral(
"An error occurred during the Atlas print: %1" ).arg( errorString ) );
475 std::unique_ptr<QImage> image(
new QImage() );
476 configureMapSettings( image.get(), mapSettings );
482 configurePrintLayout( layout.get(), mapSettings, atlas );
486 const QList<QgsMapLayer *> lyrs = mapSettings.
layers();
488#ifdef HAVE_SERVER_PYTHON_PLUGINS
489 mContext.accessControl()->resolveFilterFeatures( lyrs );
493 QHash<const QgsVectorLayer *, QStringList> fltrs;
498 fltrs.insert( vl, dimensionFilter( vl ) );
510 QTemporaryFile tempOutputFile( QDir::tempPath() +
'/' + QStringLiteral(
"XXXXXX.%1" ).arg( extension ) );
511 if ( !tempOutputFile.open() )
513 throw QgsException( QStringLiteral(
"Could not open temporary file for the GetPrint request." ) );
522 if ( !mWmsParameters.
dpi().isEmpty() )
525 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
527 exportSettings.
dpi = dpi;
540 atlasSvgExport.
exportToSvg( tempOutputFile.fileName(), exportSettings );
546 exporter.
exportToSvg( tempOutputFile.fileName(), exportSettings );
555 double dpi( layout->renderContext().dpi( ) );
556 if ( !mWmsParameters.
dpi().isEmpty() )
559 double _dpi = mWmsParameters.
dpi().toDouble( &ok );
563 exportSettings.
dpi = dpi;
569 QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
574 const QSize imageSize = QSize(
static_cast<int>( width.
length() * dpi / 25.4 ),
static_cast<int>( height.
length() * dpi / 25.4 ) );
576 const QString paramWidth = mWmsParameters.
width();
577 const QString paramHeight = mWmsParameters.
height();
582 if ( !paramWidth.isEmpty() && !paramHeight.isEmpty() )
584 exportSettings.
imageSize = QSize( paramWidth.toInt(), paramHeight.toInt() );
586 else if ( !paramWidth.isEmpty() && paramHeight.isEmpty() )
588 exportSettings.
imageSize = QSize( paramWidth.toInt(),
static_cast<double>( paramWidth.toInt() ) / imageSize.width() * imageSize.height() );
590 else if ( paramWidth.isEmpty() && !paramHeight.isEmpty() )
592 exportSettings.
imageSize = QSize(
static_cast<double>( paramHeight.toInt() ) / imageSize.height() * imageSize.width(), paramHeight.toInt() );
600 exportSettings.
pages.append( 0 );
608 atlasPngExport.
exportToImage( tempOutputFile.fileName(), exportSettings );
612 throw QgsServiceException( QStringLiteral(
"Bad request" ), QStringLiteral(
"Atlas error: empty atlas." ), QString(), 400 );
618 exporter.
exportToImage( tempOutputFile.fileName(), exportSettings );
626 if ( !mWmsParameters.
dpi().isEmpty() )
629 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
631 exportSettings.
dpi = dpi;
636 exportSettings.
rasterizeWholeImage = layout->customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
639 if ( requestMapScales.size() > 0 )
649 if ( exportThemes.size() > 0 )
677 exporter.
exportToPdf( tempOutputFile.fileName(), exportSettings );
688 handlePrintErrors( atlas->
layout() );
692 handlePrintErrors( layout.get() );
695 return tempOutputFile.readAll();
703 QList<QgsLayoutItemMap *> maps;
709 for (
const auto &map : std::as_const( maps ) )
715 if ( cMapParams.
mLayers.isEmpty() )
720 if ( !atlas || !map->atlasDriven() )
726 c->removeLayoutItem( map );
744 if ( cMapParams.
mScale > 0 )
746 map->setScale(
static_cast<double>( cMapParams.
mScale ) );
752 map->setMapRotation( cMapParams.
mRotation );
756 if ( !map->keepLayerSet() )
759 QList<QgsMapLayer *> layerSet;
761 for (
const auto &layer : std::as_const( cMapParams.mLayers ) )
765 QList<QgsMapLayer *> layersFromGroup;
767 const QList<QgsMapLayer *> cLayersFromGroup = mContext.
layersFromGroup( layer.mNickname );
768 for (
QgsMapLayer *layerFromGroup : cLayersFromGroup )
771 if ( ! layerFromGroup )
776 layersFromGroup.push_front( layerFromGroup );
779 if ( !layersFromGroup.isEmpty() )
781 layerSet.append( layersFromGroup );
793 setLayerStyle( mlayer, layer.mStyle );
798 std::reverse( layerSet.begin(), layerSet.end() );
803 QMap<QString, QString> layersStyle;
804 if ( map->followVisibilityPreset() )
815 const QString presetName = map->followVisibilityPresetName();
816 if ( layerSet.isEmpty() )
820 layerSet = map->layersToRender( &ex );
823 map->setFollowVisibilityPreset(
false );
827 for (
const auto &layerMapThemeRecord : std::as_const( mapThemeRecords ) )
829 if ( layerSet.contains( layerMapThemeRecord.layer() ) )
831 layersStyle.insert( layerMapThemeRecord.layer()->id(),
832 layerMapThemeRecord.layer()->styleManager()->style( layerMapThemeRecord.currentStyle ).xmlData() );
838 const QList< QgsMapLayer *> highlights = highlightLayers( cMapParams.
mHighlightLayers );
839 for (
const auto &hl : std::as_const( highlights ) )
841 layerSet.prepend( hl );
844 map->setLayers( layerSet );
845 map->setKeepLayerSet(
true );
849 if ( !layersStyle.isEmpty() )
851 map->setLayerStyleOverrides( layersStyle );
852 map->setKeepLayerStyles(
true );
859 map->grid()->setIntervalX(
static_cast<double>( cMapParams.
mGridX ) );
860 map->grid()->setIntervalY(
static_cast<double>( cMapParams.
mGridY ) );
865 QList<QgsLayoutItemLabel *> labels;
867 for (
const auto &label : std::as_const( labels ) )
870 const QString labelId = label->
id();
871 const QString labelParam = mWmsParameters.
layoutParameter( labelId, ok );
876 if ( labelParam.isEmpty() )
880 c->removeItem( label );
885 label->setText( labelParam );
889 QList<QgsLayoutItemHtml *> htmls;
891 for (
const auto &html : std::as_const( htmls ) )
893 if ( html->frameCount() == 0 )
898 const QString htmlId = htmlFrame->
id();
911 c->removeMultiFrame( html );
917 html->setUrl( newUrl );
923 QList<QgsLayoutItemLegend *> legends;
925 for (
const auto &legend : std::as_const( legends ) )
927 if ( legend->autoUpdateModel() )
937 legend->setAutoUpdateModel(
false );
941 QStringList layerSet;
942 QList<QgsMapLayer *> mapLayers;
943 if ( map->
layers().isEmpty() )
947 mapLayers = mProject->
mapLayers(
true ).values();
951 mapLayers = map->
layers();
953 const QList<QgsMapLayer *> layerList = mapLayers;
954 for (
const auto &layer : layerList )
955 layerSet << layer->id();
967 for (
const auto &layerId : layerIds )
974 if ( !layerSet.contains( layerId ) )
976 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
983 qobject_cast<QgsLayerTreeGroup *>( nodeLayer->
parent() )->removeChildNode( nodeLayer );
999 QStringLiteral(
"The requested map size is too large" ) );
1003 std::unique_ptr<QgsWmsRestorer> restorer;
1014 std::unique_ptr<QPainter> painter;
1015 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
1018 configureMapSettings( image.get(), mapSettings );
1024 painter.reset( layersRendering( mapSettings, *image ) );
1027 annotationsRendering( painter.get(), mapSettings );
1033 QImage *scaledImage = scaleImage( image.get() );
1035 image.reset( scaledImage );
1038 return image.release();
1049 QList< QgsDxfExport::DxfLayer > dxfLayers;
1061 int layerAttribute = -1;
1062 if ( attributes.size() > layerIdx )
1073 QString
crs = mWmsParameters.
crs();
1074 if (
crs.compare( QStringLiteral(
"CRS:84" ), Qt::CaseInsensitive ) == 0 )
1076 crs = QStringLiteral(
"EPSG:4326" );
1079 else if (
crs.isEmpty() )
1081 crs = QStringLiteral(
"EPSG:4326" );
1115 std::unique_ptr<QgsDxfExport> dxf = std::make_unique<QgsDxfExport>();
1116 dxf->setExtent( mapExtent );
1117 dxf->setDestinationCrs( outputCRS );
1118 dxf->addLayers( dxfLayers );
1120 dxf->setSymbologyExport( mWmsParameters.
dxfMode() );
1123 dxf->setSymbologyScale( mWmsParameters.
dxfScale() );
1126 dxf->setForce2d( mWmsParameters.
isForce2D() );
1127 QgsDxfExport::Flags flags;
1128 if ( mWmsParameters.
noMText() )
1131 dxf->setFlags( flags );
1139 if ( i < 0 || i > mapSettings.
outputSize().width() )
1147 if ( j < 0 || j > mapSettings.
outputSize().height() )
1172 const bool ijDefined = !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty();
1173 const bool xyDefined = !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty();
1174 const bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1175 const bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1177 if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
1181 if ( mWmsParameters.
j().isEmpty() )
1195 std::unique_ptr<QImage> outputImage( createImage( mContext.
mapSize() ) );
1198 std::unique_ptr<QgsWmsRestorer> restorer;
1203 bool mandatoryCrsParam =
true;
1204 if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.
crs().isEmpty() )
1206 mandatoryCrsParam =
false;
1212 configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
1228#ifdef HAVE_SERVER_PYTHON_PLUGINS
1229 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
1232 QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );
1237 ba = convertFeatureInfoToText( result );
1239 ba = convertFeatureInfoToHtml( result );
1241 ba = convertFeatureInfoToJson( layers, result );
1243 ba = result.toByteArray();
1248 QImage *QgsRenderer::createImage(
const QSize &size )
const
1250 std::unique_ptr<QImage> image;
1258 image = std::make_unique<QImage>( size, QImage::Format_ARGB32_Premultiplied );
1263 image = std::make_unique<QImage>( size, QImage::Format_RGB32 );
1268 if ( image->isNull() )
1270 throw QgsException( QStringLiteral(
"createImage: image could not be created, check for out of memory conditions" ) );
1273 const int dpm =
static_cast<int>( mContext.
dotsPerMm() * 1000.0 );
1274 image->setDotsPerMeterX( dpm );
1275 image->setDotsPerMeterY( dpm );
1277 return image.release();
1280 void QgsRenderer::configureMapSettings(
const QPaintDevice *paintDevice,
QgsMapSettings &mapSettings,
bool mandatoryCrsParam )
1284 throw QgsException( QStringLiteral(
"configureMapSettings: no paint device" ) );
1287 mapSettings.
setOutputSize( QSize( paintDevice->width(), paintDevice->height() ) );
1294 if ( !mWmsParameters.
bbox().isEmpty() && mapExtent.
isEmpty() )
1300 QString
crs = mWmsParameters.
crs();
1301 if (
crs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 )
1303 crs = QString(
"EPSG:4326" );
1306 else if (
crs.isEmpty() && !mandatoryCrsParam )
1308 crs = QString(
"EPSG:4326" );
1318 QgsWmsParameter parameter;
1360 else if ( backgroundColor.isValid() )
1383 const QString timeString { mWmsParameters.
dimensionValues().value( QStringLiteral(
"TIME" ), QString() ) };
1384 if ( ! timeString.isEmpty() )
1386 bool isValidTemporalRange {
true };
1389 const QDateTime dt { QDateTime::fromString( timeString, Qt::DateFormat::ISODateWithMs ) };
1402 isValidTemporalRange =
false;
1407 if ( isValidTemporalRange )
1417 QgsRenderContext QgsRenderer::configureDefaultRenderContext( QPainter *painter )
1430 QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers,
const QgsMapSettings &mapSettings,
1431 const QImage *outputImage,
const QString &version )
const
1435 bool ijDefined = ( !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty() );
1437 bool xyDefined = ( !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty() );
1439 bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1441 bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1444 if ( featureCount < 1 )
1449 int i = mWmsParameters.
iAsInt();
1450 int j = mWmsParameters.
jAsInt();
1451 if ( xyDefined && !ijDefined )
1453 i = mWmsParameters.
xAsInt();
1454 j = mWmsParameters.
yAsInt();
1458 if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
1460 i *= ( outputImage->width() /
static_cast<double>( width ) );
1461 j *= ( outputImage->height() /
static_cast<double>( height ) );
1465 std::unique_ptr<QgsRectangle> featuresRect;
1466 std::unique_ptr<QgsGeometry> filterGeom;
1467 std::unique_ptr<QgsPointXY> infoPoint;
1469 if ( i != -1 && j != -1 )
1472 infoPointToMapCoordinates( i, j, infoPoint.get(), mapSettings );
1474 else if ( filtersDefined )
1478 else if ( filterGeomDefined )
1483 QDomDocument result;
1484 const QDomNode header = result.createProcessingInstruction( QStringLiteral(
"xml" ), QStringLiteral(
"version=\"1.0\" encoding=\"UTF-8\"" ) );
1485 result.appendChild( header );
1487 QDomElement getFeatureInfoElement;
1491 getFeatureInfoElement = result.createElement( QStringLiteral(
"wfs:FeatureCollection" ) );
1492 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:wfs" ), QStringLiteral(
"http://www.opengis.net/wfs" ) );
1493 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1494 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1495 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
1496 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1497 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:qgs" ), QStringLiteral(
"http://qgis.org/gml" ) );
1498 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1499 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), QStringLiteral(
"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://qgis.org/gml" ) );
1504 if ( featureInfoElemName.isEmpty() )
1506 featureInfoElemName = QStringLiteral(
"GetFeatureInfoResponse" );
1509 if ( featureInfoElemNs.isEmpty() )
1511 getFeatureInfoElement = result.createElement( featureInfoElemName );
1515 getFeatureInfoElement = result.createElementNS( featureInfoElemNs, featureInfoElemName );
1519 if ( !featureInfoSchema.isEmpty() )
1521 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1522 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), featureInfoSchema );
1525 result.appendChild( getFeatureInfoElement );
1535 for (
const QString &queryLayer : queryLayers )
1537 bool validLayer =
false;
1538 bool queryableLayer =
true;
1539 for (
QgsMapLayer *layer : std::as_const( layers ) )
1545 if ( !queryableLayer )
1550 QDomElement layerElement;
1553 layerElement = getFeatureInfoElement;
1557 layerElement = result.createElement( QStringLiteral(
"Layer" ) );
1558 QString layerName = queryLayer;
1561 QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.constFind( layerName );
1562 if ( layerAliasIt != layerAliasMap.constEnd() )
1564 layerName = layerAliasIt.value();
1567 layerElement.setAttribute( QStringLiteral(
"name" ), layerName );
1568 getFeatureInfoElement.appendChild( layerElement );
1571 layerElement.setAttribute( QStringLiteral(
"id" ), layer->id() );
1577 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
1580 ( void )featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, featuresRect.get(), filterGeom.get() );
1586 QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
1595 QgsPointXY layerInfoPoint = mapSettings.mapToLayerCoordinates( layer, *( infoPoint.get() ) );
1602 layerElement = result.createElement( QStringLiteral(
"gml:featureMember" ) );
1603 getFeatureInfoElement.appendChild( layerElement );
1606 ( void )featureInfoFromRasterLayer( rasterLayer, mapSettings, &layerInfoPoint, result, layerElement, version );
1614 param.mValue = queryLayer;
1618 else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.
isValidGroup( queryLayer ) ) )
1621 param.mValue = queryLayer;
1623 bool hasGroupAndQueryable {
false };
1628 for (
const QString &ql : constNicks )
1632 const QList<QgsMapLayer *> constLayers { mContext.
layerGroups()[ql] };
1635 if ( ( ! ml->shortName().isEmpty() && ml->shortName() == queryLayer ) || ( ml->name() == queryLayer ) )
1641 hasGroupAndQueryable =
true;
1650 if ( ! hasGroupAndQueryable )
1658 if ( featuresRect && ! featuresRect->isNull() )
1662 QDomElement bBoxElem = result.createElement( QStringLiteral(
"gml:boundedBy" ) );
1663 QDomElement boxElem;
1665 if ( gmlVersion < 3 )
1677 boxElem.setAttribute( QStringLiteral(
"srsName" ),
crs.
authid() );
1679 bBoxElem.appendChild( boxElem );
1680 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1684 QDomElement bBoxElem = result.createElement( QStringLiteral(
"BoundingBox" ) );
1685 bBoxElem.setAttribute( QStringLiteral(
"CRS" ), mapSettings.destinationCrs().authid() );
1686 bBoxElem.setAttribute( QStringLiteral(
"minx" ),
qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1687 bBoxElem.setAttribute( QStringLiteral(
"maxx" ),
qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1688 bBoxElem.setAttribute( QStringLiteral(
"miny" ),
qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1689 bBoxElem.setAttribute( QStringLiteral(
"maxy" ),
qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
1690 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1696 convertFeatureInfoToSia2045( result );
1702 bool QgsRenderer::featureInfoFromVectorLayer(
QgsVectorLayer *layer,
1705 QDomDocument &infoDocument,
1706 QDomElement &layerElement,
1709 const QString &version,
1721 std::unique_ptr<QgsGeometry> layerFilterGeom;
1724 layerFilterGeom.reset(
new QgsGeometry( *filterGeom ) );
1738 searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
1740 else if ( layerFilterGeom )
1742 searchRect = layerFilterGeom->boundingBox();
1744 else if ( !mWmsParameters.
bbox().isEmpty() )
1746 searchRect = layerRect;
1753 int featureCounter = 0;
1772 if ( layerFilterGeom )
1774 fReq.
setFilterExpression( QString(
"intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
1779#ifdef HAVE_SERVER_PYTHON_PLUGINS
1780 mContext.accessControl()->filterFeatures( layer, fReq );
1782 QStringList attributes;
1783 for (
const QgsField &field : fields )
1785 attributes.append( field.name() );
1787 attributes = mContext.accessControl()->layerAttributes( layer, attributes );
1792 std::unique_ptr< QgsFeatureRenderer > r2( layer->
renderer() ? layer->
renderer()->
clone() : nullptr );
1795 r2->startRender( renderContext, layer->
fields() );
1798 bool featureBBoxInitialized =
false;
1807 if ( featureCounter > nFeatures )
1822 bool render = r2->willRenderFeature( feature, renderContext );
1835 if ( !featureBBoxInitialized && featureBBox->
isEmpty() )
1838 featureBBoxInitialized =
true;
1858 QDomElement elem = createFeatureGML(
1860#ifdef HAVE_SERVER_PYTHON_PLUGINS
1864 QDomElement featureMemberElem = infoDocument.createElement( QStringLiteral(
"gml:featureMember" ) );
1865 featureMemberElem.appendChild( elem );
1866 layerElement.appendChild( featureMemberElem );
1871 QDomElement featureElement = infoDocument.createElement( QStringLiteral(
"Feature" ) );
1873 layerElement.appendChild( featureElement );
1879 writeAttributesTabLayout( editConfig, layer, fields, featureAttributes, infoDocument, featureElement, renderContext
1880#ifdef HAVE_SERVER_PYTHON_PLUGINS
1887 for (
int i = 0; i < featureAttributes.count(); ++i )
1889 writeVectorLayerAttribute( i, layer, fields, featureAttributes, infoDocument, featureElement, renderContext
1890#ifdef HAVE_SERVER_PYTHON_PLUGINS
1899 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
1901 QDomElement maptipElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1902 maptipElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"maptip" ) );
1906 featureElement.appendChild( maptipElem );
1912 QDomElement displayElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1913 displayElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"displayName" ) );
1916 displayExpression.
prepare( &context );
1917 displayElem.setAttribute( QStringLiteral(
"value" ), displayExpression.
evaluate( &context ).toString() );
1918 featureElement.appendChild( displayElem );
1925 QDomElement bBoxElem = infoDocument.createElement( QStringLiteral(
"BoundingBox" ) );
1926 bBoxElem.setAttribute( version == QLatin1String(
"1.1.1" ) ?
"SRS" :
"CRS",
outputCrs.authid() );
1931 featureElement.appendChild( bBoxElem );
1947 if ( segmentizeWktGeometry )
1955 geom.
set( segmentizedGeom );
1959 QDomElement geometryElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1960 geometryElement.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"geometry" ) );
1961 geometryElement.setAttribute( QStringLiteral(
"value" ), geom.
asWkt( mContext.
precision() ) );
1962 geometryElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"derived" ) );
1963 featureElement.appendChild( geometryElement );
1970 r2->stopRender( renderContext );
1981 QString groupName = container->
name();
1982 QDomElement nameElem;
1984 if ( !groupName.isEmpty() )
1986 nameElem = doc.createElement( groupName );
1987 parentElem.appendChild( nameElem );
1990 const QList<QgsAttributeEditorElement *> children = container->
children();
1995 writeAttributesTabGroup( child, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext );
2005 writeVectorLayerAttribute( idx, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext, attributes );
2016 if ( !editorContainer )
2021 writeAttributesTabGroup( editorContainer, layer, fields, featureAttributes, doc, featureElem, renderContext, attributes );
2024 void QgsRenderer::writeVectorLayerAttribute(
int attributeIndex,
QgsVectorLayer *layer,
const QgsFields &fields,
QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem,
QgsRenderContext &renderContext, QStringList *attributes )
const
2026#ifndef HAVE_SERVER_PYTHON_PLUGINS
2027 Q_UNUSED( attributes );
2040#ifdef HAVE_SERVER_PYTHON_PLUGINS
2042 if ( attributes && !attributes->contains( fields.
at( attributeIndex ).
name() ) )
2049 QDomElement attributeElement = doc.createElement( QStringLiteral(
"Attribute" ) );
2050 attributeElement.setAttribute( QStringLiteral(
"name" ), attributeName );
2052 attributeElement.setAttribute( QStringLiteral(
"value" ),
2054 replaceValueMapAndRelation(
2055 layer, attributeIndex,
2056 featureAttributes[attributeIndex] ),
2059 featureElem.appendChild( attributeElement );
2062 bool QgsRenderer::featureInfoFromRasterLayer(
QgsRasterLayer *layer,
2065 QDomDocument &infoDocument,
2066 QDomElement &layerElement,
2067 const QString &version )
const
2087 :
Qgis::RasterIdentifyFormat::Value );
2099 .arg( layer->
name() ) );
2108 if ( !identifyResult.
isValid() )
2111 QMap<int, QVariant> attributes = identifyResult.
results();
2125 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
2128 feature.
setAttribute( index++, QString::number( it.value().toDouble() ) );
2131 QDomElement elem = createFeatureGML(
2132 &feature,
nullptr, infoDocument, layerCrs, mapSettings,
typeName,
false, gmlVersion,
nullptr );
2133 layerElement.appendChild( elem );
2137 const auto values = identifyResult.
results();
2138 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
2140 QVariant value = it.value();
2141 if ( value.type() == QVariant::Bool && !value.toBool() )
2147 if ( value.type() == QVariant::String )
2158 for (
const QgsFeature &feature : storeFeatures )
2160 QDomElement elem = createFeatureGML(
2161 &feature,
nullptr, infoDocument, layerCrs, mapSettings,
typeName,
false, gmlVersion,
nullptr );
2162 layerElement.appendChild( elem );
2172 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
2174 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2175 attributeElement.setAttribute( QStringLiteral(
"name" ), layer->
bandName( it.key() ) );
2180 value = QString::number( it.value().toDouble() );
2183 attributeElement.setAttribute( QStringLiteral(
"value" ), value );
2184 layerElement.appendChild( attributeElement );
2189 const auto values = identifyResult.
results();
2190 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
2192 QVariant value = it.value();
2193 if ( value.type() == QVariant::Bool && !value.toBool() )
2199 if ( value.type() == QVariant::String )
2209 for (
const QgsFeature &feature : storeFeatures )
2211 for (
const auto &fld : feature.fields() )
2213 const auto val { feature.
attribute( fld.name() )};
2214 if ( val.isValid() )
2216 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
2217 attributeElement.setAttribute( QStringLiteral(
"name" ), fld.name() );
2218 attributeElement.setAttribute( QStringLiteral(
"value" ), val.toString() );
2219 layerElement.appendChild( attributeElement );
2230 bool QgsRenderer::testFilterStringSafety(
const QString &filter )
const
2233 if ( filter.contains( QLatin1String(
";" ) ) )
2238#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
2239 QStringList tokens = filter.split(
' ', QString::SkipEmptyParts );
2241 QStringList tokens = filter.split(
' ', Qt::SkipEmptyParts );
2243 groupStringList( tokens, QStringLiteral(
"'" ) );
2244 groupStringList( tokens, QStringLiteral(
"\"" ) );
2246 for (
auto tokenIt = tokens.constBegin() ; tokenIt != tokens.constEnd(); ++tokenIt )
2249 if ( tokenIt->compare( QLatin1String(
"," ) ) == 0
2250 || tokenIt->compare( QLatin1String(
"(" ) ) == 0
2251 || tokenIt->compare( QLatin1String(
")" ) ) == 0
2252 || tokenIt->compare( QLatin1String(
"=" ) ) == 0
2253 || tokenIt->compare( QLatin1String(
"!=" ) ) == 0
2254 || tokenIt->compare( QLatin1String(
"<" ) ) == 0
2255 || tokenIt->compare( QLatin1String(
"<=" ) ) == 0
2256 || tokenIt->compare( QLatin1String(
">" ) ) == 0
2257 || tokenIt->compare( QLatin1String(
">=" ) ) == 0
2258 || tokenIt->compare( QLatin1String(
"%" ) ) == 0
2259 || tokenIt->compare( QLatin1String(
"IS" ), Qt::CaseInsensitive ) == 0
2260 || tokenIt->compare( QLatin1String(
"NOT" ), Qt::CaseInsensitive ) == 0
2261 || tokenIt->compare( QLatin1String(
"NULL" ), Qt::CaseInsensitive ) == 0
2262 || tokenIt->compare( QLatin1String(
"AND" ), Qt::CaseInsensitive ) == 0
2263 || tokenIt->compare( QLatin1String(
"OR" ), Qt::CaseInsensitive ) == 0
2264 || tokenIt->compare( QLatin1String(
"IN" ), Qt::CaseInsensitive ) == 0
2265 || tokenIt->compare( QLatin1String(
"LIKE" ), Qt::CaseInsensitive ) == 0
2266 || tokenIt->compare( QLatin1String(
"ILIKE" ), Qt::CaseInsensitive ) == 0
2267 || tokenIt->compare( QLatin1String(
"DMETAPHONE" ), Qt::CaseInsensitive ) == 0
2268 || tokenIt->compare( QLatin1String(
"SOUNDEX" ), Qt::CaseInsensitive ) == 0
2276 tokenIt->toDouble( &isNumeric );
2285 if ( *tokenIt == QLatin1String(
"''" ) )
2291 if ( tokenIt->size() > 2
2292 && ( *tokenIt )[0] == QChar(
'\'' )
2293 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'\'' )
2294 && ( *tokenIt )[1] != QChar(
'\'' )
2295 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'\'' ) )
2301 if ( tokenIt->size() > 2
2302 && ( *tokenIt )[0] == QChar(
'"' )
2303 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'"' )
2304 && ( *tokenIt )[1] != QChar(
'"' )
2305 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'"' ) )
2316 void QgsRenderer::groupStringList( QStringList &list,
const QString &groupString )
2319 bool groupActive =
false;
2320 int startGroup = -1;
2321 QString concatString;
2323 for (
int i = 0; i < list.size(); ++i )
2325 QString &
str = list[i];
2326 if (
str.startsWith( groupString ) )
2330 concatString.clear();
2335 if ( i != startGroup )
2337 concatString.append(
" " );
2339 concatString.append(
str );
2342 if (
str.endsWith( groupString ) )
2345 groupActive =
false;
2347 if ( startGroup != -1 )
2349 list[startGroup] = concatString;
2350 for (
int j = startGroup + 1; j <= endGroup; ++j )
2352 list.removeAt( startGroup + 1 );
2357 concatString.clear();
2363 void QgsRenderer::convertFeatureInfoToSia2045( QDomDocument &doc )
const
2365 QDomDocument SIAInfoDoc;
2366 QDomElement infoDocElement = doc.documentElement();
2367 QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement,
false ).toElement();
2368 SIAInfoDoc.appendChild( SIAInfoDocElement );
2370 QString currentAttributeName;
2371 QString currentAttributeValue;
2372 QDomElement currentAttributeElem;
2373 QString currentLayerName;
2374 QDomElement currentLayerElem;
2375 QDomNodeList layerNodeList = infoDocElement.elementsByTagName( QStringLiteral(
"Layer" ) );
2376 for (
int i = 0; i < layerNodeList.size(); ++i )
2378 currentLayerElem = layerNodeList.at( i ).toElement();
2379 currentLayerName = currentLayerElem.attribute( QStringLiteral(
"name" ) );
2381 QDomElement currentFeatureElem;
2383 QDomNodeList featureList = currentLayerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2384 if ( featureList.isEmpty() )
2387 QDomNodeList attributeList = currentLayerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2388 QDomElement rasterLayerElem;
2389 if ( !attributeList.isEmpty() )
2391 rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
2393 for (
int j = 0; j < attributeList.size(); ++j )
2395 currentAttributeElem = attributeList.at( j ).toElement();
2396 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
2397 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
2398 QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2399 QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2400 outAttributeElem.appendChild( outAttributeText );
2401 rasterLayerElem.appendChild( outAttributeElem );
2403 if ( !attributeList.isEmpty() )
2405 SIAInfoDocElement.appendChild( rasterLayerElem );
2411 QSet<QString> layerPropertyAttributes;
2412 QString currentLayerId = currentLayerElem.attribute( QStringLiteral(
"id" ) );
2413 if ( !currentLayerId.isEmpty() )
2418 QString WMSPropertyAttributesString = currentLayer->
customProperty( QStringLiteral(
"WMSPropertyAttributes" ) ).toString();
2419 if ( !WMSPropertyAttributesString.isEmpty() )
2421 QStringList propertyList = WMSPropertyAttributesString.split( QStringLiteral(
"//" ) );
2422 for (
auto propertyIt = propertyList.constBegin() ; propertyIt != propertyList.constEnd(); ++propertyIt )
2424 layerPropertyAttributes.insert( *propertyIt );
2430 QDomElement propertyRefChild;
2431 for (
int j = 0; j < featureList.size(); ++j )
2433 QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
2434 currentFeatureElem = featureList.at( j ).toElement();
2435 QDomNodeList attributeList = currentFeatureElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2437 for (
int k = 0; k < attributeList.size(); ++k )
2439 currentAttributeElem = attributeList.at( k ).toElement();
2440 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
2441 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
2442 if ( layerPropertyAttributes.contains( currentAttributeName ) )
2444 QDomElement propertyElem = SIAInfoDoc.createElement( QStringLiteral(
"property" ) );
2445 QDomElement identifierElem = SIAInfoDoc.createElement( QStringLiteral(
"identifier" ) );
2446 QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
2447 identifierElem.appendChild( identifierText );
2448 QDomElement valueElem = SIAInfoDoc.createElement( QStringLiteral(
"value" ) );
2449 QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
2450 valueElem.appendChild( valueText );
2451 propertyElem.appendChild( identifierElem );
2452 propertyElem.appendChild( valueElem );
2453 if ( propertyRefChild.isNull() )
2455 SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
2456 propertyRefChild = propertyElem;
2460 SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
2465 QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2466 QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2467 SIAAttributeElem.appendChild( SIAAttributeText );
2468 SIAFeatureElem.appendChild( SIAAttributeElem );
2471 SIAInfoDocElement.appendChild( SIAFeatureElem );
2478 QByteArray QgsRenderer::convertFeatureInfoToHtml(
const QDomDocument &doc )
const
2480 QString featureInfoString;
2483 featureInfoString.append(
"<HEAD>\n" );
2484 featureInfoString.append(
"<TITLE> GetFeatureInfo results </TITLE>\n" );
2485 featureInfoString.append(
"<META http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n" );
2486 featureInfoString.append(
"</HEAD>\n" );
2489 featureInfoString.append(
"<BODY>\n" );
2491 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2494 for (
int i = 0; i < layerList.size(); ++i )
2496 QDomElement layerElem = layerList.at( i ).toElement();
2498 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
2499 featureInfoString.append(
"<TR><TH width=25%>Layer</TH><TD>" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"</TD></TR>\n" );
2500 featureInfoString.append(
"</BR>" );
2503 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2504 QDomElement currentFeatureElement;
2506 if ( !featureNodeList.isEmpty() )
2508 for (
int j = 0; j < featureNodeList.size(); ++j )
2510 QDomElement featureElement = featureNodeList.at( j ).toElement();
2511 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
2512 featureInfoString.append(
"<TR><TH>Feature</TH><TD>" + featureElement.attribute( QStringLiteral(
"id" ) ) +
2516 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2517 for (
int k = 0; k < attributeNodeList.size(); ++k )
2519 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2520 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
2521 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
2524 featureInfoString.append(
"</TABLE>\n</BR>\n" );
2529 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2530 for (
int j = 0; j < attributeNodeList.size(); ++j )
2532 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2533 QString value = attributeElement.attribute( QStringLiteral(
"value" ) );
2534 if ( value.isEmpty() )
2536 value = QStringLiteral(
"no data" );
2538 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
2539 "</TH><TD>" + value +
"</TD></TR>\n" );
2543 featureInfoString.append(
"</TABLE>\n<BR></BR>\n" );
2547 featureInfoString.append(
"</BODY>\n" );
2549 return featureInfoString.toUtf8();
2552 QByteArray QgsRenderer::convertFeatureInfoToText(
const QDomDocument &doc )
const
2554 QString featureInfoString;
2557 featureInfoString.append(
"GetFeatureInfo results\n" );
2558 featureInfoString.append(
"\n" );
2560 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2563 for (
int i = 0; i < layerList.size(); ++i )
2565 QDomElement layerElem = layerList.at( i ).toElement();
2567 featureInfoString.append(
"Layer '" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"'\n" );
2570 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2571 QDomElement currentFeatureElement;
2573 if ( !featureNodeList.isEmpty() )
2575 for (
int j = 0; j < featureNodeList.size(); ++j )
2577 QDomElement featureElement = featureNodeList.at( j ).toElement();
2578 featureInfoString.append(
"Feature " + featureElement.attribute( QStringLiteral(
"id" ) ) +
"\n" );
2581 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2582 for (
int k = 0; k < attributeNodeList.size(); ++k )
2584 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2585 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2586 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2592 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2593 for (
int j = 0; j < attributeNodeList.size(); ++j )
2595 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2596 QString value = attributeElement.attribute( QStringLiteral(
"value" ) );
2597 if ( value.isEmpty() )
2599 value = QStringLiteral(
"no data" );
2601 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2606 featureInfoString.append(
"\n" );
2609 return featureInfoString.toUtf8();
2612 QByteArray QgsRenderer::convertFeatureInfoToJson(
const QList<QgsMapLayer *> &layers,
const QDomDocument &doc )
const
2616 {
"type",
"FeatureCollection" },
2617 {
"features", json::array() },
2621 const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2622 for (
int i = 0; i < layerList.size(); ++i )
2624 const QDomElement layerElem = layerList.at( i ).toElement();
2625 const QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
2630 if ( mContext.
layerNickname( *l ).compare( layerName ) == 0 )
2646 const QDomNodeList featuresNode = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2647 if ( featuresNode.isEmpty() )
2650 QMap<QgsFeatureId, QString> fidMap;
2652 for (
int j = 0; j < featuresNode.size(); ++j )
2654 const QDomElement featureNode = featuresNode.at( j ).toElement();
2655 const QString fid = featureNode.attribute( QStringLiteral(
"id" ) );
2658 if ( expression.isEmpty() )
2660 feature = vl->
getFeature( fid.toLongLong() );
2669 fidMap.insert( feature.
id(), fid );
2674 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
2675 for (
int k = 0; k < attrs.count(); k++ )
2677 const QDomElement elm = attrs.at( k ).toElement();
2678 if ( elm.attribute( QStringLiteral(
"name" ) ).compare(
"geometry" ) == 0 )
2680 wkt = elm.attribute(
"value" );
2685 if ( ! wkt.isEmpty() )
2691 features << feature;
2694 if ( !attributes.isEmpty() )
2697 const QDomNodeList attributesNode = featureNode.elementsByTagName( QStringLiteral(
"Attribute" ) );
2698 for (
int k = 0; k < attributesNode.size(); ++k )
2700 const QDomElement attributeElement = attributesNode.at( k ).toElement();
2701 const QString fieldName = attributeElement.
attribute( QStringLiteral(
"name" ) );
2703 attributes << feature.fieldNameIndex( fieldName );
2709 exporter.setAttributeDisplayName(
true );
2710 exporter.setAttributes( attributes );
2711 exporter.setIncludeGeometry( withGeometry );
2712 exporter.setTransformGeometries(
false );
2714 for (
const auto &feature : std::as_const( features ) )
2716 const QString
id = QStringLiteral(
"%1.%2" ).arg( layerName ).arg( fidMap.value( feature.id() ) );
2717 json[
"features"].push_back( exporter.exportFeatureToJsonObject( feature, QVariantMap(),
id ) );
2722 auto properties = json::object();
2723 const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2724 for (
int j = 0; j < attributesNode.size(); ++j )
2726 const QDomElement attrElmt = attributesNode.at( j ).toElement();
2727 const QString name = attrElmt.attribute( QStringLiteral(
"name" ) );
2729 QString value = attrElmt.attribute( QStringLiteral(
"value" ) );
2730 if ( value.isEmpty() )
2732 value = QStringLiteral(
"null" );
2735 properties[name.toStdString()] = value.toStdString();
2738 json[
"features"].push_back(
2740 {
"type",
"Feature" },
2741 {
"id", layerName.toStdString() },
2742 {
"properties", properties }
2748 return QByteArray::fromStdString( json.dump( 2 ) );
2750 return QByteArray::fromStdString( json.dump() );
2754 QDomElement QgsRenderer::createFeatureGML(
2763 QStringList *attributes )
const
2766 QDomElement typeNameElement = doc.createElement(
"qgs:" +
typeName );
2773 typeNameElement.setAttribute( QStringLiteral(
"fid" ), QStringLiteral(
"%1.%2" ).arg(
typeName, fid ) );
2776 if ( layer && layer->
crs() !=
crs )
2809 QDomElement bbElem = doc.createElement( QStringLiteral(
"gml:boundedBy" ) );
2810 QDomElement boxElem;
2822 boxElem.setAttribute( QStringLiteral(
"srsName" ),
crs.
authid() );
2824 bbElem.appendChild( boxElem );
2825 typeNameElement.appendChild( bbElem );
2837 QDomElement geomElem = doc.createElement( QStringLiteral(
"qgs:geometry" ) );
2838 QDomElement gmlElem;
2848 if ( !gmlElem.isNull() )
2852 gmlElem.setAttribute( QStringLiteral(
"srsName" ),
crs.
authid() );
2854 geomElem.appendChild( gmlElem );
2855 typeNameElement.appendChild( geomElem );
2862 for (
int i = 0; i < fields.
count(); ++i )
2864 QString attributeName = fields.
at( i ).
name();
2871 if ( attributes && !attributes->contains( attributeName ) )
2876 QDomElement fieldElem = doc.createElement(
"qgs:" + attributeName.replace(
' ',
'_' ) );
2877 QString fieldTextString = featureAttributes.at( i ).toString();
2882 QDomText fieldText = doc.createTextNode( fieldTextString );
2883 fieldElem.appendChild( fieldText );
2884 typeNameElement.appendChild( fieldElem );
2892 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
2895 QDomElement fieldElem = doc.createElement( QStringLiteral(
"qgs:maptip" ) );
2896 QDomText maptipText = doc.createTextNode( fieldTextString );
2897 fieldElem.appendChild( maptipText );
2898 typeNameElement.appendChild( fieldElem );
2902 return typeNameElement;
2905 QString QgsRenderer::replaceValueMapAndRelation(
QgsVectorLayer *vl,
int idx,
const QVariant &attributeVal )
2909 QString value( fieldFormatter->
representValue( vl, idx, setup.
config(), QVariant(), attributeVal ) );
2911 if ( setup.
config().value( QStringLiteral(
"AllowMulti" ) ).toBool() && value.startsWith( QLatin1Char(
'{' ) ) && value.endsWith( QLatin1Char(
'}' ) ) )
2913 value = value.mid( 1, value.size() - 2 );
2925 double mapUnitTolerance = 0.0;
2935 mapUnitTolerance = mapSettings.
extent().
width() / 400.0;
2947 mapUnitTolerance = mapSettings.
extent().
width() / 200.0;
2959 mapUnitTolerance = mapSettings.
extent().
width() / 100.0;
2963 QgsRectangle mapRectangle( infoPoint.
x() - mapUnitTolerance, infoPoint.
y() - mapUnitTolerance,
2964 infoPoint.
x() + mapUnitTolerance, infoPoint.
y() + mapUnitTolerance );
2968 QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
2970 QList<QgsMapLayer *> highlightLayers;
2973 QString
crs = mWmsParameters.
crs();
2974 for (
const QgsWmsParametersHighlightLayer ¶m : params )
2977 QDomDocument sldDoc;
2981 if ( !sldDoc.setContent( param.mSld,
true, &errorMsg, &errorLine, &errorColumn ) )
2993 std::unique_ptr<QgsFeatureRenderer> renderer;
2994 QDomElement el = sldDoc.documentElement();
3005 if ( ! param.mLabel.isEmpty() )
3007 url +=
"&field=label:string";
3012 std::unique_ptr<QgsVectorLayer> layer = std::make_unique<QgsVectorLayer>( url, param.mName, QLatin1String(
"memory" ), options );
3013 if ( !layer->isValid() )
3020 if ( ! param.mLabel.isEmpty() )
3022 fet.setAttribute( 0, param.mLabel );
3030 palSettings.
dist = param.mLabelDistance;
3039 switch ( param.mGeom.type() )
3052 QVariant x( pt.
x() );
3055 QVariant y( pt.
y() );
3072 QVariant x( pt.
x() );
3076 QVariant y( pt.
y() );
3080 QVariant hali(
"Center" );
3084 QVariant vali(
"Half" );
3099 if ( param.mColor.isValid() )
3101 textFormat.
setColor( param.mColor );
3104 if ( param.mSize > 0 )
3106 textFormat.
setSize( param.mSize );
3114 if ( ! param.mFont.isEmpty() )
3116 textFormat.
setFont( param.mFont );
3119 if ( param.mBufferColor.isValid() )
3121 bufferSettings.
setColor( param.mBufferColor );
3124 if ( param.mBufferSize > 0 )
3127 bufferSettings.
setSize(
static_cast<double>( param.mBufferSize ) );
3134 layer->setLabeling( simpleLabeling );
3135 layer->setLabelsEnabled(
true );
3137 fet.setGeometry( param.mGeom );
3141 layer->setRenderer( renderer.release() );
3144 if ( layer->isValid() )
3146 highlightLayers.append( layer.release() );
3150 mTemporaryLayers.append( highlightLayers );
3151 return highlightLayers;
3154 void QgsRenderer::removeTemporaryLayers()
3156 qDeleteAll( mTemporaryLayers );
3157 mTemporaryLayers.clear();
3160 QPainter *QgsRenderer::layersRendering(
const QgsMapSettings &mapSettings, QImage &image )
const
3162 QPainter *painter =
nullptr;
3166#ifdef HAVE_SERVER_PYTHON_PLUGINS
3167 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
3171 renderJob.render( mapSettings, &image );
3172 painter = renderJob.takePainter();
3174 if ( !renderJob.errors().isEmpty() )
3178 QString layerWMSName;
3185 QString errorMessage = QStringLiteral(
"Rendering error : '%1'" ).arg( e.
message );
3186 if ( ! layerWMSName.isEmpty() )
3188 errorMessage = QStringLiteral(
"Rendering error : '%1' in layer '%2'" ).arg( e.
message, layerWMSName );
3196 void QgsRenderer::setLayerOpacity(
QgsMapLayer *layer,
int opacity )
const
3198 if ( opacity >= 0 && opacity <= 255 )
3200 switch ( layer->
type() )
3219 rasterRenderer->
setOpacity( opacity / 255. );
3241 void QgsRenderer::setLayerFilter(
QgsMapLayer *layer,
const QList<QgsWmsParametersFilter> &filters )
3246 QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( layer );
3247 QStringList expList;
3248 for (
const QgsWmsParametersFilter &filter : filters )
3253 QDomDocument filterXml;
3255 if ( !filterXml.setContent( filter.mFilter,
true, &errorMsg ) )
3258 QStringLiteral(
"Filter string rejected. Error message: %1. The XML string was: %2" ).arg( errorMsg, filter.mFilter ) );
3260 QDomElement filterElem = filterXml.firstChildElement();
3265 expList << filterExp->dump();
3271 if ( !testFilterStringSafety( filter.mFilter ) )
3273 throw QgsSecurityException( QStringLiteral(
"The filter string %1"
3274 " has been rejected because of security reasons."
3275 " Note: Text strings have to be enclosed in single or double quotes."
3276 " A space between each word / special character is mandatory."
3277 " Allowed Keywords and special characters are"
3278 " IS,NOT,NULL,AND,OR,IN,=,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX%2."
3279 " Not allowed are semicolons in the filter expression." ).arg(
3282 mContext.settings().allowedExtraSqlTokens().join(
',' ).prepend(
',' ) ) );
3285 QString newSubsetString = filter.mFilter;
3288 newSubsetString.prepend(
") AND (" );
3289 newSubsetString.append(
")" );
3290 newSubsetString.prepend( filteredLayer->
subsetString() );
3291 newSubsetString.prepend(
"(" );
3295 QgsMessageLog::logMessage( QStringLiteral(
"Error setting subset string from filter for layer %1, filter: %2" ).arg( layer->
name(), newSubsetString ),
3296 QStringLiteral(
"Server" ),
3299 QStringLiteral(
"Filter not valid for layer %1: check the filter syntax and the field names." ).arg( layer->
name() ) );
3305 expList.append( dimensionFilter( filteredLayer ) );
3309 if ( expList.size() == 1 )
3313 else if ( expList.size() > 1 )
3315 exp = QStringLiteral(
"( %1 )" ).arg( expList.join( QLatin1String(
" ) AND ( " ) ) );
3317 if ( !exp.isEmpty() )
3319 std::unique_ptr<QgsExpression> expression(
new QgsExpression( exp ) );
3322 mFeatureFilter.
setFilter( filteredLayer, *expression );
3328 QStringList QgsRenderer::dimensionFilter(
QgsVectorLayer *layer )
const
3330 QStringList expList;
3333 const QList<QgsMapLayerServerProperties::WmsDimensionInfo> wmsDims = serverProperties->
wmsDimensions();
3334 if ( wmsDims.isEmpty() )
3349 if ( fieldIndex == -1 )
3354 int endFieldIndex = -1;
3355 if ( !dim.endFieldName.isEmpty() )
3357 endFieldIndex = layer->
fields().
indexOf( dim.endFieldName );
3358 if ( endFieldIndex == -1 )
3364 if ( !dimParamValues.contains( dim.name.toUpper() ) )
3368 if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::AllValues )
3372 else if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::ReferenceValue )
3374 defValue = dim.referenceValue;
3379 QSet<QVariant> uniqueValues = layer->
uniqueValues( fieldIndex );
3380 if ( endFieldIndex != -1 )
3382 uniqueValues.unite( layer->
uniqueValues( endFieldIndex ) );
3385 QList<QVariant> values = qgis::setToList( uniqueValues );
3386 std::sort( values.begin(), values.end() );
3387 if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::MinValue )
3389 defValue = values.first();
3391 else if ( dim.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::MaxValue )
3393 defValue = values.last();
3397 if ( endFieldIndex == -1 )
3403 QStringList expElems;
3408 expList << expElems.join(
' ' );
3416 QString dimParamValue = dimParamValues[dim.name.toUpper()];
3418 QStringList dimExplist;
3420 QStringList dimValues = dimParamValue.split(
',' );
3421 for (
int i = 0; i < dimValues.size(); ++i )
3423 QString dimValue = dimValues[i];
3425 if ( dimValue.size() > 1 )
3427 dimValue = dimValue.trimmed();
3430 if ( dimValue.contains(
'/' ) )
3432 QStringList rangeValues = dimValue.split(
'/' );
3434 if ( rangeValues.size() != 2 )
3439 QVariant rangeMin = QVariant( rangeValues[0] );
3440 QVariant rangeMax = QVariant( rangeValues[1] );
3451 QStringList expElems;
3452 if ( endFieldIndex == -1 )
3472 << QStringLiteral(
")" );
3474 dimExplist << expElems.join(
' ' );
3478 QVariant dimVariant = QVariant( dimValue );
3484 if ( endFieldIndex == -1 )
3493 QStringList expElems;
3498 dimExplist << expElems.join(
' ' );
3503 if ( dimExplist.size() == 1 )
3505 expList << dimExplist;
3507 else if ( dimExplist.size() > 1 )
3509 expList << QStringLiteral(
"( %1 )" ).arg( dimExplist.join( QLatin1String(
" ) OR ( " ) ) );
3516 void QgsRenderer::setLayerSelection(
QgsMapLayer *layer,
const QStringList &fids )
const
3526 if ( selectedIds.empty() )
3537 void QgsRenderer::setLayerAccessControlFilter(
QgsMapLayer *layer )
const
3539#ifdef HAVE_SERVER_PYTHON_PLUGINS
3557 void QgsRenderer::annotationsRendering( QPainter *painter,
const QgsMapSettings &mapSettings )
const
3560 const QList< QgsAnnotation * > annotations = annotationManager->
annotations();
3566 if ( !annotation || !annotation->isVisible() )
3572 if ( annotation->hasFixedMapPosition() )
3574 QgsPointXY mapPos = annotation->mapPosition();
3575 if ( mapSettings.
destinationCrs() != annotation->mapPositionCrs() )
3580 mapPos = coordTransform.transform( mapPos );
3588 offsetX = devicePos.
x();
3589 offsetY = devicePos.
y();
3593 const QPointF relativePos = annotation->relativePosition();
3594 offsetX = mapSettings.
outputSize().width() * relativePos.x();
3595 offsetY = mapSettings.
outputSize().height() * relativePos.y();
3599 painter->translate( offsetX, offsetY );
3600 annotation->render( renderContext );
3605 QImage *QgsRenderer::scaleImage(
const QImage *image )
const
3610 QImage *scaledImage =
nullptr;
3611 const int width = mWmsParameters.
widthAsInt();
3613 if ( width != image->width() || height != image->height() )
3615 scaledImage =
new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
3621 void QgsRenderer::handlePrintErrors(
const QgsLayout *layout )
const
3627 QList< QgsLayoutItemMap * > mapList;
3630 QList< QgsLayoutItemMap * >::const_iterator mapIt = mapList.constBegin();
3631 for ( ; mapIt != mapList.constEnd(); ++mapIt )
3633 if ( !( *mapIt )->renderingErrors().isEmpty() )
3645 for (
auto layer : layers )
3658 setLayerOpacity( layer, param.
mOpacity );
3665 setLayerSld( layer, mContext.
sld( *layer ) );
3669 setLayerStyle( layer, mContext.
style( *layer ) );
3674 setLayerOpacity( layer, param.
mOpacity );
3679 setLayerFilter( layer, param.
mFilter );
3684 setLayerAccessControlFilter( layer );
3689 setLayerSelection( layer, param.
mSelection );
3694 updateExtent( layer, *settings );
3704 void QgsRenderer::setLayerStyle(
QgsMapLayer *layer,
const QString &style )
const
3706 if ( style.isEmpty() )
3715 QStringLiteral(
"Style '%1' does not exist for layer '%2'" ).arg( style, layer->
name() ) );
3719 void QgsRenderer::setLayerSld(
QgsMapLayer *layer,
const QDomElement &sld )
const
3724 QString sldStyleName =
"__sld_style";
3725 while ( styles.contains( sldStyleName ) )
3727 sldStyleName.append(
'@' );
3740 if ( !mWmsParameters.
bbox().isEmpty() )
3744 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
3745 configureMapSettings( tmp.get(), mapSettings );
The Qgis class provides global constants for use throughout the application.
@ MapOrientation
Signifies that the AboveLine and BelowLine flags should respect the map's orientation rather than the...
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
@ Millimeters
Millimeters.
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ DragAndDrop
"Drag and drop" layout. Needs to be configured.
@ Warning
Warning message.
@ Info
Information message.
@ 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)...
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.
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
Abstract base class for all geometries.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
virtual void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.
Manages storage of a set of QgsAnnotation annotation objects.
QList< QgsAnnotation * > annotations() const
Returns a list of all annotations contained in the manager.
Abstract base class for annotation items which are drawn over a map.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
This is a container for attribute editors, used to group them visually in the attribute form if it is...
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
This is an abstract base class for any elements of a drag and drop form.
QString name() const
Returns the name of this element.
This element will load a field's widget onto the form.
Exception thrown in case of malformed request.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Qgis::DistanceUnit mapUnits
bool hasAxisInverted() const
Returns whether the axis order is inverted for the CRS compared to the order east/north (longitude/la...
Custom exception class for Coordinate Reference System related exceptions.
A server filter to apply a dimension filter to a request.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
@ FlagNoMText
Export text as TEXT elements. If not set, text will be exported as MTEXT elements.
Defines a QGIS exception class.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString expression() const
Returns the original, unmodified expression string.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value, QVariant::Type fieldType=QVariant::Type::Invalid)
Create an expression allowing to evaluate if a field is equal to a value.
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 quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
QVariant evaluate()
Evaluate the feature and return the result.
bool isValid() const
Checks if this expression is valid.
A filter filter provider grouping several filter providers.
QgsFeatureFilterProviderGroup & addProvider(const QgsFeatureFilterProvider *provider)
Add another filter provider to the group.
void setFilter(const QgsVectorLayer *layer, const QgsExpression &expression)
Set a filter for the given layer.
void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures) const override
Filter the features of the layer.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
@ 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.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Flags 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.
@ 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.
QgsCoordinateTransformContext transformContext() const
Returns the transform context, for use when a destinationCrs() has been set and reprojection is requi...
const QgsFeatureIds & filterFids() const
Returns the feature IDs that should be fetched.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
A container for features with the same fields and crs.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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.
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Qgis::FieldConfigurationFlags configurationFlags
Container of fields for a vector layer.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
int count() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
A geometry is the spatial representation of a feature.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static 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.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Handles exporting QgsFeature features to GeoJSON features.
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.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
Namespace with helper functions for layer tree operations.
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
bool beginRender() override
Called when rendering begins, before iteration commences.
bool setFilterExpression(const QString &expression, QString &errorString)
Sets the expression used for filtering features in the coverage layer.
bool first()
Seeks to the first feature, returning false if no feature was found.
QgsLayout * layout() override
Returns the layout associated with the iterator.
bool enabled() const
Returns whether the atlas generation is enabled.
int count() const override
Returns the number of features to iterate over.
void setFilterFeatures(bool filtered)
Sets whether features should be filtered in the coverage layer.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
int updateFeatures()
Requeries the current atlas coverage layer and applies filtering and sorting.
Handles rendering and exports of layouts to various formats.
ExportResult exportToSvg(const QString &filePath, const QgsLayoutExporter::SvgExportSettings &settings)
Exports the layout as an SVG to the filePath, using the specified export settings.
ExportResult exportToImage(const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings)
Exports the layout to the filePath, using the specified export settings.
ExportResult exportToPdf(const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings)
Exports the layout as a PDF to the filePath, using the specified export settings.
Base class for frame items, which form a layout multiframe item.
A layout multiframe subclass for HTML content.
A layout item subclass for text labels.
A layout item subclass for map legends.
Layout graphical items for displaying a map.
double scale() const
Returns the map scale.
QList< QgsMapLayer * > layers() const
Returns the stored layer set.
QString id() const
Returns the item's ID name.
Manages storage of a set of layouts.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
double length() const
Returns the length of the measurement.
int pageCount() const
Returns the number of pages in the collection.
Stores information relating to the current rendering settings for a layout.
void setFeatureFilterProvider(QgsFeatureFilterProvider *featureFilterProvider)
Sets feature filter provider to featureFilterProvider.
@ FlagDrawSelection
Draw selection.
@ FlagLosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ FlagDisableTiledRasterLayerRenders
If set, then raster layers will not be drawn as separate tiles. This may improve the appearance in ex...
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
double height() const
Returns the height of the size.
double width() const
Returns the width of the size.
static QVector< double > predefinedScales(const QgsLayout *layout)
Returns a list of predefined scales associated with a layout.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
Item model implementation based on layer tree model for layout legend.
The QgsLegendRenderer class handles automatic layout and rendering of legend.
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.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
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.
Manages QGIS Server properties for a map layer.
QStringList styles() const
Returns list of all defined style names.
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
bool addStyleFromLayer(const QString &name)
Add style by cloning the current one.
Base class for all map layer types.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
virtual QgsRectangle extent() const
Returns the extent of the layer.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsCoordinateReferenceSystem crs
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
@ Identifiable
If the layer is identifiable using the identify map tool and as a WMS layer.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
The QgsMapSettings class contains configuration for rendering of the map.
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 setOutputDpi(double dpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
const QgsMapToPixel & mapToPixel() const
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Sets the coordinates of the rectangle which should be rendered.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QList< QgsMapThemeCollection::MapThemeLayerRecord > layerRecords() const
Returns a list of records for all visible layer belonging to the theme.
QgsMapThemeCollection::MapThemeRecord mapThemeState(const QString &name) const
Returns the recorded state of a map theme.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
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 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 QDomElement rectangleToGMLEnvelope(QgsRectangle *env, QDomDocument &doc, int precision=17)
Exports the rectangle to GML3 Envelope.
static QgsExpression * expressionFromOgcFilter(const QDomElement &element, QgsVectorLayer *layer=nullptr)
Parse XML with OGC filter into QGIS expression.
static QDomElement rectangleToGMLBox(QgsRectangle *box, QDomDocument &doc, int precision=17)
Exports the rectangle to GML2 Box.
Contains settings for how a map layer will be labeled.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
Qgis::LabelPlacement placement
Label placement mode.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
int priority
Label priority.
Property
Data definable properties.
@ LabelRotation
Label rotation.
@ PositionY
Y-coordinate data defined label position.
@ PositionX
X-coordinate data defined label position.
@ Hali
Horizontal alignment for data defined label position (Left, Center, Right)
@ Vali
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
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.
QString fieldName
Name of field (or an expression) to use for label text.
A class to represent a 2D point.
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.
A class to describe the version of a project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsMapThemeCollection * mapThemeCollection
QgsAnnotationManager * annotationManager()
Returns pointer to the project's annotation manager.
QgsCoordinateTransformContext transformContext
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages print layouts, atlases and reports within the pro...
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns project's global labeling engine settings.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
virtual QgsRasterIdentifyResult identify(const QgsPointXY &point, Qgis::RasterIdentifyFormat format, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Identify raster value(s) found on the point position.
Raster identify results container.
bool isValid() const
Returns true if valid.
QMap< int, QVariant > results() const
Returns the identify results.
@ IdentifyValue
Numerical values.
@ IdentifyFeature
WMS GML -> feature.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
Represents a raster layer.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Raster renderer pipe that applies colors to a raster.
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double width() const
Returns the width of the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
bool isEmpty() const
Returns true if the rectangle has no area.
double height() const
Returns the height of the rectangle.
void invert()
Swap x/y coordinates in the rectangle.
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 setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
Scoped object for temporary scaling of a QgsRenderContext for millimeter based rendering.
Bad request error API exception.
static QgsDateTimeRange parseTemporalDateTimeInterval(const QString &interval)
Parses a datetime interval and returns a QgsDateTimeRange.
Exception base class for server exceptions.
int maxThreads() const
Returns the maximum number of threads to use.
QStringList allowedExtraSqlTokens() const
Returns the list of strings that represent the allowed extra SQL tokens accepted as components of a f...
bool parallelRendering() const
Returns parallel rendering setting.
const QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > wmsDimensions() const
Returns the QGIS Server WMS Dimension list.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
Abstract base class for all rendered symbols.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
Container for settings relating to a text buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
This is the base class for vector data providers.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
Basic implementation of the labeling interface.
Represents a vector layer which manages a vector based data sets.
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider,...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Q_INVOKABLE void selectByExpression(const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
Selects matching features using an expression.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QString displayExpression
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsEditorWidgetSetup editorWidgetSetup(int index) const
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection)
Selects matching features using a list of feature IDs.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
QgsAttributeList primaryKeyAttributes() const
Returns the list of attributes which make up the layer's primary keys.
QgsEditFormConfig editFormConfig
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
Implements a map layer that is dedicated to rendering of vector tiles.
static QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
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.
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model)
Returns the map legend as a JSON object.
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).
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
~QgsRenderer()
Destructor for QgsRenderer.
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.
double dxfScale() const
Returns the DXF SCALE parameter.
bool transparentAsBool() const
Returns TRANSPARENT parameter as a bool or its default value if not defined.
QString x() const
Returns X parameter or an empty string if not defined.
QString formatAsString() const
Returns FORMAT parameter as a string.
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
QgsWmsParametersComposerMap composerMapParameters(int mapId) const
Returns the requested parameters for a composer map parameter.
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
bool withGeometry() const
Returns if the client wants the feature info response with geometry information.
DxfFormatOption
Options for DXF format.
QString pointTolerance() const
Returns FI_POINT_TOLERANCE parameter or an empty string if not defined.
QString filterGeom() const
Returns the filter geometry found in FILTER_GEOM parameter.
QString composerTemplate() const
Returns TEMPLATE parameter or an empty string if not defined.
Format infoFormat() const
Returns infoFormat.
QString y() const
Returns Y parameter or an empty string if not defined.
void dump() const
Dumps parameters.
int pointToleranceAsInt() const
Returns FI_POINT_TOLERANCE parameter as an integer.
bool withMapTip() const
withMapTip
QString polygonTolerance() const
Returns FI_POLYGON_TOLERANCE parameter or an empty string if not defined.
QString i() const
Returns I parameter or an empty string if not defined.
bool pdfLosslessImageCompression() const
Returns true if images embedded in pdf must be compressed using a lossless algorithm.
int lineToleranceAsInt() const
Returns FI_LINE_TOLERANCE parameter as an integer.
QString lineTolerance() const
Returns FI_LINE_TOLERANCE parameter or an empty string if not defined.
QStringList pdfExportMapThemes() const
Returns map themes for GeoPDF export.
bool pdfUseOgcBestPracticeFormatGeoreferencing() const
Returns true if OGC best practice georeferencing shall be used.
QString j() const
Returns J parameter or an empty string if not defined.
int xAsInt() const
Returns X parameter as an int or its default value if not defined.
QString bbox() const
Returns BBOX if defined or an empty string.
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
QColor backgroundColorAsColor() const
Returns BGCOLOR parameter as a QColor or its default value if not defined.
Format format() const
Returns format.
QStringList atlasPk() const
Returns the ATLAS_PK parameter.
QList< QgsWmsParametersHighlightLayer > highlightLayersParameters() const
Returns parameters for each highlight layer.
int iAsInt() const
Returns I parameter as an int or its default value if not defined.
bool pdfAppendGeoreference() const
Returns true if georeference info shall be added to the pdf.
int polygonToleranceAsInt() const
Returns FI_POLYGON_TOLERANCE parameter as an integer.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
QString sldBody() const
Returns SLD_body if defined or an empty string.
bool pdfDisableTiledRasterRendering() const
Returns true if rasters shall be untiled in the pdf.
QString layoutParameter(const QString &id, bool &ok) const
Returns a layout parameter thanks to its id.
bool dxfUseLayerTitleAsName() const
Returns the DXF USE_TITLE_AS_LAYERNAME parameter.
bool pdfForceVectorOutput() const
Returns if pdf should be exported as vector.
bool pdfUseIso32000ExtensionFormatGeoreferencing() const
Returns true, if Iso32000 georeferencing shall be used.
QMap< QString, QString > dimensionValues() const
Returns the dimensions parameter.
bool withDisplayName() const
withDisplayName
int infoFormatVersion() const
Returns the infoFormat version for GML.
QgsLegendSettings legendSettings() const
Returns legend settings.
Qgis::TextRenderFormat pdfTextRenderFormat() const
Returns text render format for pdf export.
QStringList dxfLayerAttributes() const
Returns the DXF LAYERATTRIBUTES parameter.
bool writeGeoPdf() const
Returns if a GeoPDF shall be exported.
Qgis::FeatureSymbologyExport dxfMode() const
Returns the DXF MODE parameter.
QString height() const
Returns HEIGHT parameter or an empty string if not defined.
QString crs() const
Returns CRS or an empty string if none is defined.
int featureCountAsInt() const
Returns FEATURE_COUNT as an integer.
int yAsInt() const
Returns Y parameter as an int or its default value if not defined.
QMap< T, QString > formatOptions() const
Returns the format options for an output format.
Format
Output format for the response.
QString width() const
Returns WIDTH parameter or an empty string if not defined.
QStringList filters() const
Returns the list of filters found in FILTER parameter.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
int jAsInt() const
Returns J parameter as an int or its default value if not defined.
QVector< qreal > pdfPredefinedMapScales() const
Returns list of map scales.
bool pdfSimplifyGeometries() const
Returns if geometries shall to be simplified.
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
Rendering context for the WMS renderer.
QSize mapSize(bool aspectRatio=true) const
Returns the size (in pixels) of the map to render, according to width and height WMS parameters as we...
bool isExternalLayer(const QString &name) const
Returns true if the layer is an external layer, false otherwise.
bool isValidGroup(const QString &name) const
Returns true if name is a group.
QStringList flattenedQueryLayers(const QStringList &layerNames) const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
QgsMapLayer * layer(const QString &nickname) const
Returns the layer corresponding to the nickname, or a nullptr if not found or if the layer do not nee...
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
const QgsServerSettings & settings() const
Returns settings of the server.
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
QList< QgsMapLayer * > layersFromGroup(const QString &nickname) const
Returns the group's layers list corresponding to the nickname, or an empty list if not found.
QgsWmsParameters parameters() const
Returns WMS parameters.
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
QString style(const QgsMapLayer &layer) const
Returns a style's name for a specific layer.
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
double mapTileBuffer(int mapWidth) const
Returns the tile buffer in geographical units for the given map width in pixels.
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration.
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
const QgsProject * project() const
Returns the project.
int precision() const
Returns the precision to use according to the current configuration.
bool renderMapTiles() const
Returns true if WMS requests should use the QgsMapSettings::RenderMapTile flag, so that no visible ar...
RAII class to restore the rendering context configuration on destruction.
SERVER_EXPORT QString getExpressionFromServerFid(const QString &serverFid, const QgsVectorDataProvider *provider)
Returns the expression feature id based on primary keys.
SERVER_EXPORT QgsFeatureRequest updateFeatureRequestFromServerFids(QgsFeatureRequest &featureRequest, const QStringList &serverFids, const QgsVectorDataProvider *provider)
Returns the feature request based on feature ids build with primary keys.
SERVER_EXPORT QString getServerFid(const QgsFeature &feature, const QgsAttributeList &pkAttributes)
Returns the feature id based on primary keys.
SERVER_EXPORT QString wmsFeatureInfoSchema(const QgsProject &project)
Returns the schema URL for XML GetFeatureInfo request.
SERVER_EXPORT bool wmsInfoFormatSia2045(const QgsProject &project)
Returns if the info format is SIA20145.
SERVER_EXPORT QString wmsFeatureInfoDocumentElementNs(const QgsProject &project)
Returns the document element namespace for XML GetFeatureInfo request.
SERVER_EXPORT QStringList wmsRestrictedComposers(const QgsProject &project)
Returns the restricted composer list.
SERVER_EXPORT bool wmsFeatureInfoSegmentizeWktGeometry(const QgsProject &project)
Returns if the geometry has to be segmentize in GetFeatureInfo request.
SERVER_EXPORT bool wmsFeatureInfoUseAttributeFormSettings(const QgsProject &project)
Returns if feature form settings should be considered for the format of the feature info response.
SERVER_EXPORT QHash< QString, QString > wmsFeatureInfoLayerAliasMap(const QgsProject &project)
Returns the mapping between layer name and wms layer name for GetFeatureInfo request.
SERVER_EXPORT bool wmsFeatureInfoAddWktGeometry(const QgsProject &project)
Returns if the geometry is displayed as Well Known Text in GetFeatureInfo request.
SERVER_EXPORT double wmsDefaultMapUnitsPerMm(const QgsProject &project)
Returns the default number of map units per millimeters in case of the scale is not given.
SERVER_EXPORT QString wmsFeatureInfoDocumentElement(const QgsProject &project)
Returns the document element name for XML GetFeatureInfo request.
SERVER_EXPORT int wmsMaxAtlasFeatures(const QgsProject &project)
Returns the maximum number of atlas features which can be printed in a request.
Median cut implementation.
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
CONSTLATIN1STRING geoNone()
Constant that holds the string representation for "No ellips/No CRS".
#define Q_NOWARN_DEPRECATED_POP
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
#define FID_TO_STRING(fid)
QVector< QgsFeatureStore > QgsFeatureStoreList
QList< int > QgsAttributeList
#define QgsDebugMsgLevel(str, level)
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs
Layers and optional attribute index to split into multiple layers using attribute value as layer name...
QPainter * painter
Painter.
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.
Contains settings relating to exporting layouts to raster images.
QList< int > pages
List of specific pages to export, or an empty list to export all pages.
QSize imageSize
Manual size in pixels for output image.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
Contains settings relating to exporting layouts to PDF.
bool useIso32000ExtensionFormatGeoreferencing
true if ISO3200 extension format georeferencing should be used.
bool forceVectorOutput
Set to true to force vector object exports, even when the resultant appearance will differ from the l...
bool rasterizeWholeImage
Set to true to force whole layout to be rasterized while exporting.
QStringList exportThemes
Optional list of map themes to export as GeoPDF layer groups.
bool appendGeoreference
Indicates whether PDF export should append georeference data.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
bool writeGeoPdf
true if GeoPDF 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,...
bool useOgcBestPracticeFormatGeoreferencing
true if OGC "best practice" format georeferencing should be used.
Qgis::TextRenderFormat textRenderFormat
Text rendering format, which controls how text should be rendered in the export (e....
Contains settings relating to exporting layouts to SVG.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
Setting to define QGIS Server WMS Dimension.
Setting options for loading vector layers.
QList< QgsWmsParametersLayer > mLayers
QList< QgsWmsParametersHighlightLayer > mHighlightLayers
QList< QgsWmsParametersFilter > mFilter