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();
180 std::unique_ptr<QgsLayerRestorer> restorer;
203 for (
const QString &
id : mapSettings.
layerIds() )
220 runHitTestLayer( vl, usedSymbols, context );
226 std::unique_ptr< QgsFeatureRenderer > r( vl->
renderer()->
clone() );
228 r->startRender( context, vl->
fields() );
236 if ( moreSymbolsPerFeature )
238 for (
QgsSymbol *s : r->originalSymbolsForFeature( f, context ) )
244 r->stopRender( context );
253 QStringLiteral(
"The requested map size is too large" ) );
257 std::unique_ptr<QgsLayerRestorer> restorer;
267 std::unique_ptr<QPainter> painter;
268 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
271 configureMapSettings( image.get(), mapSettings );
278 runHitTest( mapSettings, symbols );
286 std::unique_ptr<QgsLayerRestorer> restorer;
291 if ( templateName.isEmpty() )
310 QStringLiteral(
"The template has no pages" ) );
313 std::unique_ptr<QgsPrintLayout> layout( sourceLayout->
clone() );
317 QStringList atlasPk = mWmsParameters.
atlasPk();
318 if ( !atlasPk.isEmpty() )
320 atlas = layout->atlas();
321 if ( !atlas || !atlas->enabled() )
325 QStringLiteral(
"The template has no atlas enabled" ) );
332 QStringLiteral(
"The atlas has no coverage layer" ) );
336 if ( atlasPk.size() == 1 && atlasPk.at( 0 ) == QStringLiteral(
"*" ) )
338 atlas->setFilterFeatures(
false );
339 atlas->updateFeatures();
340 if ( atlas->count() > maxAtlasFeatures )
343 QString(
"The project configuration allows printing maximum %1 atlas features at a time" ).arg( maxAtlasFeatures ) );
349 if ( pkIndexes.size() < 1 )
351 throw QgsException( QStringLiteral(
"An error occurred during the Atlas print" ) );
353 QStringList pkAttributeNames;
354 for (
int i = 0; i < pkIndexes.size(); ++i )
356 pkAttributeNames.append( cLayer->
fields()[pkIndexes.at( i )].name() );
359 int nAtlasFeatures = atlasPk.size() / pkIndexes.size();
360 if ( nAtlasFeatures * pkIndexes.size() != atlasPk.size() )
363 QStringLiteral(
"Wrong number of ATLAS_PK parameters" ) );
367 if ( nAtlasFeatures > maxAtlasFeatures )
370 QString(
"%1 atlas features have been requestet, but the project configuration only allows printing %2 atlas features at a time" )
371 .arg( nAtlasFeatures ).arg( maxAtlasFeatures ) );
374 QString filterString;
375 int currentAtlasPk = 0;
377 for (
int i = 0; i < nAtlasFeatures; ++i )
381 filterString.append(
" OR " );
384 filterString.append(
"( " );
386 for (
int j = 0; j < pkIndexes.size(); ++j )
390 filterString.append(
" AND " );
392 filterString.append( QString(
"\"%1\" = %2" ).arg( pkAttributeNames.at( j ) ).arg( atlasPk.at( currentAtlasPk ) ) );
396 filterString.append(
" )" );
399 atlas->setFilterFeatures(
true );
401 atlas->setFilterExpression( filterString, errorString );
402 if ( !errorString.isEmpty() )
404 throw QgsException( QStringLiteral(
"An error occurred during the Atlas print" ) );
416 std::unique_ptr<QImage> image(
new QImage() );
417 configureMapSettings( image.get(), mapSettings );
423 configurePrintLayout( layout.get(), mapSettings, atlas );
429 QTemporaryFile tempOutputFile( QDir::tempPath() +
'/' + QStringLiteral(
"XXXXXX.%1" ).arg( extension ) );
430 if ( !tempOutputFile.open() )
432 throw QgsException( QStringLiteral(
"Could not open temporary file for the GetPrint request." ) );
441 if ( !mWmsParameters.
dpi().isEmpty() )
444 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
446 exportSettings.
dpi = dpi;
453 atlas->beginRender();
457 atlasSvgExport.
exportToSvg( tempOutputFile.fileName(), exportSettings );
463 exporter.
exportToSvg( tempOutputFile.fileName(), exportSettings );
472 double dpi( layout->renderContext().dpi( ) );
473 if ( !mWmsParameters.
dpi().isEmpty() )
476 double _dpi = mWmsParameters.
dpi().toDouble( &ok );
480 exportSettings.
dpi = dpi;
484 QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
485 QgsLayoutMeasurement width( layout->convertFromLayoutUnits( layoutSize.width(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
486 QgsLayoutMeasurement height( layout->convertFromLayoutUnits( layoutSize.height(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
487 exportSettings.
imageSize = QSize( static_cast<int>( width.length() * dpi / 25.4 ), static_cast<int>( height.
length() * dpi / 25.4 ) );
489 exportSettings.
pages.append( 0 );
493 atlas->beginRender();
497 atlasPngExport.
exportToImage( tempOutputFile.fileName(), exportSettings );
503 exporter.
exportToImage( tempOutputFile.fileName(), exportSettings );
511 if ( !mWmsParameters.
dpi().isEmpty() )
514 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
516 exportSettings.
dpi = dpi;
521 exportSettings.
rasterizeWholeImage = layout->customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
527 exporter.
exportToPdf( atlas, tempOutputFile.fileName(), exportSettings, exportError );
531 exporter.exportToPdf( tempOutputFile.fileName(), exportSettings );
542 handlePrintErrors( atlas->layout() );
546 handlePrintErrors( layout.get() );
549 return tempOutputFile.readAll();
556 QList<QgsLayoutItemMap *> maps;
562 for (
const auto &map : qgis::as_const( maps ) )
567 if ( !atlasPrint || !map->atlasDriven() )
591 if ( cMapParams.
mScale > 0 )
593 map->setScale( static_cast<double>( cMapParams.
mScale ) );
599 map->setMapRotation( cMapParams.
mRotation );
603 if ( !map->keepLayerSet() )
607 map->setLayers( mapSettings.
layers() );
611 QList<QgsMapLayer *> layerSet;
612 for (
auto layer : cMapParams.
mLayers )
621 setLayerStyle( mlayer, layer.mStyle );
627 std::reverse( layerSet.begin(), layerSet.end() );
628 map->setLayers( layerSet );
630 map->setKeepLayerSet(
true );
636 map->grid()->setIntervalX( static_cast<double>( cMapParams.
mGridX ) );
637 map->grid()->setIntervalY( static_cast<double>( cMapParams.
mGridY ) );
642 QList<QgsLayoutItemLabel *> labels;
644 for (
const auto &label : qgis::as_const( labels ) )
647 const QString labelId = label->
id();
648 const QString labelParam = mWmsParameters.
layoutParameter( labelId, ok );
653 if ( labelParam.isEmpty() )
657 c->removeItem( label );
662 label->setText( labelParam );
666 QList<QgsLayoutItemHtml *> htmls;
668 for (
const auto &html : qgis::as_const( htmls ) )
670 if ( html->frameCount() == 0 )
675 const QString htmlId = htmlFrame->
id();
694 html->setUrl( newUrl );
700 QList<QgsLayoutItemLegend *> legends;
702 for (
const auto &legend : qgis::as_const( legends ) )
704 if ( legend->autoUpdateModel() )
714 legend->setAutoUpdateModel(
false );
718 QStringList layerSet;
719 const QList<QgsMapLayer *> layerList( map->
layers() );
720 for (
const auto &layer : layerList )
721 layerSet << layer->id();
733 for (
const auto &layerId : layerIds )
740 if ( !layerSet.contains( layerId ) )
765 QStringLiteral(
"The requested map size is too large" ) );
769 std::unique_ptr<QgsLayerRestorer> restorer;
780 std::unique_ptr<QPainter> painter;
781 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
784 configureMapSettings( image.get(), mapSettings );
790 painter.reset( layersRendering( mapSettings, *image ) );
793 annotationsRendering( painter.get() );
799 QImage *scaledImage = scaleImage( image.get() );
801 image.reset( scaledImage );
804 return image.release();
810 std::unique_ptr<QgsLayerRestorer> restorer;
819 QList< QgsDxfExport::DxfLayer > dxfLayers;
831 int layerAttribute = -1;
832 if ( attributes.size() > layerIdx )
841 std::unique_ptr<QgsDxfExport> dxf = qgis::make_unique<QgsDxfExport>();
843 dxf->addLayers( dxfLayers );
845 dxf->setSymbologyExport( mWmsParameters.
dxfMode() );
846 if ( mWmsParameters.
dxfFormatOptions().contains( QgsWmsParameters::DxfFormatOption::SCALE ) )
848 dxf->setSymbologyScale( mWmsParameters.
dxfScale() );
851 dxf->setForce2d( mWmsParameters.
isForce2D() );
852 QgsDxfExport::Flags flags;
853 if ( mWmsParameters.
noMText() )
854 flags.setFlag( QgsDxfExport::Flag::FlagNoMText );
856 dxf->setFlags( flags );
864 if ( i < 0 || i > mapSettings.
outputSize().width() )
872 if ( j < 0 || j > mapSettings.
outputSize().height() )
897 const bool ijDefined = !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty();
898 const bool xyDefined = !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty();
899 const bool filtersDefined = !mWmsParameters.
filters().isEmpty();
900 const bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
902 if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
906 if ( mWmsParameters.
j().isEmpty() )
913 if ( infoFormat == QgsWmsParameters::Format::NONE )
920 std::unique_ptr<QImage> outputImage( createImage( mContext.
mapSize() ) );
923 std::unique_ptr<QgsLayerRestorer> restorer;
928 bool mandatoryCrsParam =
true;
929 if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.
crs().isEmpty() )
931 mandatoryCrsParam =
false;
937 configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
953 QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );
957 if ( infoFormat == QgsWmsParameters::Format::TEXT )
958 ba = convertFeatureInfoToText( result );
959 else if ( infoFormat == QgsWmsParameters::Format::HTML )
960 ba = convertFeatureInfoToHtml( result );
961 else if ( infoFormat == QgsWmsParameters::Format::JSON )
962 ba = convertFeatureInfoToJson( layers, result );
964 ba = result.toByteArray();
969 QImage *QgsRenderer::createImage(
const QSize &size )
const 971 std::unique_ptr<QImage> image;
979 image = qgis::make_unique<QImage>( size, QImage::Format_ARGB32_Premultiplied );
984 image = qgis::make_unique<QImage>( size, QImage::Format_RGB32 );
989 if ( image->isNull() )
991 throw QgsException( QStringLiteral(
"createImage: image could not be created, check for out of memory conditions" ) );
994 const int dpm =
static_cast<int>( mContext.
dotsPerMm() * 1000.0 );
995 image->setDotsPerMeterX( dpm );
996 image->setDotsPerMeterY( dpm );
998 return image.release();
1001 void QgsRenderer::configureMapSettings(
const QPaintDevice *paintDevice,
QgsMapSettings &mapSettings,
bool mandatoryCrsParam )
const 1005 throw QgsException( QStringLiteral(
"configureMapSettings: no paint device" ) );
1008 mapSettings.
setOutputSize( QSize( paintDevice->width(), paintDevice->height() ) );
1009 mapSettings.
setOutputDpi( paintDevice->logicalDpiX() );
1013 if ( !mWmsParameters.
bbox().isEmpty() && mapExtent.
isEmpty() )
1019 QString
crs = mWmsParameters.
crs();
1020 if ( crs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 )
1022 crs = QString(
"EPSG:4326" );
1025 else if ( crs.isEmpty() && !mandatoryCrsParam )
1027 crs = QString(
"EPSG:4326" );
1079 else if ( backgroundColor.isValid() )
1099 QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers,
const QgsMapSettings &mapSettings,
1100 const QImage *outputImage,
const QString &version )
const 1104 bool ijDefined = ( !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty() );
1106 bool xyDefined = ( !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty() );
1108 bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1110 bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1113 if ( featureCount < 1 )
1118 int i = mWmsParameters.
iAsInt();
1119 int j = mWmsParameters.
jAsInt();
1120 if ( xyDefined && !ijDefined )
1122 i = mWmsParameters.
xAsInt();
1123 j = mWmsParameters.
yAsInt();
1127 if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
1129 i *= ( outputImage->width() /
static_cast<double>( width ) );
1130 j *= ( outputImage->height() /
static_cast<double>( height ) );
1134 std::unique_ptr<QgsRectangle> featuresRect;
1135 std::unique_ptr<QgsGeometry> filterGeom;
1136 std::unique_ptr<QgsPointXY> infoPoint;
1138 if ( i != -1 && j != -1 )
1141 infoPointToMapCoordinates( i, j, infoPoint.get(), mapSettings );
1143 else if ( filtersDefined )
1147 else if ( filterGeomDefined )
1152 QDomDocument result;
1154 QDomElement getFeatureInfoElement;
1156 if ( infoFormat == QgsWmsParameters::Format::GML )
1158 getFeatureInfoElement = result.createElement( QStringLiteral(
"wfs:FeatureCollection" ) );
1159 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:wfs" ), QStringLiteral(
"http://www.opengis.net/wfs" ) );
1160 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1161 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1162 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
1163 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1164 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:qgs" ), QStringLiteral(
"http://qgis.org/gml" ) );
1165 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1166 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" ) );
1171 if ( featureInfoElemName.isEmpty() )
1173 featureInfoElemName = QStringLiteral(
"GetFeatureInfoResponse" );
1176 if ( featureInfoElemNs.isEmpty() )
1178 getFeatureInfoElement = result.createElement( featureInfoElemName );
1182 getFeatureInfoElement = result.createElementNS( featureInfoElemNs, featureInfoElemName );
1186 if ( !featureInfoSchema.isEmpty() )
1188 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1189 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), featureInfoSchema );
1192 result.appendChild( getFeatureInfoElement );
1202 for (
const QString &queryLayer : queryLayers )
1204 bool validLayer =
false;
1205 bool queryableLayer =
true;
1206 for (
QgsMapLayer *layer : qgis::as_const( layers ) )
1212 if ( !queryableLayer )
1217 QDomElement layerElement;
1218 if ( infoFormat == QgsWmsParameters::Format::GML )
1220 layerElement = getFeatureInfoElement;
1224 layerElement = result.createElement( QStringLiteral(
"Layer" ) );
1225 QString layerName = queryLayer;
1228 QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.constFind( layerName );
1229 if ( layerAliasIt != layerAliasMap.constEnd() )
1231 layerName = layerAliasIt.value();
1234 layerElement.setAttribute( QStringLiteral(
"name" ), layerName );
1235 getFeatureInfoElement.appendChild( layerElement );
1238 layerElement.setAttribute( QStringLiteral(
"id" ), layer->id() );
1247 ( void )featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, featuresRect.get(), filterGeom.get() );
1267 if ( infoFormat == QgsWmsParameters::Format::GML )
1269 layerElement = result.createElement( QStringLiteral(
"gml:featureMember" ) );
1270 getFeatureInfoElement.appendChild( layerElement );
1273 ( void )featureInfoFromRasterLayer( rasterLayer, mapSettings, &layerInfoPoint, result, layerElement, version );
1281 param.
mValue = queryLayer;
1285 else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.
isValidGroup( queryLayer ) ) )
1288 param.
mValue = queryLayer;
1290 bool hasGroupAndQueryable {
false };
1295 for (
const QString &ql : constNicks )
1299 const QList<QgsMapLayer *> constLayers { mContext.
layerGroups()[ql] };
1302 if ( ( ! ml->shortName().isEmpty() && ml->shortName() == queryLayer ) || ( ml->name() == queryLayer ) )
1308 hasGroupAndQueryable =
true;
1317 if ( ! hasGroupAndQueryable )
1327 if ( infoFormat == QgsWmsParameters::Format::GML )
1329 QDomElement bBoxElem = result.createElement( QStringLiteral(
"gml:boundedBy" ) );
1330 QDomElement boxElem;
1332 if ( gmlVersion < 3 )
1342 if ( crs.isValid() )
1344 boxElem.setAttribute( QStringLiteral(
"srsName" ), crs.authid() );
1346 bBoxElem.appendChild( boxElem );
1347 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1351 QDomElement bBoxElem = result.createElement( QStringLiteral(
"BoundingBox" ) );
1353 bBoxElem.setAttribute( QStringLiteral(
"minx" ),
qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1354 bBoxElem.setAttribute( QStringLiteral(
"maxx" ),
qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1355 bBoxElem.setAttribute( QStringLiteral(
"miny" ),
qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1356 bBoxElem.setAttribute( QStringLiteral(
"maxy" ),
qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
1357 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1361 if ( sia2045 && infoFormat == QgsWmsParameters::Format::XML )
1363 convertFeatureInfoToSia2045( result );
1369 bool QgsRenderer::featureInfoFromVectorLayer(
QgsVectorLayer *layer,
1372 QDomDocument &infoDocument,
1373 QDomElement &layerElement,
1376 const QString &version,
1388 std::unique_ptr<QgsGeometry> layerFilterGeom;
1391 layerFilterGeom.reset(
new QgsGeometry( *filterGeom ) );
1405 searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
1407 else if ( layerFilterGeom )
1409 searchRect = layerFilterGeom->boundingBox();
1411 else if ( !mWmsParameters.
bbox().isEmpty() )
1413 searchRect = layerRect;
1420 int featureCounter = 0;
1440 if ( layerFilterGeom )
1442 fReq.
setFilterExpression( QString(
"intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
1445 #ifdef HAVE_SERVER_PYTHON_PLUGINS 1446 mContext.accessControl()->filterFeatures( layer, fReq );
1448 QStringList attributes;
1449 for (
const QgsField &field : fields )
1451 attributes.append( field.name() );
1453 attributes = mContext.accessControl()->layerAttributes( layer, attributes );
1458 std::unique_ptr< QgsFeatureRenderer > r2( layer->
renderer() ? layer->
renderer()->
clone() : nullptr );
1461 r2->startRender( renderContext, layer->
fields() );
1464 bool featureBBoxInitialized =
false;
1473 if ( featureCounter > nFeatures )
1488 bool render = r2->willRenderFeature( feature, renderContext );
1501 if ( !featureBBoxInitialized && featureBBox->
isEmpty() )
1504 featureBBoxInitialized =
true;
1519 if ( mWmsParameters.
infoFormat() == QgsWmsParameters::Format::GML )
1524 QDomElement elem = createFeatureGML(
1525 &feature, layer, infoDocument, outputCrs, mapSettings, typeName, withGeom, gmlVersion
1526 #ifdef HAVE_SERVER_PYTHON_PLUGINS
1530 QDomElement featureMemberElem = infoDocument.createElement( QStringLiteral(
"gml:featureMember" ) );
1531 featureMemberElem.appendChild( elem );
1532 layerElement.appendChild( featureMemberElem );
1537 QDomElement featureElement = infoDocument.createElement( QStringLiteral(
"Feature" ) );
1539 layerElement.appendChild( featureElement );
1543 for (
int i = 0; i < featureAttributes.count(); ++i )
1546 if ( excludedAttributes.contains( fields.at( i ).name() ) )
1550 #ifdef HAVE_SERVER_PYTHON_PLUGINS 1552 if ( !attributes.contains( fields.at( i ).name() ) )
1561 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1562 attributeElement.setAttribute( QStringLiteral(
"name" ), attributeName );
1564 attributeElement.setAttribute( QStringLiteral(
"value" ),
1566 replaceValueMapAndRelation(
1568 featureAttributes[i] ),
1571 featureElement.appendChild( attributeElement );
1576 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
1578 QDomElement maptipElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1579 maptipElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"maptip" ) );
1581 featureElement.appendChild( maptipElem );
1588 QDomElement bBoxElem = infoDocument.createElement( QStringLiteral(
"BoundingBox" ) );
1589 bBoxElem.setAttribute( version == QLatin1String(
"1.1.1" ) ?
"SRS" :
"CRS", outputCrs.
authid() );
1594 featureElement.appendChild( bBoxElem );
1610 if ( segmentizeWktGeometry )
1618 geom.
set( segmentizedGeom );
1622 QDomElement geometryElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1623 geometryElement.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"geometry" ) );
1624 geometryElement.setAttribute( QStringLiteral(
"value" ), geom.
asWkt( mContext.
precision() ) );
1625 geometryElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"derived" ) );
1626 featureElement.appendChild( geometryElement );
1633 r2->stopRender( renderContext );
1639 bool QgsRenderer::featureInfoFromRasterLayer(
QgsRasterLayer *layer,
1642 QDomDocument &infoDocument,
1643 QDomElement &layerElement,
1644 const QString &version )
const 1663 QgsRaster::IdentifyFormat::IdentifyFormatFeature :
1664 QgsRaster::IdentifyFormat::IdentifyFormatValue };
1671 if ( ! transform.isValid() )
1676 .arg( layer->
name() ) );
1685 if ( !identifyResult.
isValid() )
1688 QMap<int, QVariant> attributes = identifyResult.
results();
1690 if ( mWmsParameters.
infoFormat() == QgsWmsParameters::Format::GML )
1702 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
1705 feature.
setAttribute( index++, QString::number( it.value().toDouble() ) );
1708 QDomElement elem = createFeatureGML(
1709 &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
1710 layerElement.appendChild( elem );
1714 const auto values = identifyResult.
results();
1715 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1717 QVariant value = it.value();
1718 if ( value.type() == QVariant::Bool && !value.toBool() )
1724 if ( value.type() == QVariant::String )
1735 for (
const QgsFeature &feature : storeFeatures )
1737 QDomElement elem = createFeatureGML(
1738 &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
1739 layerElement.appendChild( elem );
1749 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
1751 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1752 attributeElement.setAttribute( QStringLiteral(
"name" ), layer->
bandName( it.key() ) );
1753 attributeElement.setAttribute( QStringLiteral(
"value" ), QString::number( it.value().toDouble() ) );
1754 layerElement.appendChild( attributeElement );
1759 const auto values = identifyResult.
results();
1760 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1762 QVariant value = it.value();
1763 if ( value.type() == QVariant::Bool && !value.toBool() )
1769 if ( value.type() == QVariant::String )
1779 for (
const QgsFeature &feature : storeFeatures )
1781 for (
const auto &fld : feature.fields() )
1783 const auto val { feature.attribute( fld.name() )};
1784 if ( val.isValid() )
1786 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1787 attributeElement.setAttribute( QStringLiteral(
"name" ), fld.name() );
1788 attributeElement.setAttribute( QStringLiteral(
"value" ), val.toString() );
1789 layerElement.appendChild( attributeElement );
1800 bool QgsRenderer::testFilterStringSafety(
const QString &filter )
const 1803 if ( filter.contains( QLatin1String(
";" ) ) )
1808 QStringList tokens = filter.split(
' ', QString::SkipEmptyParts );
1809 groupStringList( tokens, QStringLiteral(
"'" ) );
1810 groupStringList( tokens, QStringLiteral(
"\"" ) );
1812 for (
auto tokenIt = tokens.constBegin() ; tokenIt != tokens.constEnd(); ++tokenIt )
1815 if ( tokenIt->compare( QLatin1String(
"," ) ) == 0
1816 || tokenIt->compare( QLatin1String(
"(" ) ) == 0
1817 || tokenIt->compare( QLatin1String(
")" ) ) == 0
1818 || tokenIt->compare( QLatin1String(
"=" ) ) == 0
1819 || tokenIt->compare( QLatin1String(
"!=" ) ) == 0
1820 || tokenIt->compare( QLatin1String(
"<" ) ) == 0
1821 || tokenIt->compare( QLatin1String(
"<=" ) ) == 0
1822 || tokenIt->compare( QLatin1String(
">" ) ) == 0
1823 || tokenIt->compare( QLatin1String(
">=" ) ) == 0
1824 || tokenIt->compare( QLatin1String(
"%" ) ) == 0
1825 || tokenIt->compare( QLatin1String(
"IS" ), Qt::CaseInsensitive ) == 0
1826 || tokenIt->compare( QLatin1String(
"NOT" ), Qt::CaseInsensitive ) == 0
1827 || tokenIt->compare( QLatin1String(
"NULL" ), Qt::CaseInsensitive ) == 0
1828 || tokenIt->compare( QLatin1String(
"AND" ), Qt::CaseInsensitive ) == 0
1829 || tokenIt->compare( QLatin1String(
"OR" ), Qt::CaseInsensitive ) == 0
1830 || tokenIt->compare( QLatin1String(
"IN" ), Qt::CaseInsensitive ) == 0
1831 || tokenIt->compare( QLatin1String(
"LIKE" ), Qt::CaseInsensitive ) == 0
1832 || tokenIt->compare( QLatin1String(
"ILIKE" ), Qt::CaseInsensitive ) == 0
1833 || tokenIt->compare( QLatin1String(
"DMETAPHONE" ), Qt::CaseInsensitive ) == 0
1834 || tokenIt->compare( QLatin1String(
"SOUNDEX" ), Qt::CaseInsensitive ) == 0 )
1841 tokenIt->toDouble( &isNumeric );
1850 if ( *tokenIt == QLatin1String(
"''" ) )
1856 if ( tokenIt->size() > 2
1857 && ( *tokenIt )[0] == QChar(
'\'' )
1858 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'\'' )
1859 && ( *tokenIt )[1] != QChar(
'\'' )
1860 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'\'' ) )
1866 if ( tokenIt->size() > 2
1867 && ( *tokenIt )[0] == QChar(
'"' )
1868 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'"' )
1869 && ( *tokenIt )[1] != QChar(
'"' )
1870 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'"' ) )
1881 void QgsRenderer::groupStringList( QStringList &list,
const QString &groupString )
1884 bool groupActive =
false;
1885 int startGroup = -1;
1886 QString concatString;
1888 for (
int i = 0; i < list.size(); ++i )
1890 QString &str = list[i];
1891 if ( str.startsWith( groupString ) )
1895 concatString.clear();
1900 if ( i != startGroup )
1902 concatString.append(
" " );
1904 concatString.append( str );
1907 if ( str.endsWith( groupString ) )
1910 groupActive =
false;
1912 if ( startGroup != -1 )
1914 list[startGroup] = concatString;
1915 for (
int j = startGroup + 1; j <= endGroup; ++j )
1917 list.removeAt( startGroup + 1 );
1922 concatString.clear();
1928 void QgsRenderer::convertFeatureInfoToSia2045( QDomDocument &doc )
const 1930 QDomDocument SIAInfoDoc;
1931 QDomElement infoDocElement = doc.documentElement();
1932 QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement,
false ).toElement();
1933 SIAInfoDoc.appendChild( SIAInfoDocElement );
1935 QString currentAttributeName;
1936 QString currentAttributeValue;
1937 QDomElement currentAttributeElem;
1938 QString currentLayerName;
1939 QDomElement currentLayerElem;
1940 QDomNodeList layerNodeList = infoDocElement.elementsByTagName( QStringLiteral(
"Layer" ) );
1941 for (
int i = 0; i < layerNodeList.size(); ++i )
1943 currentLayerElem = layerNodeList.at( i ).toElement();
1944 currentLayerName = currentLayerElem.attribute( QStringLiteral(
"name" ) );
1946 QDomElement currentFeatureElem;
1948 QDomNodeList featureList = currentLayerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
1949 if ( featureList.isEmpty() )
1952 QDomNodeList attributeList = currentLayerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
1953 QDomElement rasterLayerElem;
1954 if ( !attributeList.isEmpty() )
1956 rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
1958 for (
int j = 0; j < attributeList.size(); ++j )
1960 currentAttributeElem = attributeList.at( j ).toElement();
1961 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
1962 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
1963 QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
1964 QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
1965 outAttributeElem.appendChild( outAttributeText );
1966 rasterLayerElem.appendChild( outAttributeElem );
1968 if ( !attributeList.isEmpty() )
1970 SIAInfoDocElement.appendChild( rasterLayerElem );
1976 QSet<QString> layerPropertyAttributes;
1977 QString currentLayerId = currentLayerElem.attribute( QStringLiteral(
"id" ) );
1978 if ( !currentLayerId.isEmpty() )
1983 QString WMSPropertyAttributesString = currentLayer->
customProperty( QStringLiteral(
"WMSPropertyAttributes" ) ).toString();
1984 if ( !WMSPropertyAttributesString.isEmpty() )
1986 QStringList propertyList = WMSPropertyAttributesString.split( QStringLiteral(
"//" ) );
1987 for (
auto propertyIt = propertyList.constBegin() ; propertyIt != propertyList.constEnd(); ++propertyIt )
1989 layerPropertyAttributes.insert( *propertyIt );
1995 QDomElement propertyRefChild;
1996 for (
int j = 0; j < featureList.size(); ++j )
1998 QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
1999 currentFeatureElem = featureList.at( j ).toElement();
2000 QDomNodeList attributeList = currentFeatureElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2002 for (
int k = 0; k < attributeList.size(); ++k )
2004 currentAttributeElem = attributeList.at( k ).toElement();
2005 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
2006 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
2007 if ( layerPropertyAttributes.contains( currentAttributeName ) )
2009 QDomElement propertyElem = SIAInfoDoc.createElement( QStringLiteral(
"property" ) );
2010 QDomElement identifierElem = SIAInfoDoc.createElement( QStringLiteral(
"identifier" ) );
2011 QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
2012 identifierElem.appendChild( identifierText );
2013 QDomElement valueElem = SIAInfoDoc.createElement( QStringLiteral(
"value" ) );
2014 QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
2015 valueElem.appendChild( valueText );
2016 propertyElem.appendChild( identifierElem );
2017 propertyElem.appendChild( valueElem );
2018 if ( propertyRefChild.isNull() )
2020 SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
2021 propertyRefChild = propertyElem;
2025 SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
2030 QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2031 QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2032 SIAAttributeElem.appendChild( SIAAttributeText );
2033 SIAFeatureElem.appendChild( SIAAttributeElem );
2036 SIAInfoDocElement.appendChild( SIAFeatureElem );
2043 QByteArray QgsRenderer::convertFeatureInfoToHtml(
const QDomDocument &doc )
const 2045 QString featureInfoString;
2048 featureInfoString.append(
"<HEAD>\n" );
2049 featureInfoString.append(
"<TITLE> GetFeatureInfo results </TITLE>\n" );
2050 featureInfoString.append(
"<META http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n" );
2051 featureInfoString.append(
"</HEAD>\n" );
2054 featureInfoString.append(
"<BODY>\n" );
2056 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2059 for (
int i = 0; i < layerList.size(); ++i )
2061 QDomElement layerElem = layerList.at( i ).toElement();
2063 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
2064 featureInfoString.append(
"<TR><TH width=25%>Layer</TH><TD>" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"</TD></TR>\n" );
2065 featureInfoString.append(
"</BR>" );
2068 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2069 QDomElement currentFeatureElement;
2071 if ( !featureNodeList.isEmpty() )
2073 for (
int j = 0; j < featureNodeList.size(); ++j )
2075 QDomElement featureElement = featureNodeList.at( j ).toElement();
2076 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
2077 featureInfoString.append(
"<TR><TH>Feature</TH><TD>" + featureElement.attribute( QStringLiteral(
"id" ) ) +
2081 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2082 for (
int k = 0; k < attributeNodeList.size(); ++k )
2084 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2085 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
2086 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
2089 featureInfoString.append(
"</TABLE>\n</BR>\n" );
2094 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2095 for (
int j = 0; j < attributeNodeList.size(); ++j )
2097 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2098 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
2099 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
2103 featureInfoString.append(
"</TABLE>\n<BR></BR>\n" );
2107 featureInfoString.append(
"</BODY>\n" );
2109 return featureInfoString.toUtf8();
2112 QByteArray QgsRenderer::convertFeatureInfoToText(
const QDomDocument &doc )
const 2114 QString featureInfoString;
2117 featureInfoString.append(
"GetFeatureInfo results\n" );
2118 featureInfoString.append(
"\n" );
2120 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2123 for (
int i = 0; i < layerList.size(); ++i )
2125 QDomElement layerElem = layerList.at( i ).toElement();
2127 featureInfoString.append(
"Layer '" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"'\n" );
2130 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2131 QDomElement currentFeatureElement;
2133 if ( !featureNodeList.isEmpty() )
2135 for (
int j = 0; j < featureNodeList.size(); ++j )
2137 QDomElement featureElement = featureNodeList.at( j ).toElement();
2138 featureInfoString.append(
"Feature " + featureElement.attribute( QStringLiteral(
"id" ) ) +
"\n" );
2141 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2142 for (
int k = 0; k < attributeNodeList.size(); ++k )
2144 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2145 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2146 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2152 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2153 for (
int j = 0; j < attributeNodeList.size(); ++j )
2155 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2156 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2157 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2161 featureInfoString.append(
"\n" );
2164 return featureInfoString.toUtf8();
2167 QByteArray QgsRenderer::convertFeatureInfoToJson(
const QList<QgsMapLayer *> &layers,
const QDomDocument &doc )
const 2171 {
"type",
"FeatureCollection" },
2172 {
"features", json::array() },
2176 const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2177 for (
int i = 0; i < layerList.size(); ++i )
2179 const QDomElement layerElem = layerList.at( i ).toElement();
2180 const QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
2185 if ( mContext.
layerNickname( *l ).compare( layerName ) == 0 )
2201 const QDomNodeList featuresNode = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2202 if ( featuresNode.isEmpty() )
2205 for (
int j = 0; j < featuresNode.size(); ++j )
2207 const QDomElement featureNode = featuresNode.at( j ).toElement();
2208 const QgsFeatureId fid = featureNode.attribute( QStringLiteral(
"id" ) ).toLongLong();
2214 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
2215 for (
int k = 0; k < attrs.count(); k++ )
2217 const QDomElement elm = attrs.at( k ).toElement();
2218 if ( elm.attribute( QStringLiteral(
"name" ) ).compare(
"geometry" ) == 0 )
2225 if ( ! wkt.isEmpty() )
2231 features << feature;
2234 if ( !attributes.isEmpty() )
2237 const QDomNodeList attributesNode = featureNode.elementsByTagName( QStringLiteral(
"Attribute" ) );
2238 for (
int k = 0; k < attributesNode.size(); ++k )
2240 const QDomElement attributeElement = attributesNode.at( k ).toElement();
2241 const QString fieldName = attributeElement.
attribute( QStringLiteral(
"name" ) );
2243 attributes << feature.fieldNameIndex( fieldName );
2254 for (
const auto &feature : qgis::as_const( features ) )
2262 auto properties = json::object();
2263 const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2264 for (
int j = 0; j < attributesNode.size(); ++j )
2266 const QDomElement attrElmt = attributesNode.at( j ).toElement();
2267 const QString name = attrElmt.attribute( QStringLiteral(
"name" ) );
2268 const QString value = attrElmt.attribute( QStringLiteral(
"value" ) );
2269 properties[name.toStdString()] = value.toStdString();
2272 json[
"features"].push_back(
2274 {
"type",
"Feature" },
2275 {
"id", layer->
name().toStdString() },
2276 {
"properties", properties }
2282 return QByteArray::fromStdString( json.dump( 2 ) );
2284 return QByteArray::fromStdString( json.dump() );
2288 QDomElement QgsRenderer::createFeatureGML(
2297 QStringList *attributes )
const 2300 QDomElement typeNameElement = doc.createElement(
"qgs:" + typeName );
2301 typeNameElement.setAttribute( QStringLiteral(
"fid" ), typeName +
"." + QString::number( feat->
id() ) );
2304 if ( layer && layer->
crs() !=
crs )
2330 box = transformedBox;
2338 QDomElement bbElem = doc.createElement( QStringLiteral(
"gml:boundedBy" ) );
2339 QDomElement boxElem;
2351 boxElem.setAttribute( QStringLiteral(
"srsName" ), crs.
authid() );
2353 bbElem.appendChild( boxElem );
2354 typeNameElement.appendChild( bbElem );
2357 if ( withGeom && !geom.
isNull() )
2366 QDomElement geomElem = doc.createElement( QStringLiteral(
"qgs:geometry" ) );
2367 QDomElement gmlElem;
2377 if ( !gmlElem.isNull() )
2381 gmlElem.setAttribute( QStringLiteral(
"srsName" ), crs.
authid() );
2383 geomElem.appendChild( gmlElem );
2384 typeNameElement.appendChild( geomElem );
2391 for (
int i = 0; i < fields.
count(); ++i )
2393 QString attributeName = fields.
at( i ).
name();
2400 if ( attributes && !attributes->contains( attributeName ) )
2405 QDomElement fieldElem = doc.createElement(
"qgs:" + attributeName.replace(
' ',
'_' ) );
2406 QString fieldTextString = featureAttributes.at( i ).toString();
2411 QDomText fieldText = doc.createTextNode( fieldTextString );
2412 fieldElem.appendChild( fieldText );
2413 typeNameElement.appendChild( fieldElem );
2421 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
2424 QDomElement fieldElem = doc.createElement( QStringLiteral(
"qgs:maptip" ) );
2425 QDomText maptipText = doc.createTextNode( fieldTextString );
2426 fieldElem.appendChild( maptipText );
2427 typeNameElement.appendChild( fieldElem );
2431 return typeNameElement;
2434 QString QgsRenderer::replaceValueMapAndRelation(
QgsVectorLayer *vl,
int idx,
const QVariant &attributeVal )
2438 QString value( fieldFormatter->
representValue( vl, idx, setup.
config(), QVariant(), attributeVal ) );
2440 if ( setup.
config().value( QStringLiteral(
"AllowMulti" ) ).toBool() && value.startsWith( QLatin1String(
"{" ) ) && value.endsWith( QLatin1String(
"}" ) ) )
2442 value = value.mid( 1, value.size() - 2 );
2454 double mapUnitTolerance = 0.0;
2464 mapUnitTolerance = mapSettings.
extent().
width() / 400.0;
2476 mapUnitTolerance = mapSettings.
extent().
width() / 200.0;
2488 mapUnitTolerance = mapSettings.
extent().
width() / 100.0;
2492 QgsRectangle mapRectangle( infoPoint.
x() - mapUnitTolerance, infoPoint.
y() - mapUnitTolerance,
2493 infoPoint.
x() + mapUnitTolerance, infoPoint.
y() + mapUnitTolerance );
2497 QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
2499 QList<QgsMapLayer *> highlightLayers;
2502 QString crs = mWmsParameters.
crs();
2506 QDomDocument sldDoc;
2507 if ( !sldDoc.setContent( param.mSld,
true ) )
2514 std::unique_ptr<QgsFeatureRenderer> renderer;
2515 QDomElement el = sldDoc.documentElement();
2525 QString url = typeName +
"?crs=" +
crs;
2526 if ( ! param.mLabel.isEmpty() )
2528 url +=
"&field=label:string";
2533 std::unique_ptr<QgsVectorLayer> layer = qgis::make_unique<QgsVectorLayer>( url, param.mName, QLatin1Literal(
"memory" ), options );
2534 if ( !layer->isValid() )
2541 if ( ! param.mLabel.isEmpty() )
2552 switch ( param.mGeom.type() )
2557 palSettings.
dist = 2;
2568 QVariant x( pt.
x() );
2572 QVariant y( pt.
y() );
2576 QVariant hali(
"Center" );
2580 QVariant vali(
"Half" );
2587 palSettings.
dist = 2;
2596 if ( param.mColor.isValid() )
2598 textFormat.
setColor( param.mColor );
2601 if ( param.mSize > 0 )
2603 textFormat.
setSize( param.mSize );
2611 if ( ! param.mFont.isEmpty() )
2613 textFormat.
setFont( param.mFont );
2616 if ( param.mBufferColor.isValid() )
2618 bufferSettings.
setColor( param.mBufferColor );
2621 if ( param.mBufferSize > 0 )
2624 bufferSettings.
setSize( static_cast<double>( param.mBufferSize ) );
2631 layer->setLabeling( simpleLabeling );
2632 layer->setLabelsEnabled(
true );
2634 fet.setGeometry( param.mGeom );
2638 layer->setRenderer( renderer.release() );
2641 if ( layer->isValid() )
2643 highlightLayers.append( layer.release() );
2647 mTemporaryLayers.append( highlightLayers );
2648 return highlightLayers;
2651 QList<QgsMapLayer *> QgsRenderer::externalLayers(
const QList<QgsWmsParametersExternalLayer> ¶ms )
2653 QList<QgsMapLayer *> layers;
2657 std::unique_ptr<QgsMapLayer> layer = qgis::make_unique< QgsRasterLayer >( param.mUri, param.mName, QStringLiteral(
"wms" ) );
2659 if ( layer->isValid() )
2662 mTemporaryLayers.append( layer.release() );
2663 layers << mTemporaryLayers.last();
2670 void QgsRenderer::removeTemporaryLayers()
2672 qDeleteAll( mTemporaryLayers );
2673 mTemporaryLayers.clear();
2676 QPainter *QgsRenderer::layersRendering(
const QgsMapSettings &mapSettings, QImage &image )
const 2678 QPainter *painter =
nullptr;
2682 #ifdef HAVE_SERVER_PYTHON_PLUGINS 2683 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
2687 renderJob.
render( mapSettings, &image );
2688 painter = renderJob.takePainter();
2690 if ( !renderJob.errors().isEmpty() )
2692 QString layerWMSName;
2693 QString firstErrorLayerId = renderJob.errors().at( 0 ).layerID;
2700 throw QgsException( QStringLiteral(
"Map rendering error in layer '%1'" ).arg( layerWMSName ) );
2706 void QgsRenderer::setLayerOpacity(
QgsMapLayer *layer,
int opacity )
const 2708 if ( opacity >= 0 && opacity <= 255 )
2710 switch ( layer->
type() )
2723 rasterRenderer->
setOpacity( opacity / 255. );
2734 void QgsRenderer::setLayerFilter(
QgsMapLayer *layer,
const QList<QgsWmsParametersFilter> &filters )
2739 QStringList expList;
2745 QDomDocument filterXml;
2747 if ( !filterXml.setContent( filter.mFilter,
true, &errorMsg ) )
2750 QStringLiteral(
"Filter string rejected. Error message: %1. The XML string was: %2" ).arg( errorMsg, filter.mFilter ) );
2752 QDomElement filterElem = filterXml.firstChildElement();
2757 expList << filterExp->dump();
2763 if ( !testFilterStringSafety( filter.mFilter ) )
2766 " has been rejected because of security reasons." 2767 " Note: Text strings have to be enclosed in single or double quotes." 2768 " A space between each word / special character is mandatory." 2769 " Allowed Keywords and special characters are " 2770 " IS,NOT,NULL,AND,OR,IN,=,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX." 2771 " Not allowed are semicolons in the filter expression." ).arg(
2775 QString newSubsetString = filter.mFilter;
2778 newSubsetString.prepend(
") AND (" );
2779 newSubsetString.append(
")" );
2780 newSubsetString.prepend( filteredLayer->
subsetString() );
2781 newSubsetString.prepend(
"(" );
2787 expList.append( dimensionFilter( filteredLayer ) );
2791 if ( expList.size() == 1 )
2795 else if ( expList.size() > 1 )
2797 exp = QStringLiteral(
"( %1 )" ).arg( expList.join( QStringLiteral(
" ) AND ( " ) ) );
2799 if ( !exp.isEmpty() )
2801 std::unique_ptr<QgsExpression> expression(
new QgsExpression( exp ) );
2804 mFeatureFilter.
setFilter( filteredLayer, *expression );
2810 QStringList QgsRenderer::dimensionFilter(
QgsVectorLayer *layer )
const 2812 QStringList expList;
2815 if ( wmsDims.isEmpty() )
2825 if ( fieldIndex == -1 )
2830 int endFieldIndex = -1;
2831 if ( !dim.endFieldName.isEmpty() )
2833 endFieldIndex = layer->
fields().
indexOf( dim.endFieldName );
2834 if ( endFieldIndex == -1 )
2840 if ( !dimParamValues.contains( dim.name.toUpper() ) )
2850 defValue = dim.referenceValue;
2855 QSet<QVariant> uniqueValues = layer->
uniqueValues( fieldIndex );
2856 if ( endFieldIndex != -1 )
2858 uniqueValues.unite( layer->
uniqueValues( endFieldIndex ) );
2861 QList<QVariant> values = uniqueValues.toList();
2862 std::sort( values.begin(), values.end() );
2865 defValue = values.first();
2869 defValue = values.last();
2873 if ( endFieldIndex == -1 )
2879 QStringList expElems;
2884 expList << expElems.join(
' ' );
2892 QString dimParamValue = dimParamValues[dim.name.toUpper()];
2894 QStringList dimExplist;
2896 QStringList dimValues = dimParamValue.split(
',' );
2897 for (
int i = 0; i < dimValues.size(); ++i )
2899 QString dimValue = dimValues[i];
2901 if ( dimValue.size() > 1 )
2903 dimValue = dimValue.trimmed();
2906 if ( dimValue.contains(
'/' ) )
2908 QStringList rangeValues = dimValue.split(
'/' );
2910 if ( rangeValues.size() != 2 )
2915 QVariant rangeMin = QVariant( rangeValues[0] );
2916 QVariant rangeMax = QVariant( rangeValues[1] );
2927 QStringList expElems;
2928 if ( endFieldIndex == -1 )
2948 << QStringLiteral(
")" );
2950 dimExplist << expElems.join(
' ' );
2954 QVariant dimVariant = QVariant( dimValue );
2960 if ( endFieldIndex == -1 )
2969 QStringList expElems;
2974 dimExplist << expElems.join(
' ' );
2979 if ( dimExplist.size() == 1 )
2981 expList << dimExplist;
2983 else if ( dimExplist.size() > 1 )
2985 expList << QStringLiteral(
"( %1 )" ).arg( dimExplist.join( QStringLiteral(
" ) OR ( " ) ) );
2992 void QgsRenderer::setLayerSelection(
QgsMapLayer *layer,
const QStringList &fids )
const 2998 for (
const QString &
id : fids )
3008 void QgsRenderer::setLayerAccessControlFilter(
QgsMapLayer *layer )
const 3010 #ifdef HAVE_SERVER_PYTHON_PLUGINS 3028 void QgsRenderer::annotationsRendering( QPainter *painter )
const 3031 const QList< QgsAnnotation * > annotations = annotationManager->
annotations();
3037 if ( !annotation || !annotation->isVisible() )
3040 annotation->render( renderContext );
3044 QImage *QgsRenderer::scaleImage(
const QImage *image )
const 3049 QImage *scaledImage =
nullptr;
3050 const int width = mWmsParameters.
widthAsInt();
3052 if ( width != image->width() || height != image->height() )
3054 scaledImage =
new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
3060 void QgsRenderer::handlePrintErrors(
const QgsLayout *layout )
const 3066 QList< QgsLayoutItemMap * > mapList;
3069 QList< QgsLayoutItemMap * >::const_iterator mapIt = mapList.constBegin();
3070 for ( ; mapIt != mapList.constEnd(); ++mapIt )
3072 if ( !( *mapIt )->renderingErrors().isEmpty() )
3084 for (
auto layer : layers )
3095 setLayerSld( layer, mContext.
sld( *layer ) );
3099 setLayerStyle( layer, mContext.
style( *layer ) );
3104 setLayerOpacity( layer, param.
mOpacity );
3109 setLayerFilter( layer, param.
mFilter );
3114 setLayerSelection( layer, param.
mSelection );
3119 updateExtent( layer, *settings );
3124 setLayerAccessControlFilter( layer );
3139 void QgsRenderer::setLayerStyle(
QgsMapLayer *layer,
const QString &style )
const 3141 if ( style.isEmpty() )
3150 QStringLiteral(
"Style '%1' does not exist for layer '%2'" ).arg( style, layer->
name() ) );
3154 void QgsRenderer::setLayerSld(
QgsMapLayer *layer,
const QDomElement &sld )
const 3166 if ( !mWmsParameters.
bbox().isEmpty() )
3170 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
3171 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.
Q_INVOKABLE 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.
Represents a raster layer.
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...
Q_INVOKABLE 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.
Q_INVOKABLE 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.
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.
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 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...
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model)
Returns the map legend as a JSON object.
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.
QgsVectorLayerServerProperties * serverProperties() const
Returns QGIS Server Properties of the vector layer.
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 print layouts, atlases and reports within the pro...
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.
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 setTransformGeometries(bool activate)
Sets whether geometries should be transformed in EPSG 4326 (default behavior) or just keep as it is...
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 exportLegendToJson(const QgsRenderContext &context, QJsonObject &json)
Renders the legend in a json object.
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.
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.
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects matching features using a list of feature IDs.
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.
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.
Q_INVOKABLE 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...
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.
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
void setOpacity(double opacity)
Sets the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1...