70 #include <QStringList> 71 #include <QTemporaryFile> 74 #include <nlohmann/json.hpp> 104 mWmsParameters.
dump();
109 removeTemporaryLayers();
115 std::unique_ptr<QgsLayerRestorer> restorer;
127 std::unique_ptr<QImage> image;
130 const QSize size( static_cast<int>( minSize.width() * dpmm ), static_cast<int>( minSize.height() * dpmm ) );
131 image.reset( createImage( size ) );
134 std::unique_ptr<QPainter> painter;
135 painter.reset(
new QPainter( image.get() ) );
136 painter->setRenderHint( QPainter::Antialiasing,
true );
137 painter->scale( dpmm, dpmm );
143 return image.release();
149 std::unique_ptr<QgsLayerRestorer> restorer;
158 std::unique_ptr<QImage> image( createImage( size ) );
162 std::unique_ptr<QPainter> painter;
163 painter.reset(
new QPainter( image.get() ) );
164 painter->setRenderHint( QPainter::Antialiasing,
true );
165 painter->scale( dpmm, dpmm );
171 nodeModel.
drawSymbol( settings, &ctx, size.height() / dpmm );
174 return image.release();
181 for (
const QString &
id : mapSettings.
layerIds() )
198 runHitTestLayer( vl, usedSymbols, context );
204 std::unique_ptr< QgsFeatureRenderer > r( vl->
renderer()->
clone() );
206 r->startRender( context, vl->
fields() );
214 if ( moreSymbolsPerFeature )
216 for (
QgsSymbol *s : r->originalSymbolsForFeature( f, context ) )
222 r->stopRender( context );
231 QStringLiteral(
"The requested map size is too large" ) );
235 std::unique_ptr<QgsLayerRestorer> restorer;
245 std::unique_ptr<QPainter> painter;
246 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
249 configureMapSettings( image.get(), mapSettings );
256 runHitTest( mapSettings, symbols );
264 std::unique_ptr<QgsLayerRestorer> restorer;
269 if ( templateName.isEmpty() )
288 QStringLiteral(
"The template has no pages" ) );
291 std::unique_ptr<QgsPrintLayout> layout( sourceLayout->
clone() );
295 QStringList atlasPk = mWmsParameters.
atlasPk();
296 if ( !atlasPk.isEmpty() )
298 atlas = layout->atlas();
299 if ( !atlas || !atlas->enabled() )
303 QStringLiteral(
"The template has no atlas enabled" ) );
310 QStringLiteral(
"The atlas has no coverage layer" ) );
314 if ( atlasPk.size() == 1 && atlasPk.at( 0 ) == QStringLiteral(
"*" ) )
316 atlas->setFilterFeatures(
false );
317 atlas->updateFeatures();
318 if ( atlas->count() > maxAtlasFeatures )
321 QString(
"The project configuration allows printing maximum %1 atlas features at a time" ).arg( maxAtlasFeatures ) );
327 if ( pkIndexes.size() < 1 )
329 throw QgsException( QStringLiteral(
"An error occurred during the Atlas print" ) );
331 QStringList pkAttributeNames;
332 for (
int i = 0; i < pkIndexes.size(); ++i )
334 pkAttributeNames.append( cLayer->
fields()[pkIndexes.at( i )].name() );
337 int nAtlasFeatures = atlasPk.size() / pkIndexes.size();
338 if ( nAtlasFeatures * pkIndexes.size() != atlasPk.size() )
341 QStringLiteral(
"Wrong number of ATLAS_PK parameters" ) );
345 if ( nAtlasFeatures > maxAtlasFeatures )
348 QString(
"%1 atlas features have been requestet, but the project configuration only allows printing %2 atlas features at a time" )
349 .arg( nAtlasFeatures ).arg( maxAtlasFeatures ) );
352 QString filterString;
353 int currentAtlasPk = 0;
355 for (
int i = 0; i < nAtlasFeatures; ++i )
359 filterString.append(
" OR " );
362 filterString.append(
"( " );
364 for (
int j = 0; j < pkIndexes.size(); ++j )
368 filterString.append(
" AND " );
370 filterString.append( QString(
"\"%1\" = %2" ).arg( pkAttributeNames.at( j ) ).arg( atlasPk.at( currentAtlasPk ) ) );
374 filterString.append(
" )" );
377 atlas->setFilterFeatures(
true );
379 atlas->setFilterExpression( filterString, errorString );
380 if ( !errorString.isEmpty() )
382 throw QgsException( QStringLiteral(
"An error occurred during the Atlas print" ) );
394 std::unique_ptr<QImage> image(
new QImage() );
395 configureMapSettings( image.get(), mapSettings );
401 configurePrintLayout( layout.get(), mapSettings, atlas );
407 QTemporaryFile tempOutputFile( QDir::tempPath() +
'/' + QStringLiteral(
"XXXXXX.%1" ).arg( extension ) );
408 if ( !tempOutputFile.open() )
410 throw QgsException( QStringLiteral(
"Could not open temporary file for the GetPrint request." ) );
419 if ( !mWmsParameters.
dpi().isEmpty() )
422 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
424 exportSettings.
dpi = dpi;
431 atlas->beginRender();
435 atlasSvgExport.
exportToSvg( tempOutputFile.fileName(), exportSettings );
441 exporter.
exportToSvg( tempOutputFile.fileName(), exportSettings );
450 double dpi( layout->renderContext().dpi( ) );
451 if ( !mWmsParameters.
dpi().isEmpty() )
454 double _dpi = mWmsParameters.
dpi().toDouble( &ok );
458 exportSettings.
dpi = dpi;
462 QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
463 QgsLayoutMeasurement width( layout->convertFromLayoutUnits( layoutSize.width(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
464 QgsLayoutMeasurement height( layout->convertFromLayoutUnits( layoutSize.height(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
465 exportSettings.
imageSize = QSize( static_cast<int>( width.length() * dpi / 25.4 ), static_cast<int>( height.
length() * dpi / 25.4 ) );
467 exportSettings.
pages.append( 0 );
471 atlas->beginRender();
475 atlasPngExport.
exportToImage( tempOutputFile.fileName(), exportSettings );
481 exporter.
exportToImage( tempOutputFile.fileName(), exportSettings );
489 if ( !mWmsParameters.
dpi().isEmpty() )
492 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
494 exportSettings.
dpi = dpi;
499 exportSettings.
rasterizeWholeImage = layout->customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
505 exporter.
exportToPdf( atlas, tempOutputFile.fileName(), exportSettings, exportError );
509 exporter.exportToPdf( tempOutputFile.fileName(), exportSettings );
520 handlePrintErrors( atlas->layout() );
524 handlePrintErrors( layout.get() );
527 return tempOutputFile.readAll();
534 QList<QgsLayoutItemMap *> maps;
540 for (
const auto &map : qgis::as_const( maps ) )
545 if ( !atlasPrint || !map->atlasDriven() )
569 if ( cMapParams.
mScale > 0 )
571 map->setScale( static_cast<double>( cMapParams.
mScale ) );
577 map->setMapRotation( cMapParams.
mRotation );
581 if ( !map->keepLayerSet() )
585 map->setLayers( mapSettings.
layers() );
589 QList<QgsMapLayer *> layerSet;
590 for (
auto layer : cMapParams.
mLayers )
599 setLayerStyle( mlayer, layer.mStyle );
605 std::reverse( layerSet.begin(), layerSet.end() );
606 map->setLayers( layerSet );
608 map->setKeepLayerSet(
true );
614 map->grid()->setIntervalX( static_cast<double>( cMapParams.
mGridX ) );
615 map->grid()->setIntervalY( static_cast<double>( cMapParams.
mGridY ) );
620 QList<QgsLayoutItemLabel *> labels;
622 for (
const auto &label : qgis::as_const( labels ) )
625 const QString labelId = label->
id();
626 const QString labelParam = mWmsParameters.
layoutParameter( labelId, ok );
631 if ( labelParam.isEmpty() )
635 c->removeItem( label );
640 label->setText( labelParam );
644 QList<QgsLayoutItemHtml *> htmls;
646 for (
const auto &html : qgis::as_const( htmls ) )
648 if ( html->frameCount() == 0 )
653 const QString htmlId = htmlFrame->
id();
672 html->setUrl( newUrl );
678 QList<QgsLayoutItemLegend *> legends;
680 for (
const auto &legend : qgis::as_const( legends ) )
682 if ( legend->autoUpdateModel() )
692 legend->setAutoUpdateModel(
false );
696 QStringList layerSet;
697 const QList<QgsMapLayer *> layerList( map->
layers() );
698 for (
const auto &layer : layerList )
699 layerSet << layer->id();
711 for (
const auto &layerId : layerIds )
718 if ( !layerSet.contains( layerId ) )
743 QStringLiteral(
"The requested map size is too large" ) );
747 std::unique_ptr<QgsLayerRestorer> restorer;
758 std::unique_ptr<QPainter> painter;
759 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
762 configureMapSettings( image.get(), mapSettings );
768 painter.reset( layersRendering( mapSettings, *image ) );
771 annotationsRendering( painter.get() );
777 QImage *scaledImage = scaleImage( image.get() );
779 image.reset( scaledImage );
782 return image.release();
788 std::unique_ptr<QgsLayerRestorer> restorer;
797 QList< QgsDxfExport::DxfLayer > dxfLayers;
809 int layerAttribute = -1;
810 if ( attributes.size() > layerIdx )
824 if ( mWmsParameters.
dxfFormatOptions().contains( QgsWmsParameters::DxfFormatOption::SCALE ) )
835 if ( i < 0 || i > mapSettings.
outputSize().width() )
843 if ( j < 0 || j > mapSettings.
outputSize().height() )
868 const bool ijDefined = !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty();
869 const bool xyDefined = !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty();
870 const bool filtersDefined = !mWmsParameters.
filters().isEmpty();
871 const bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
873 if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
877 if ( mWmsParameters.
j().isEmpty() )
884 if ( infoFormat == QgsWmsParameters::Format::NONE )
891 std::unique_ptr<QImage> outputImage( createImage( mContext.
mapSize() ) );
894 std::unique_ptr<QgsLayerRestorer> restorer;
899 bool mandatoryCrsParam =
true;
900 if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.
crs().isEmpty() )
902 mandatoryCrsParam =
false;
908 configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
924 QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );
928 if ( infoFormat == QgsWmsParameters::Format::TEXT )
929 ba = convertFeatureInfoToText( result );
930 else if ( infoFormat == QgsWmsParameters::Format::HTML )
931 ba = convertFeatureInfoToHtml( result );
932 else if ( infoFormat == QgsWmsParameters::Format::JSON )
933 ba = convertFeatureInfoToJson( layers, result );
935 ba = result.toByteArray();
940 QImage *QgsRenderer::createImage(
const QSize &size )
const 942 std::unique_ptr<QImage> image;
950 image = qgis::make_unique<QImage>( size, QImage::Format_ARGB32_Premultiplied );
955 image = qgis::make_unique<QImage>( size, QImage::Format_RGB32 );
960 if ( image->isNull() )
962 throw QgsException( QStringLiteral(
"createImage: image could not be created, check for out of memory conditions" ) );
965 const int dpm =
static_cast<int>( mContext.
dotsPerMm() * 1000.0 );
966 image->setDotsPerMeterX( dpm );
967 image->setDotsPerMeterY( dpm );
969 return image.release();
972 void QgsRenderer::configureMapSettings(
const QPaintDevice *paintDevice,
QgsMapSettings &mapSettings,
bool mandatoryCrsParam )
const 976 throw QgsException( QStringLiteral(
"configureMapSettings: no paint device" ) );
979 mapSettings.
setOutputSize( QSize( paintDevice->width(), paintDevice->height() ) );
984 if ( !mWmsParameters.
bbox().isEmpty() && mapExtent.
isEmpty() )
990 QString
crs = mWmsParameters.
crs();
991 if ( crs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 )
993 crs = QString(
"EPSG:4326" );
996 else if ( crs.isEmpty() && !mandatoryCrsParam )
998 crs = QString(
"EPSG:4326" );
1050 else if ( backgroundColor.isValid() )
1070 QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers,
const QgsMapSettings &mapSettings,
1071 const QImage *outputImage,
const QString &version )
const 1075 bool ijDefined = ( !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty() );
1077 bool xyDefined = ( !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty() );
1079 bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1081 bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1084 if ( featureCount < 1 )
1089 int i = mWmsParameters.
iAsInt();
1090 int j = mWmsParameters.
jAsInt();
1091 if ( xyDefined && !ijDefined )
1093 i = mWmsParameters.
xAsInt();
1094 j = mWmsParameters.
yAsInt();
1098 if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
1100 i *= ( outputImage->width() /
static_cast<double>( width ) );
1101 j *= ( outputImage->height() /
static_cast<double>( height ) );
1105 std::unique_ptr<QgsRectangle> featuresRect;
1106 std::unique_ptr<QgsGeometry> filterGeom;
1107 std::unique_ptr<QgsPointXY> infoPoint;
1109 if ( i != -1 && j != -1 )
1112 infoPointToMapCoordinates( i, j, infoPoint.get(), mapSettings );
1114 else if ( filtersDefined )
1118 else if ( filterGeomDefined )
1123 QDomDocument result;
1125 QDomElement getFeatureInfoElement;
1127 if ( infoFormat == QgsWmsParameters::Format::GML )
1129 getFeatureInfoElement = result.createElement( QStringLiteral(
"wfs:FeatureCollection" ) );
1130 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:wfs" ), QStringLiteral(
"http://www.opengis.net/wfs" ) );
1131 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1132 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1133 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
1134 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1135 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:qgs" ), QStringLiteral(
"http://qgis.org/gml" ) );
1136 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1137 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" ) );
1142 if ( featureInfoElemName.isEmpty() )
1144 featureInfoElemName = QStringLiteral(
"GetFeatureInfoResponse" );
1147 if ( featureInfoElemNs.isEmpty() )
1149 getFeatureInfoElement = result.createElement( featureInfoElemName );
1153 getFeatureInfoElement = result.createElementNS( featureInfoElemNs, featureInfoElemName );
1157 if ( !featureInfoSchema.isEmpty() )
1159 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1160 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), featureInfoSchema );
1163 result.appendChild( getFeatureInfoElement );
1173 for (
const QString &queryLayer : queryLayers )
1175 bool validLayer =
false;
1176 bool queryableLayer =
true;
1177 for (
QgsMapLayer *layer : qgis::as_const( layers ) )
1183 if ( !queryableLayer )
1188 QDomElement layerElement;
1189 if ( infoFormat == QgsWmsParameters::Format::GML )
1191 layerElement = getFeatureInfoElement;
1195 layerElement = result.createElement( QStringLiteral(
"Layer" ) );
1196 QString layerName = queryLayer;
1199 QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.constFind( layerName );
1200 if ( layerAliasIt != layerAliasMap.constEnd() )
1202 layerName = layerAliasIt.value();
1205 layerElement.setAttribute( QStringLiteral(
"name" ), layerName );
1206 getFeatureInfoElement.appendChild( layerElement );
1209 layerElement.setAttribute( QStringLiteral(
"id" ), layer->id() );
1218 ( void )featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, featuresRect.get(), filterGeom.get() );
1238 if ( infoFormat == QgsWmsParameters::Format::GML )
1240 layerElement = result.createElement( QStringLiteral(
"gml:featureMember" ) );
1241 getFeatureInfoElement.appendChild( layerElement );
1244 ( void )featureInfoFromRasterLayer( rasterLayer, mapSettings, &layerInfoPoint, result, layerElement, version );
1252 param.
mValue = queryLayer;
1256 else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.
isValidGroup( queryLayer ) ) )
1259 param.
mValue = queryLayer;
1261 bool hasGroupAndQueryable {
false };
1266 for (
const auto &ql : constNicks )
1270 const auto &constLayers { mContext.
layerGroups()[ql] };
1271 for (
const auto &ml : constLayers )
1273 if ( ( ! ml->shortName().isEmpty() && ml->shortName() == queryLayer ) || ( ml->name() == queryLayer ) )
1279 hasGroupAndQueryable =
true;
1288 if ( ! hasGroupAndQueryable )
1298 if ( infoFormat == QgsWmsParameters::Format::GML )
1300 QDomElement bBoxElem = result.createElement( QStringLiteral(
"gml:boundedBy" ) );
1301 QDomElement boxElem;
1303 if ( gmlVersion < 3 )
1313 if ( crs.isValid() )
1315 boxElem.setAttribute( QStringLiteral(
"srsName" ), crs.authid() );
1317 bBoxElem.appendChild( boxElem );
1318 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1322 QDomElement bBoxElem = result.createElement( QStringLiteral(
"BoundingBox" ) );
1324 bBoxElem.setAttribute( QStringLiteral(
"minx" ),
qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1325 bBoxElem.setAttribute( QStringLiteral(
"maxx" ),
qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1326 bBoxElem.setAttribute( QStringLiteral(
"miny" ),
qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1327 bBoxElem.setAttribute( QStringLiteral(
"maxy" ),
qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
1328 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1332 if ( sia2045 && infoFormat == QgsWmsParameters::Format::XML )
1334 convertFeatureInfoToSia2045( result );
1340 bool QgsRenderer::featureInfoFromVectorLayer(
QgsVectorLayer *layer,
1343 QDomDocument &infoDocument,
1344 QDomElement &layerElement,
1347 const QString &version,
1359 std::unique_ptr<QgsGeometry> layerFilterGeom;
1362 layerFilterGeom.reset(
new QgsGeometry( *filterGeom ) );
1376 searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
1378 else if ( layerFilterGeom )
1380 searchRect = layerFilterGeom->boundingBox();
1382 else if ( !mWmsParameters.
bbox().isEmpty() )
1384 searchRect = layerRect;
1391 int featureCounter = 0;
1398 bool hasGeometry = addWktGeometry || featureBBox || layerFilterGeom;
1411 if ( layerFilterGeom )
1413 fReq.
setFilterExpression( QString(
"intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
1416 #ifdef HAVE_SERVER_PYTHON_PLUGINS 1417 mContext.accessControl()->filterFeatures( layer, fReq );
1419 QStringList attributes;
1420 for (
const QgsField &field : fields )
1422 attributes.append( field.name() );
1424 attributes = mContext.accessControl()->layerAttributes( layer, attributes );
1429 std::unique_ptr< QgsFeatureRenderer > r2( layer->
renderer() ? layer->
renderer()->
clone() : nullptr );
1432 r2->startRender( renderContext, layer->
fields() );
1435 bool featureBBoxInitialized =
false;
1444 if ( featureCounter > nFeatures )
1459 bool render = r2->willRenderFeature( feature, renderContext );
1472 if ( !featureBBoxInitialized && featureBBox->
isEmpty() )
1475 featureBBoxInitialized =
true;
1490 if ( mWmsParameters.
infoFormat() == QgsWmsParameters::Format::GML )
1495 QDomElement elem = createFeatureGML(
1496 &feature, layer, infoDocument, outputCrs, mapSettings, typeName, withGeom, gmlVersion
1497 #ifdef HAVE_SERVER_PYTHON_PLUGINS
1501 QDomElement featureMemberElem = infoDocument.createElement( QStringLiteral(
"gml:featureMember" ) );
1502 featureMemberElem.appendChild( elem );
1503 layerElement.appendChild( featureMemberElem );
1508 QDomElement featureElement = infoDocument.createElement( QStringLiteral(
"Feature" ) );
1510 layerElement.appendChild( featureElement );
1514 for (
int i = 0; i < featureAttributes.count(); ++i )
1517 if ( excludedAttributes.contains( fields.at( i ).name() ) )
1521 #ifdef HAVE_SERVER_PYTHON_PLUGINS 1523 if ( !attributes.contains( fields.at( i ).name() ) )
1532 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1533 attributeElement.setAttribute( QStringLiteral(
"name" ), attributeName );
1535 attributeElement.setAttribute( QStringLiteral(
"value" ),
1537 replaceValueMapAndRelation(
1539 featureAttributes[i] ),
1542 featureElement.appendChild( attributeElement );
1547 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
1549 QDomElement maptipElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1550 maptipElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"maptip" ) );
1552 featureElement.appendChild( maptipElem );
1558 QDomElement bBoxElem = infoDocument.createElement( QStringLiteral(
"BoundingBox" ) );
1559 bBoxElem.setAttribute( version == QLatin1String(
"1.1.1" ) ?
"SRS" :
"CRS", outputCrs.
authid() );
1564 featureElement.appendChild( bBoxElem );
1580 if ( segmentizeWktGeometry )
1588 geom.
set( segmentizedGeom );
1592 QDomElement geometryElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1593 geometryElement.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"geometry" ) );
1594 geometryElement.setAttribute( QStringLiteral(
"value" ), geom.
asWkt( mContext.
precision() ) );
1595 geometryElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"derived" ) );
1596 featureElement.appendChild( geometryElement );
1603 r2->stopRender( renderContext );
1609 bool QgsRenderer::featureInfoFromRasterLayer(
QgsRasterLayer *layer,
1612 QDomDocument &infoDocument,
1613 QDomElement &layerElement,
1614 const QString &version )
const 1633 QgsRaster::IdentifyFormat::IdentifyFormatFeature :
1634 QgsRaster::IdentifyFormat::IdentifyFormatValue };
1641 if ( ! transform.isValid() )
1646 .arg( layer->
name() ) );
1655 if ( !identifyResult.
isValid() )
1658 QMap<int, QVariant> attributes = identifyResult.
results();
1660 if ( mWmsParameters.
infoFormat() == QgsWmsParameters::Format::GML )
1672 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
1675 feature.
setAttribute( index++, QString::number( it.value().toDouble() ) );
1678 QDomElement elem = createFeatureGML(
1679 &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
1680 layerElement.appendChild( elem );
1684 const auto values = identifyResult.
results();
1685 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1687 QVariant value = it.value();
1688 if ( value.type() == QVariant::Bool && !value.toBool() )
1694 if ( value.type() == QVariant::String )
1705 for (
const QgsFeature &feature : storeFeatures )
1707 QDomElement elem = createFeatureGML(
1708 &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
1709 layerElement.appendChild( elem );
1719 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
1721 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1722 attributeElement.setAttribute( QStringLiteral(
"name" ), layer->
bandName( it.key() ) );
1723 attributeElement.setAttribute( QStringLiteral(
"value" ), QString::number( it.value().toDouble() ) );
1724 layerElement.appendChild( attributeElement );
1729 const auto values = identifyResult.
results();
1730 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1732 QVariant value = it.value();
1733 if ( value.type() == QVariant::Bool && !value.toBool() )
1739 if ( value.type() == QVariant::String )
1749 for (
const QgsFeature &feature : storeFeatures )
1751 for (
const auto &fld : feature.fields() )
1753 const auto val { feature.attribute( fld.name() )};
1754 if ( val.isValid() )
1756 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1757 attributeElement.setAttribute( QStringLiteral(
"name" ), fld.name() );
1758 attributeElement.setAttribute( QStringLiteral(
"value" ), val.toString() );
1759 layerElement.appendChild( attributeElement );
1770 bool QgsRenderer::testFilterStringSafety(
const QString &filter )
const 1773 if ( filter.contains( QLatin1String(
";" ) ) )
1778 QStringList tokens = filter.split(
' ', QString::SkipEmptyParts );
1779 groupStringList( tokens, QStringLiteral(
"'" ) );
1780 groupStringList( tokens, QStringLiteral(
"\"" ) );
1782 for (
auto tokenIt = tokens.constBegin() ; tokenIt != tokens.constEnd(); ++tokenIt )
1785 if ( tokenIt->compare( QLatin1String(
"," ) ) == 0
1786 || tokenIt->compare( QLatin1String(
"(" ) ) == 0
1787 || tokenIt->compare( QLatin1String(
")" ) ) == 0
1788 || tokenIt->compare( QLatin1String(
"=" ) ) == 0
1789 || tokenIt->compare( QLatin1String(
"!=" ) ) == 0
1790 || tokenIt->compare( QLatin1String(
"<" ) ) == 0
1791 || tokenIt->compare( QLatin1String(
"<=" ) ) == 0
1792 || tokenIt->compare( QLatin1String(
">" ) ) == 0
1793 || tokenIt->compare( QLatin1String(
">=" ) ) == 0
1794 || tokenIt->compare( QLatin1String(
"%" ) ) == 0
1795 || tokenIt->compare( QLatin1String(
"IS" ), Qt::CaseInsensitive ) == 0
1796 || tokenIt->compare( QLatin1String(
"NOT" ), Qt::CaseInsensitive ) == 0
1797 || tokenIt->compare( QLatin1String(
"NULL" ), Qt::CaseInsensitive ) == 0
1798 || tokenIt->compare( QLatin1String(
"AND" ), Qt::CaseInsensitive ) == 0
1799 || tokenIt->compare( QLatin1String(
"OR" ), Qt::CaseInsensitive ) == 0
1800 || tokenIt->compare( QLatin1String(
"IN" ), Qt::CaseInsensitive ) == 0
1801 || tokenIt->compare( QLatin1String(
"LIKE" ), Qt::CaseInsensitive ) == 0
1802 || tokenIt->compare( QLatin1String(
"ILIKE" ), Qt::CaseInsensitive ) == 0
1803 || tokenIt->compare( QLatin1String(
"DMETAPHONE" ), Qt::CaseInsensitive ) == 0
1804 || tokenIt->compare( QLatin1String(
"SOUNDEX" ), Qt::CaseInsensitive ) == 0 )
1811 tokenIt->toDouble( &isNumeric );
1820 if ( *tokenIt == QLatin1String(
"''" ) )
1826 if ( tokenIt->size() > 2
1827 && ( *tokenIt )[0] == QChar(
'\'' )
1828 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'\'' )
1829 && ( *tokenIt )[1] != QChar(
'\'' )
1830 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'\'' ) )
1836 if ( tokenIt->size() > 2
1837 && ( *tokenIt )[0] == QChar(
'"' )
1838 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'"' )
1839 && ( *tokenIt )[1] != QChar(
'"' )
1840 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'"' ) )
1851 void QgsRenderer::groupStringList( QStringList &list,
const QString &groupString )
1854 bool groupActive =
false;
1855 int startGroup = -1;
1856 QString concatString;
1858 for (
int i = 0; i < list.size(); ++i )
1860 QString &str = list[i];
1861 if ( str.startsWith( groupString ) )
1865 concatString.clear();
1870 if ( i != startGroup )
1872 concatString.append(
" " );
1874 concatString.append( str );
1877 if ( str.endsWith( groupString ) )
1880 groupActive =
false;
1882 if ( startGroup != -1 )
1884 list[startGroup] = concatString;
1885 for (
int j = startGroup + 1; j <= endGroup; ++j )
1887 list.removeAt( startGroup + 1 );
1892 concatString.clear();
1898 void QgsRenderer::convertFeatureInfoToSia2045( QDomDocument &doc )
const 1900 QDomDocument SIAInfoDoc;
1901 QDomElement infoDocElement = doc.documentElement();
1902 QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement,
false ).toElement();
1903 SIAInfoDoc.appendChild( SIAInfoDocElement );
1905 QString currentAttributeName;
1906 QString currentAttributeValue;
1907 QDomElement currentAttributeElem;
1908 QString currentLayerName;
1909 QDomElement currentLayerElem;
1910 QDomNodeList layerNodeList = infoDocElement.elementsByTagName( QStringLiteral(
"Layer" ) );
1911 for (
int i = 0; i < layerNodeList.size(); ++i )
1913 currentLayerElem = layerNodeList.at( i ).toElement();
1914 currentLayerName = currentLayerElem.attribute( QStringLiteral(
"name" ) );
1916 QDomElement currentFeatureElem;
1918 QDomNodeList featureList = currentLayerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
1919 if ( featureList.isEmpty() )
1922 QDomNodeList attributeList = currentLayerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
1923 QDomElement rasterLayerElem;
1924 if ( !attributeList.isEmpty() )
1926 rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
1928 for (
int j = 0; j < attributeList.size(); ++j )
1930 currentAttributeElem = attributeList.at( j ).toElement();
1931 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
1932 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
1933 QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
1934 QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
1935 outAttributeElem.appendChild( outAttributeText );
1936 rasterLayerElem.appendChild( outAttributeElem );
1938 if ( !attributeList.isEmpty() )
1940 SIAInfoDocElement.appendChild( rasterLayerElem );
1946 QSet<QString> layerPropertyAttributes;
1947 QString currentLayerId = currentLayerElem.attribute( QStringLiteral(
"id" ) );
1948 if ( !currentLayerId.isEmpty() )
1953 QString WMSPropertyAttributesString = currentLayer->
customProperty( QStringLiteral(
"WMSPropertyAttributes" ) ).toString();
1954 if ( !WMSPropertyAttributesString.isEmpty() )
1956 QStringList propertyList = WMSPropertyAttributesString.split( QStringLiteral(
"//" ) );
1957 for (
auto propertyIt = propertyList.constBegin() ; propertyIt != propertyList.constEnd(); ++propertyIt )
1959 layerPropertyAttributes.insert( *propertyIt );
1965 QDomElement propertyRefChild;
1966 for (
int j = 0; j < featureList.size(); ++j )
1968 QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
1969 currentFeatureElem = featureList.at( j ).toElement();
1970 QDomNodeList attributeList = currentFeatureElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
1972 for (
int k = 0; k < attributeList.size(); ++k )
1974 currentAttributeElem = attributeList.at( k ).toElement();
1975 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
1976 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
1977 if ( layerPropertyAttributes.contains( currentAttributeName ) )
1979 QDomElement propertyElem = SIAInfoDoc.createElement( QStringLiteral(
"property" ) );
1980 QDomElement identifierElem = SIAInfoDoc.createElement( QStringLiteral(
"identifier" ) );
1981 QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
1982 identifierElem.appendChild( identifierText );
1983 QDomElement valueElem = SIAInfoDoc.createElement( QStringLiteral(
"value" ) );
1984 QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
1985 valueElem.appendChild( valueText );
1986 propertyElem.appendChild( identifierElem );
1987 propertyElem.appendChild( valueElem );
1988 if ( propertyRefChild.isNull() )
1990 SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
1991 propertyRefChild = propertyElem;
1995 SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
2000 QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2001 QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2002 SIAAttributeElem.appendChild( SIAAttributeText );
2003 SIAFeatureElem.appendChild( SIAAttributeElem );
2006 SIAInfoDocElement.appendChild( SIAFeatureElem );
2013 QByteArray QgsRenderer::convertFeatureInfoToHtml(
const QDomDocument &doc )
const 2015 QString featureInfoString;
2018 featureInfoString.append(
"<HEAD>\n" );
2019 featureInfoString.append(
"<TITLE> GetFeatureInfo results </TITLE>\n" );
2020 featureInfoString.append(
"<META http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n" );
2021 featureInfoString.append(
"</HEAD>\n" );
2024 featureInfoString.append(
"<BODY>\n" );
2026 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2029 for (
int i = 0; i < layerList.size(); ++i )
2031 QDomElement layerElem = layerList.at( i ).toElement();
2033 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
2034 featureInfoString.append(
"<TR><TH width=25%>Layer</TH><TD>" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"</TD></TR>\n" );
2035 featureInfoString.append(
"</BR>" );
2038 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2039 QDomElement currentFeatureElement;
2041 if ( !featureNodeList.isEmpty() )
2043 for (
int j = 0; j < featureNodeList.size(); ++j )
2045 QDomElement featureElement = featureNodeList.at( j ).toElement();
2046 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
2047 featureInfoString.append(
"<TR><TH>Feature</TH><TD>" + featureElement.attribute( QStringLiteral(
"id" ) ) +
2051 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2052 for (
int k = 0; k < attributeNodeList.size(); ++k )
2054 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2055 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
2056 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
2059 featureInfoString.append(
"</TABLE>\n</BR>\n" );
2064 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2065 for (
int j = 0; j < attributeNodeList.size(); ++j )
2067 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2068 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
2069 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
2073 featureInfoString.append(
"</TABLE>\n<BR></BR>\n" );
2077 featureInfoString.append(
"</BODY>\n" );
2079 return featureInfoString.toUtf8();
2082 QByteArray QgsRenderer::convertFeatureInfoToText(
const QDomDocument &doc )
const 2084 QString featureInfoString;
2087 featureInfoString.append(
"GetFeatureInfo results\n" );
2088 featureInfoString.append(
"\n" );
2090 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2093 for (
int i = 0; i < layerList.size(); ++i )
2095 QDomElement layerElem = layerList.at( i ).toElement();
2097 featureInfoString.append(
"Layer '" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"'\n" );
2100 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2101 QDomElement currentFeatureElement;
2103 if ( !featureNodeList.isEmpty() )
2105 for (
int j = 0; j < featureNodeList.size(); ++j )
2107 QDomElement featureElement = featureNodeList.at( j ).toElement();
2108 featureInfoString.append(
"Feature " + featureElement.attribute( QStringLiteral(
"id" ) ) +
"\n" );
2111 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2112 for (
int k = 0; k < attributeNodeList.size(); ++k )
2114 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2115 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2116 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2122 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2123 for (
int j = 0; j < attributeNodeList.size(); ++j )
2125 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2126 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2127 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2131 featureInfoString.append(
"\n" );
2134 return featureInfoString.toUtf8();
2137 QByteArray QgsRenderer::convertFeatureInfoToJson(
const QList<QgsMapLayer *> &layers,
const QDomDocument &doc )
const 2141 {
"type",
"FeatureCollection" },
2142 {
"features", json::array() },
2146 const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2147 for (
int i = 0; i < layerList.size(); ++i )
2149 const QDomElement layerElem = layerList.at( i ).toElement();
2150 const QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
2155 if ( mContext.
layerNickname( *l ).compare( layerName ) == 0 )
2171 const QDomNodeList featuresNode = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2172 if ( featuresNode.isEmpty() )
2175 for (
int j = 0; j < featuresNode.size(); ++j )
2177 const QDomElement featureNode = featuresNode.at( j ).toElement();
2178 const QgsFeatureId fid = featureNode.attribute( QStringLiteral(
"id" ) ).toLongLong();
2184 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
2185 for (
int k = 0; k < attrs.count(); k++ )
2187 const QDomElement elm = attrs.at( k ).toElement();
2188 if ( elm.attribute( QStringLiteral(
"name" ) ).compare(
"geometry" ) == 0 )
2195 if ( ! wkt.isEmpty() )
2201 features << feature;
2204 if ( !attributes.isEmpty() )
2207 const QDomNodeList attributesNode = featureNode.elementsByTagName( QStringLiteral(
"Attribute" ) );
2208 for (
int k = 0; k < attributesNode.size(); ++k )
2210 const QDomElement attributeElement = attributesNode.at( k ).toElement();
2211 const QString fieldName = attributeElement.
attribute( QStringLiteral(
"name" ) );
2213 attributes << feature.fieldNameIndex( fieldName );
2223 for (
const auto &feature : qgis::as_const( features ) )
2231 auto properties = json::object();
2232 const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2233 for (
int j = 0; j < attributesNode.size(); ++j )
2235 const QDomElement attrElmt = attributesNode.at( j ).toElement();
2236 const QString name = attrElmt.attribute( QStringLiteral(
"name" ) );
2237 const QString value = attrElmt.attribute( QStringLiteral(
"value" ) );
2238 properties[name.toStdString()] = value.toStdString();
2241 json[
"features"].push_back(
2243 {
"type",
"Feature" },
2244 {
"id", layer->
name().toStdString() },
2245 {
"properties", properties }
2251 return QByteArray::fromStdString( json.dump( 2 ) );
2253 return QByteArray::fromStdString( json.dump() );
2257 QDomElement QgsRenderer::createFeatureGML(
2266 QStringList *attributes )
const 2269 QDomElement typeNameElement = doc.createElement(
"qgs:" + typeName );
2270 typeNameElement.setAttribute( QStringLiteral(
"fid" ), typeName +
"." + QString::number( feat->
id() ) );
2273 if ( layer && layer->
crs() !=
crs )
2296 box = transformedBox;
2304 QDomElement bbElem = doc.createElement( QStringLiteral(
"gml:boundedBy" ) );
2305 QDomElement boxElem;
2317 boxElem.setAttribute( QStringLiteral(
"srsName" ), crs.
authid() );
2319 bbElem.appendChild( boxElem );
2320 typeNameElement.appendChild( bbElem );
2323 if ( withGeom && !geom.
isNull() )
2332 QDomElement geomElem = doc.createElement( QStringLiteral(
"qgs:geometry" ) );
2333 QDomElement gmlElem;
2343 if ( !gmlElem.isNull() )
2347 gmlElem.setAttribute( QStringLiteral(
"srsName" ), crs.
authid() );
2349 geomElem.appendChild( gmlElem );
2350 typeNameElement.appendChild( geomElem );
2357 for (
int i = 0; i < fields.
count(); ++i )
2359 QString attributeName = fields.
at( i ).
name();
2366 if ( attributes && !attributes->contains( attributeName ) )
2371 QDomElement fieldElem = doc.createElement(
"qgs:" + attributeName.replace(
' ',
'_' ) );
2372 QString fieldTextString = featureAttributes.at( i ).toString();
2377 QDomText fieldText = doc.createTextNode( fieldTextString );
2378 fieldElem.appendChild( fieldText );
2379 typeNameElement.appendChild( fieldElem );
2387 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
2390 QDomElement fieldElem = doc.createElement( QStringLiteral(
"qgs:maptip" ) );
2391 QDomText maptipText = doc.createTextNode( fieldTextString );
2392 fieldElem.appendChild( maptipText );
2393 typeNameElement.appendChild( fieldElem );
2397 return typeNameElement;
2400 QString QgsRenderer::replaceValueMapAndRelation(
QgsVectorLayer *vl,
int idx,
const QVariant &attributeVal )
2404 QString value( fieldFormatter->
representValue( vl, idx, setup.
config(), QVariant(), attributeVal ) );
2406 if ( setup.
config().value( QStringLiteral(
"AllowMulti" ) ).toBool() && value.startsWith( QLatin1String(
"{" ) ) && value.endsWith( QLatin1String(
"}" ) ) )
2408 value = value.mid( 1, value.size() - 2 );
2420 double mapUnitTolerance = 0.0;
2430 mapUnitTolerance = mapSettings.
extent().
width() / 400.0;
2442 mapUnitTolerance = mapSettings.
extent().
width() / 200.0;
2454 mapUnitTolerance = mapSettings.
extent().
width() / 100.0;
2458 QgsRectangle mapRectangle( infoPoint.
x() - mapUnitTolerance, infoPoint.
y() - mapUnitTolerance,
2459 infoPoint.
x() + mapUnitTolerance, infoPoint.
y() + mapUnitTolerance );
2463 QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
2465 QList<QgsMapLayer *> highlightLayers;
2468 QString crs = mWmsParameters.
crs();
2472 QDomDocument sldDoc;
2473 if ( !sldDoc.setContent( param.mSld,
true ) )
2480 std::unique_ptr<QgsFeatureRenderer> renderer;
2481 QDomElement el = sldDoc.documentElement();
2491 QString url = typeName +
"?crs=" +
crs;
2492 if ( ! param.mLabel.isEmpty() )
2494 url +=
"&field=label:string";
2499 std::unique_ptr<QgsVectorLayer> layer = qgis::make_unique<QgsVectorLayer>( url, param.mName, QLatin1Literal(
"memory" ), options );
2500 if ( !layer->isValid() )
2507 if ( ! param.mLabel.isEmpty() )
2518 switch ( param.mGeom.type() )
2523 palSettings.
dist = 2;
2534 QVariant x( pt.
x() );
2538 QVariant y( pt.
y() );
2542 QVariant hali(
"Center" );
2546 QVariant vali(
"Half" );
2553 palSettings.
dist = 2;
2562 if ( param.mColor.isValid() )
2564 textFormat.
setColor( param.mColor );
2567 if ( param.mSize > 0 )
2569 textFormat.
setSize( param.mSize );
2577 if ( ! param.mFont.isEmpty() )
2579 textFormat.
setFont( param.mFont );
2582 if ( param.mBufferColor.isValid() )
2584 bufferSettings.
setColor( param.mBufferColor );
2587 if ( param.mBufferSize > 0 )
2590 bufferSettings.
setSize( static_cast<double>( param.mBufferSize ) );
2597 layer->setLabeling( simpleLabeling );
2598 layer->setLabelsEnabled(
true );
2600 fet.setGeometry( param.mGeom );
2604 layer->setRenderer( renderer.release() );
2607 if ( layer->isValid() )
2609 highlightLayers.append( layer.release() );
2613 mTemporaryLayers.append( highlightLayers );
2614 return highlightLayers;
2617 QList<QgsMapLayer *> QgsRenderer::externalLayers(
const QList<QgsWmsParametersExternalLayer> ¶ms )
2619 QList<QgsMapLayer *> layers;
2623 std::unique_ptr<QgsMapLayer> layer = qgis::make_unique< QgsRasterLayer >( param.mUri, param.mName, QStringLiteral(
"wms" ) );
2625 if ( layer->isValid() )
2628 mTemporaryLayers.append( layer.release() );
2629 layers << mTemporaryLayers.last();
2636 void QgsRenderer::removeTemporaryLayers()
2638 qDeleteAll( mTemporaryLayers );
2639 mTemporaryLayers.clear();
2642 QPainter *QgsRenderer::layersRendering(
const QgsMapSettings &mapSettings, QImage &image )
const 2644 QPainter *painter =
nullptr;
2648 #ifdef HAVE_SERVER_PYTHON_PLUGINS 2649 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
2653 renderJob.
render( mapSettings, &image );
2654 painter = renderJob.takePainter();
2656 if ( !renderJob.errors().isEmpty() )
2658 QString layerWMSName;
2659 QString firstErrorLayerId = renderJob.errors().at( 0 ).layerID;
2666 throw QgsException( QStringLiteral(
"Map rendering error in layer '%1'" ).arg( layerWMSName ) );
2672 void QgsRenderer::setLayerOpacity(
QgsMapLayer *layer,
int opacity )
const 2674 if ( opacity >= 0 && opacity <= 255 )
2676 switch ( layer->
type() )
2689 rasterRenderer->
setOpacity( opacity / 255. );
2700 void QgsRenderer::setLayerFilter(
QgsMapLayer *layer,
const QList<QgsWmsParametersFilter> &filters )
2705 QStringList expList;
2711 QDomDocument filterXml;
2713 if ( !filterXml.setContent( filter.mFilter,
true, &errorMsg ) )
2716 QStringLiteral(
"Filter string rejected. Error message: %1. The XML string was: %2" ).arg( errorMsg, filter.mFilter ) );
2718 QDomElement filterElem = filterXml.firstChildElement();
2723 expList << filterExp->dump();
2729 if ( !testFilterStringSafety( filter.mFilter ) )
2732 " has been rejected because of security reasons." 2733 " Note: Text strings have to be enclosed in single or double quotes." 2734 " A space between each word / special character is mandatory." 2735 " Allowed Keywords and special characters are " 2736 " IS,NOT,NULL,AND,OR,IN,=,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX." 2737 " Not allowed are semicolons in the filter expression." ).arg(
2741 QString newSubsetString = filter.mFilter;
2744 newSubsetString.prepend(
") AND (" );
2745 newSubsetString.append(
")" );
2746 newSubsetString.prepend( filteredLayer->
subsetString() );
2747 newSubsetString.prepend(
"(" );
2753 expList.append( dimensionFilter( filteredLayer ) );
2757 if ( expList.size() == 1 )
2761 else if ( expList.size() > 1 )
2763 exp = QStringLiteral(
"( %1 )" ).arg( expList.join( QStringLiteral(
" ) AND ( " ) ) );
2765 if ( !exp.isEmpty() )
2767 std::unique_ptr<QgsExpression> expression(
new QgsExpression( exp ) );
2770 mFeatureFilter.
setFilter( filteredLayer, *expression );
2776 QStringList QgsRenderer::dimensionFilter(
QgsVectorLayer *layer )
const 2778 QStringList expList;
2781 if ( wmsDims.isEmpty() )
2791 if ( fieldIndex == -1 )
2796 int endFieldIndex = -1;
2797 if ( !dim.endFieldName.isEmpty() )
2799 endFieldIndex = layer->
fields().
indexOf( dim.endFieldName );
2800 if ( endFieldIndex == -1 )
2806 if ( !dimParamValues.contains( dim.name.toUpper() ) )
2816 defValue = dim.referenceValue;
2821 QSet<QVariant> uniqueValues = layer->
uniqueValues( fieldIndex );
2822 if ( endFieldIndex != -1 )
2824 uniqueValues.unite( layer->
uniqueValues( endFieldIndex ) );
2827 QList<QVariant> values = uniqueValues.toList();
2828 std::sort( values.begin(), values.end() );
2831 defValue = values.first();
2835 defValue = values.last();
2839 if ( endFieldIndex == -1 )
2845 QStringList expElems;
2850 expList << expElems.join(
' ' );
2858 QString dimParamValue = dimParamValues[dim.name.toUpper()];
2860 QStringList dimExplist;
2862 QStringList dimValues = dimParamValue.split(
',' );
2863 for (
int i = 0; i < dimValues.size(); ++i )
2865 QString dimValue = dimValues[i];
2867 if ( dimValue.size() > 1 )
2869 dimValue = dimValue.trimmed();
2872 if ( dimValue.contains(
'/' ) )
2874 QStringList rangeValues = dimValue.split(
'/' );
2876 if ( rangeValues.size() != 2 )
2881 QVariant rangeMin = QVariant( rangeValues[0] );
2882 QVariant rangeMax = QVariant( rangeValues[1] );
2893 QStringList expElems;
2894 if ( endFieldIndex == -1 )
2914 << QStringLiteral(
")" );
2916 dimExplist << expElems.join(
' ' );
2920 QVariant dimVariant = QVariant( dimValue );
2926 if ( endFieldIndex == -1 )
2935 QStringList expElems;
2940 dimExplist << expElems.join(
' ' );
2945 if ( dimExplist.size() == 1 )
2947 expList << dimExplist;
2949 else if ( dimExplist.size() > 1 )
2951 expList << QStringLiteral(
"( %1 )" ).arg( dimExplist.join( QStringLiteral(
" ) OR ( " ) ) );
2958 void QgsRenderer::setLayerSelection(
QgsMapLayer *layer,
const QStringList &fids )
const 2964 for (
const QString &
id : fids )
2974 void QgsRenderer::setLayerAccessControlFilter(
QgsMapLayer *layer )
const 2976 #ifdef HAVE_SERVER_PYTHON_PLUGINS 2994 void QgsRenderer::annotationsRendering( QPainter *painter )
const 2997 const QList< QgsAnnotation * > annotations = annotationManager->
annotations();
3003 if ( !annotation || !annotation->isVisible() )
3006 annotation->render( renderContext );
3010 QImage *QgsRenderer::scaleImage(
const QImage *image )
const 3015 QImage *scaledImage =
nullptr;
3016 const int width = mWmsParameters.
widthAsInt();
3018 if ( width != image->width() || height != image->height() )
3020 scaledImage =
new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
3026 void QgsRenderer::handlePrintErrors(
const QgsLayout *layout )
const 3032 QList< QgsLayoutItemMap * > mapList;
3035 QList< QgsLayoutItemMap * >::const_iterator mapIt = mapList.constBegin();
3036 for ( ; mapIt != mapList.constEnd(); ++mapIt )
3038 if ( !( *mapIt )->renderingErrors().isEmpty() )
3050 for (
auto layer : layers )
3061 setLayerSld( layer, mContext.
sld( *layer ) );
3065 setLayerStyle( layer, mContext.
style( *layer ) );
3070 setLayerOpacity( layer, param.
mOpacity );
3075 setLayerFilter( layer, param.
mFilter );
3080 setLayerSelection( layer, param.
mSelection );
3085 updateExtent( layer, *settings );
3090 setLayerAccessControlFilter( layer );
3105 void QgsRenderer::setLayerStyle(
QgsMapLayer *layer,
const QString &style )
const 3107 if ( style.isEmpty() )
3116 QStringLiteral(
"Style '%1' does not exist for layer '%2'" ).arg( style, layer->
name() ) );
3120 void QgsRenderer::setLayerSld(
QgsMapLayer *layer,
const QDomElement &sld )
const 3132 if ( !mWmsParameters.
bbox().isEmpty() )
3136 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
3137 configureMapSettings( tmp.get(), mapSettings );
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
QgsPrintLayout * clone() const override
Creates a clone of the layout.
QList< QgsWmsParametersHighlightLayer > highlightLayersParameters() const
Returns parameters for each highlight layer.
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
Class for parsing and evaluation of expressions (formerly called "search strings").
void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider...
Layer tree group node serves as a container for layers and further groups.
Wrapper for iterator of features from vector data provider or vector layer.
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
A container for features with the same fields and crs.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
void removeChildrenGroupWithoutLayers()
Remove all child group nodes without layers.
May use more than one symbol to render a feature: symbolsForFeature() will return them...
A rectangle specified with double values.
Base class for all map layer types.
void dump() const
Dumps parameters.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
~QgsRenderer()
Destructor for QgsRenderer.
HitTest symbols()
Returns the hit test according to the current context.
Item model implementation based on layer tree model for layout legend.
QSet< QgsFeatureId > QgsFeatureIds
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
QgsMasterLayoutInterface * layoutByName(const QString &name) const
Returns the layout with a matching name, or nullptr if no matching layouts were found.
json exportFeatureToJsonObject(const QgsFeature &feature, const QVariantMap &extraProperties=QVariantMap(), const QVariant &id=QVariant()) const
Returns a QJsonObject representation of a feature.
void setAttributeDisplayName(bool displayName)
Sets whether to print original names of attributes or aliases if defined.
void layoutObjects(QList< T *> &objectList) const
Returns a list of layout objects (items and multiframes) of a specific type.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
QgsMapLayerType type() const
Returns the type of the layer.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QString i() const
Returns I parameter or an empty string if not defined.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
const Flags & flags() const
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
Manages storage of a set of QgsAnnotation annotation objects.
Abstract base class for all rendered symbols.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Setting to define QGIS Server WMS Dimension.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
int featureCountAsInt() const
Returns FEATURE_COUNT as an integer.
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
Use exact geometry intersection (slower) instead of bounding boxes.
QSet< QString > excludeAttributesWms() const
A set of attributes that are not advertised in WMS requests with QGIS server.
QgsWmsParameters parameters() const
Returns WMS parameters.
A layout item subclass for text labels.
QStringList layerIds() const
Gets list of layer IDs for map rendering The layers are stored in the reverse order of how they are r...
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
QStringList filters() const
Returns the list of filters found in FILTER parameter.
SERVER_EXPORT double wmsDefaultMapUnitsPerMm(const QgsProject &project)
Returns the default number of map units per millimeters in case of the scale is not given...
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
QString j() const
Returns J parameter or an empty string if not defined.
ExportResult exportToImage(const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings)
Exports the layout to the filePath, using the specified export settings.
SERVER_EXPORT QString getServerFid(const QgsFeature &feature, const QgsAttributeList &pkAttributes)
Returns the feature id based on primary keys.
void render(const QgsMapSettings &mapSettings, QImage *image)
Sequential or parallel map rendering.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Setting options for loading vector layers.
QList< QgsWmsParametersLayer > mLayers
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QList< QgsFeatureStore > QgsFeatureStoreList
QList< QgsFeature > QgsFeatureList
void setIncludeGeometry(bool includeGeometry)
Sets whether to include geometry in the JSON exports.
void setSize(double size)
Sets the size of the buffer.
A class to represent a 2D point.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
void drawLegend(QPainter *painter)
Draws the legend with given painter.
Modify current selection to include only select features which match.
void setFont(const QFont &font)
Sets the font used for rendering text.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
SERVER_EXPORT QString wmsFeatureInfoDocumentElement(const QgsProject &project)
Returns the document element name for XML GetFeatureInfo request.
QByteArray getPrint()
Returns printed page as binary.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
const QList< QgsVectorLayerServerProperties::WmsDimensionInfo > wmsDimensions() const
Returns the QGIS Server WMS Dimension list.
QgsLegendSettings legendSettings() const
Returns legend settings.
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QString sldBody() const
Returns SLD_body if defined or an empty string.
bool convertCompatible(QVariant &v) const
Converts the provided variant to a compatible format.
QgsDxfExport::SymbologyExport dxfMode() const
Returns the DXF MODE parameter.
int yAsInt() const
Returns Y parameter as an int or its default value if not defined.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
X-coordinate data defined label position.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
Container of fields for a vector layer.
bool dxfUseLayerTitleAsName() const
Returns the DXF USE_TITLE_AS_LAYERNAME parameter.
SERVER_EXPORT QHash< QString, QString > wmsFeatureInfoLayerAliasMap(const QgsProject &project)
Returns the mapping between layer name and wms layer name for GetFeatureInfo request.
A geometry is the spatial representation of a feature.
void selectByIds(const QgsFeatureIds &ids, SelectBehavior behavior=SetSelection)
Selects matching features using a list of feature IDs.
SERVER_EXPORT bool wmsInfoFormatSia2045(const QgsProject &project)
Returns if the info format is SIA20145.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
Display all values of the dimension.
Format
Output format for the response.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
QgsDxfExport getDxf()
Returns the map as DXF data.
QgsUnitTypes::DistanceUnit mapUnits
static QDomElement rectangleToGMLBox(QgsRectangle *box, QDomDocument &doc, int precision=17)
Exports the rectangle to GML2 Box.
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
void setSymbologyExport(QgsDxfExport::SymbologyExport e)
Set symbology export mode.
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Sets the mmPerMapUnit calculated by mapUnitsPerPixel mostly taken from the map settings.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
Exception thrown in case of malformed request.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Format infoFormat() const
Returns infoFormat.
Layers and optional attribute index to split into multiple layers using attribute value as layer name...
const QgsCoordinateReferenceSystem & crs
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
RAII class to restore layer configuration on destruction (opacity, filters, ...)
bool transparentAsBool() const
Returns TRANSPARENT parameter as a bool or its default value if not defined.
QStringList flattenedQueryLayers() const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
int count() const
Returns number of items.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
QPainter * painter
Painter.
QList< int > pages
List of specific pages to export, or an empty list to export all pages.
bool withMapTip() const
withMapTip
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual QgsRectangle extent() const
Returns the extent of the layer.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Abstract base class for annotation items which are drawn over a map.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
QString bbox() const
Returns BBOX if defined or an empty string.
The QgsMapSettings class contains configuration for rendering of the map.
void setAttributes(const QgsAttributeList &attributes)
Sets the list of attributes to include in the JSON exports.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
SERVER_EXPORT bool wmsFeatureInfoAddWktGeometry(const QgsProject &project)
Returns if the geometry is displayed as Well Known Text in GetFeatureInfo request.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
Raster identify results container.
void layoutItems(QList< T *> &itemList) const
Returns a list of layout items of a specific type.
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
static void applyAccessControlLayerFilters(const QgsAccessControl *accessControl, QgsMapLayer *mapLayer, QHash< QgsMapLayer *, QString > &originalLayerFilters)
Apply filter from AccessControl.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QHash< QgsVectorLayer *, SymbolSet > HitTest
QSize imageSize
Manual size in pixels for output image.
int lineToleranceAsInt() const
Returns FI_LINE_TOLERANCE parameter as an integer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Property
Data definable properties.
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
bool isValid() const
Returns true if valid.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
QList< QgsMapLayer * > layers() const
Returns the stored layer set.
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
Layout graphical items for displaying a map.
void setOutputSize(QSize size)
Sets the size of the resulting map image.
bool displayAll
If true, all features will be labelled even when overlaps occur.
void setSize(double size)
Sets the size for rendered text.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString x() const
Returns X parameter or an empty string if not defined.
QString layoutParameter(const QString &id, bool &ok) const
Returns a layout parameter thanks to its id.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
SERVER_EXPORT int wmsMaxAtlasFeatures(const QgsProject &project)
Returns the maximum number of atlas features which can be printed in a request.
#define STRING_TO_FID(str)
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
static QString encodeValue(const QVariant &value)
Encodes a value to a JSON string representation, adding appropriate quotations and escaping where req...
Namespace with helper functions for layer tree operations.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
QString crs() const
Returns CRS or an empty string if none is defined.
SERVER_EXPORT QString wmsFeatureInfoDocumentElementNs(const QgsProject &project)
Returns the document element namespace for XML GetFeatureInfo request.
bool isEmpty() const
Returns true if the rectangle is empty.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QString filterGeom() const
Returns the filter geometry found in FILTER_GEOM parameter.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout...
double scale() const
Returns the calculated map scale.
A class to describe the version of a project.
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
double width() const
Returns the width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setMapScale(double scale)
Sets the legend map scale.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
int infoFormatVersion() const
Returns the infoFormat version for GML.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
bool rasterizeWholeImage
Set to true to force whole layout to be rasterized while exporting.
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
void setY(double y)
Sets the y value of the point.
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
SERVER_EXPORT bool wmsFeatureInfoSegmentizeWktGeometry(const QgsProject &project)
Returns if the geometry has to be segmentize in GetFeatureInfo request.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void configureLayers(QList< QgsMapLayer *> &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
void setFilter(const QgsVectorLayer *layer, const QgsExpression &expression)
Set a filter for the given layer.
Horizontal alignment for data defined label position (Left, Center, Right)
QMap< QString, QString > dimensionValues() const
Returns the dimensions parameter.
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
void setColor(const QColor &color)
Sets the color that text will be rendered in.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
QgsAttributeList primaryKeyAttributes() const
Returns the list of attributes which make up the layer's primary keys.
QList< QgsWmsParametersHighlightLayer > mHighlightLayers
void removeMultiFrame(QgsLayoutMultiFrame *multiFrame)
Removes a multiFrame from the layout (but does not delete it).
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
QString composerTemplate() const
Returns TEMPLATE parameter or an empty string if not defined.
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) ...
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
QgsFeatureRenderer * renderer()
Returns renderer.
ExportResult exportToSvg(const QString &filePath, const QgsLayoutExporter::SvgExportSettings &settings)
Exports the layout as an SVG to the filePath, using the specified export settings.
QString id() const
Returns the item's ID name.
Encapsulate a field in an attribute table or data source.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
Abstract base class for all geometries.
ExceptionCode
Exception codes as defined in OGC scpecifications for WMS 1.1.1 and WMS 1.3.0.
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
int pointToleranceAsInt() const
Returns FI_POINT_TOLERANCE parameter as an integer.
Format format() const
Returns format.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
Manages storage of a set of layouts.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value)
Create an expression allowing to evaluate if a field is equal to a value.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
const QgsServerSettings & settings() const
Returns settings of the server.
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...
QgsAnnotationManager * annotationManager()
Returns pointer to the project's annotation manager.
int polygonToleranceAsInt() const
Returns FI_POLYGON_TOLERANCE parameter as an integer.
void setX(double x)
Sets the x value of the point.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages compositions within the project.
Handles exporting QgsFeature features to GeoJSON features.
Remove from current selection.
const QgsProject * project() const
Returns the project.
Median cut implementation.
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
bool parallelRendering() const
Returns parallel rendering setting.
bool withGeometry() const
Returns if the client wants the feature info response with geometry information.
QMap< int, QVariant > results() const
Returns the identify results.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
int pageCount() const
Returns the number of pages in the collection.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Add selection to current selection.
QgsExpressionContext & expressionContext()
Gets the expression context.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Handles rendering and exports of layouts to various formats.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QgsCoordinateTransformContext transformContext
QgsMapLayer * layer() const
Returns the map layer associated with this node.
unsigned int placementFlags
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration...
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
QSet< QString > SymbolSet
Contains settings relating to exporting layouts to PDF.
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
void setSymbologyScale(double scale)
Set reference scale for output.
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Contains information about the context of a rendering operation.
QList< QgsWmsParametersExternalLayer > mExternalLayers
double length() const
Returns the length of the measurement.
Contains settings relating to exporting layouts to raster images.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
int jAsInt() const
Returns J parameter as an int or its default value if not defined.
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QList< QgsAnnotation *> annotations() const
Returns a list of all annotations contained in the manager.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
QgsEditorWidgetSetup editorWidgetSetup(int index) const
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
void removeLayoutItem(QgsLayoutItem *item)
Removes an item from the layout.
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
bool isValidGroup(const QString &name) const
Returns true if name is a group.
int precision() const
Returns the precision to use according to the current configuration.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
double mapTileBuffer(int mapWidth) const
Returns the tile buffer in geographical units for the given map width in pixels.
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
void setExtent(const QgsRectangle &r)
Set extent of area to export.
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QString pointTolerance() const
Returns FI_POINT_TOLERANCE parameter or an empty string if not defined.
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
double scale() const
Returns the map scale.
static QgsFeatureRenderer * loadSld(const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
Container for settings relating to a text buffer.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
ExportResult exportToPdf(const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings)
Exports the layout as a PDF to the filePath, using the specified export settings. ...
Rendering context for the WMS renderer.
Exception thrown when data access violates access controls.
Proxy for sequential or parallel map render job.
static QgsProject * instance()
Returns the QgsProject singleton instance.
double dist
Distance from feature to the label.
double dxfScale() const
Returns the DXF SCALE parameter.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool hasAxisInverted() const
Returns whether axis is inverted (e.g., for WMS 1.3) for the CRS.
This class represents a coordinate reference system (CRS).
QgsFeatureFilterProviderGroup & addProvider(const QgsFeatureFilterProvider *provider)
Add another filter provider to the group.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QString polygonTolerance() const
Returns FI_POLYGON_TOLERANCE parameter or an empty string if not defined.
virtual QgsRasterIdentifyResult identify(const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Identify raster value(s) found on the point position.
QStringList atlasPk() const
Returns the ATLAS_PK parameter.
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 QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
static QDomElement rectangleToGMLEnvelope(QgsRectangle *env, QDomDocument &doc, int precision=17)
Exports the rectangle to GML3 Envelope.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
const QgsCoordinateReferenceSystem & outputCrs
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setLayers(const QList< QgsMapLayer *> &layers)
Set list of layers for map rendering.
QString formatAsString() const
Returns FORMAT parameter as a string.
QStringList dxfLayerAttributes() const
Returns the DXF LAYERATTRIBUTES parameter.
Basic implementation of the labeling interface.
QString lineTolerance() const
Returns FI_LINE_TOLERANCE parameter or an empty string if not defined.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsVectorLayerServerProperties * serverProperties()
Returns QGIS Server Properties of the vector layer.
Enable vector simplification and other rendering optimizations.
QString y() const
Returns Y parameter or an empty string if not defined.
QColor backgroundColorAsColor() const
Returns BGCOLOR parameter as a QColor or its default value if not defined.
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
QgsWkbTypes::GeometryType type
Custom exception class for Coordinate Reference System related exceptions.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
SERVER_EXPORT QString wmsFeatureInfoSchema(const QgsProject &project)
Returns the schema URL for XML GetFeatureInfo request.
QMap< DxfFormatOption, QString > dxfFormatOptions() const
Returns a map of DXF options defined within FORMAT_OPTIONS parameter.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QList< int > QgsAttributeList
Print layout, a QgsLayout subclass for static or atlas-based layouts.
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...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
A layout item subclass for map legends.
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
Y-coordinate data defined label position.
bool nextFeature(QgsFeature &f)
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required...
Container for all settings relating to text rendering.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Geometry is not required. It may still be returned if e.g. required for a filter condition.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
QList< QgsWmsParametersExternalLayer > externalLayersParameters() const
Returns parameters for each external layer.
static QgsExpression * expressionFromOgcFilter(const QDomElement &element, QgsVectorLayer *layer=nullptr)
Parse XML with OGC filter into QGIS expression.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
int maxThreads() const
Returns the maximum number of threads to use.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Represents a vector layer which manages a vector based data sets.
int iAsInt() const
Returns I parameter as an int or its default value if not defined.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Contains settings relating to exporting layouts to SVG.
Base class for frame items, which form a layout multiframe item.
QgsWmsParametersComposerMap composerMapParameters(int mapId) const
Returns the requested parameters for a composer map parameter.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
A layout multiframe subclass for HTML content.
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top) ...
QList< QgsWmsParametersFilter > mFilter
Defines a QGIS exception class.
WMS parameter received from the client.
QgsCoordinateTransformContext transformContext() const
Returns the transform context, for use when a destinationCrs() has been set and reprojection is requi...
void addLayers(const QList< QgsDxfExport::DxfLayer > &layers)
Add layers to export.
QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else...
void setColor(const QColor &color)
Sets the color for the buffer.
int priority
Label priority.
If the layer is identifiable using the identify map tool and as a WMS layer.
QSize outputSize() const
Returns the size of the resulting map image.
Raster renderer pipe that applies colors to a raster.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QString authid() const
Returns the authority identifier for the CRS.
A filter filter provider grouping several filter providers.
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
QgsCoordinateReferenceSystem crs
QString style(const QgsMapLayer &layer) const
Returns a style's name for a specific layer.
void invert()
Swap x/y coordinates in the rectangle.
double height() const
Returns the height of the rectangle.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
int xAsInt() const
Returns X parameter as an int or its default value if not defined.
Layer tree node points to a map layer.
The QgsLegendRenderer class handles automatic layout and rendering of legend.
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
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...
QString fieldName
Name of field (or an expression) to use for label text.
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns project's global labeling engine settings.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setOpacity(double opacity)
Sets the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1...