69 #include <QStringList> 70 #include <QTemporaryFile> 73 #include <nlohmann/json.hpp> 103 mWmsParameters.
dump();
108 removeTemporaryLayers();
114 std::unique_ptr<QgsLayerRestorer> restorer;
119 configureLayers( layers );
126 std::unique_ptr<QImage> image;
129 const QSize size( minSize.width() * dpmm, minSize.height() * dpmm );
130 image.reset( createImage( size ) );
133 std::unique_ptr<QPainter> painter;
134 painter.reset(
new QPainter( image.get() ) );
135 painter->setRenderHint( QPainter::Antialiasing,
true );
136 painter->scale( dpmm, dpmm );
142 return image.release();
148 std::unique_ptr<QgsLayerRestorer> restorer;
153 configureLayers( layers );
157 std::unique_ptr<QImage> image( createImage( size ) );
161 std::unique_ptr<QPainter> painter;
162 painter.reset(
new QPainter( image.get() ) );
163 painter->setRenderHint( QPainter::Antialiasing,
true );
164 painter->scale( dpmm, dpmm );
171 ctx.
point = QPointF();
172 nodeModel.
drawSymbol( settings, &ctx, size.height() / dpmm );
175 return image.release();
182 for (
const QString &
id : mapSettings.
layerIds() )
199 runHitTestLayer( vl, usedSymbols, context );
205 std::unique_ptr< QgsFeatureRenderer > r( vl->
renderer()->
clone() );
207 r->startRender( context, vl->
fields() );
215 if ( moreSymbolsPerFeature )
217 for (
QgsSymbol *s : r->originalSymbolsForFeature( f, context ) )
223 r->stopRender( context );
232 QStringLiteral(
"The requested map size is too large" ) );
236 std::unique_ptr<QgsLayerRestorer> restorer;
242 configureLayers( layers, &mapSettings );
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" ) );
390 configureLayers( layers, &mapSettings );
393 std::unique_ptr<QImage> image(
new QImage() );
394 configureMapSettings( image.get(), mapSettings );
400 configurePrintLayout( layout.get(), mapSettings, atlas );
406 QTemporaryFile tempOutputFile( QDir::tempPath() +
'/' + QStringLiteral(
"XXXXXX.%1" ).arg( extension ) );
407 if ( !tempOutputFile.open() )
409 throw QgsException( QStringLiteral(
"Could not open temporary file for the GetPrint request." ) );
418 if ( !mWmsParameters.
dpi().isEmpty() )
421 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
423 exportSettings.
dpi = dpi;
430 atlas->beginRender();
434 atlasSvgExport.
exportToSvg( tempOutputFile.fileName(), exportSettings );
440 exporter.
exportToSvg( tempOutputFile.fileName(), exportSettings );
449 double dpi( layout->renderContext().dpi( ) );
450 if ( !mWmsParameters.
dpi().isEmpty() )
453 double _dpi = mWmsParameters.
dpi().toDouble( &ok );
457 exportSettings.
dpi = dpi;
461 QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
462 QgsLayoutMeasurement width( layout->convertFromLayoutUnits( layoutSize.width(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
463 QgsLayoutMeasurement height( layout->convertFromLayoutUnits( layoutSize.height(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
464 exportSettings.
imageSize = QSize( static_cast<int>( width.length() * dpi / 25.4 ), static_cast<int>( height.
length() * dpi / 25.4 ) );
466 exportSettings.
pages.append( 0 );
470 atlas->beginRender();
474 atlasPngExport.
exportToImage( tempOutputFile.fileName(), exportSettings );
480 exporter.
exportToImage( tempOutputFile.fileName(), exportSettings );
488 if ( !mWmsParameters.
dpi().isEmpty() )
491 double dpi( mWmsParameters.
dpi().toDouble( &ok ) );
493 exportSettings.
dpi = dpi;
498 exportSettings.
rasterizeWholeImage = layout->customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
504 exporter.
exportToPdf( atlas, tempOutputFile.fileName(), exportSettings, exportError );
508 exporter.exportToPdf( tempOutputFile.fileName(), exportSettings );
519 handlePrintErrors( atlas->layout() );
523 handlePrintErrors( layout.get() );
526 return tempOutputFile.readAll();
533 QList<QgsLayoutItemMap *> maps;
539 for (
const auto &map : qgis::as_const( maps ) )
544 if ( !atlasPrint || !map->atlasDriven() )
568 if ( cMapParams.
mScale > 0 )
570 map->setScale( cMapParams.
mScale );
576 map->setMapRotation( cMapParams.
mRotation );
580 if ( !map->keepLayerSet() )
584 map->setLayers( mapSettings.
layers() );
588 QList<QgsMapLayer *> layerSet;
589 for (
auto layer : cMapParams.
mLayers )
598 setLayerStyle( mlayer, layer.mStyle );
604 std::reverse( layerSet.begin(), layerSet.end() );
605 map->setLayers( layerSet );
607 map->setKeepLayerSet(
true );
613 map->grid()->setIntervalX( cMapParams.
mGridX );
614 map->grid()->setIntervalY( cMapParams.
mGridY );
619 QList<QgsLayoutItemLabel *> labels;
621 for (
const auto &label : qgis::as_const( labels ) )
624 const QString labelId = label->
id();
625 const QString labelParam = mWmsParameters.
layoutParameter( labelId, ok );
630 if ( labelParam.isEmpty() )
634 c->removeItem( label );
639 label->setText( labelParam );
643 QList<QgsLayoutItemHtml *> htmls;
645 for (
const auto &html : qgis::as_const( htmls ) )
647 if ( html->frameCount() == 0 )
652 const QString htmlId = htmlFrame->
id();
671 html->setUrl( newUrl );
677 QList<QgsLayoutItemLegend *> legends;
679 for (
const auto &legend : qgis::as_const( legends ) )
681 if ( legend->autoUpdateModel() )
691 legend->setAutoUpdateModel(
false );
695 QStringList layerSet;
696 const QList<QgsMapLayer *> layerList( map->
layers() );
697 for (
const auto &layer : layerList )
698 layerSet << layer->id();
710 for (
const auto &layerId : layerIds )
717 if ( !layerSet.contains( layerId ) )
742 QStringLiteral(
"The requested map size is too large" ) );
746 std::unique_ptr<QgsLayerRestorer> restorer;
753 configureLayers( layers, &mapSettings );
756 std::unique_ptr<QPainter> painter;
757 std::unique_ptr<QImage> image( createImage( mContext.
mapSize() ) );
760 configureMapSettings( image.get(), mapSettings );
766 painter.reset( layersRendering( mapSettings, *image ) );
769 annotationsRendering( painter.get() );
775 QImage *scaledImage = scaleImage( image.get() );
777 image.reset( scaledImage );
780 return image.release();
786 std::unique_ptr<QgsLayerRestorer> restorer;
791 configureLayers( layers );
795 QList< QgsDxfExport::DxfLayer > dxfLayers;
807 int layerAttribute = -1;
808 if ( attributes.size() > layerIdx )
822 if ( mWmsParameters.
dxfFormatOptions().contains( QgsWmsParameters::DxfFormatOption::SCALE ) )
833 if ( i < 0 || i > mapSettings.
outputSize().width() )
841 if ( j < 0 || j > mapSettings.
outputSize().height() )
866 const bool ijDefined = !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty();
867 const bool xyDefined = !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty();
868 const bool filtersDefined = !mWmsParameters.
filters().isEmpty();
869 const bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
871 if ( !ijDefined && !xyDefined && !filtersDefined && !filterGeomDefined )
875 if ( mWmsParameters.
j().isEmpty() )
882 if ( infoFormat == QgsWmsParameters::Format::NONE )
889 std::unique_ptr<QImage> outputImage( createImage( mContext.
mapSize() ) );
892 std::unique_ptr<QgsLayerRestorer> restorer;
897 bool mandatoryCrsParam =
true;
898 if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.
crs().isEmpty() )
900 mandatoryCrsParam =
false;
905 configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
916 configureLayers( layers, &mapSettings );
921 QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );
925 if ( infoFormat == QgsWmsParameters::Format::TEXT )
926 ba = convertFeatureInfoToText( result );
927 else if ( infoFormat == QgsWmsParameters::Format::HTML )
928 ba = convertFeatureInfoToHtml( result );
929 else if ( infoFormat == QgsWmsParameters::Format::JSON )
930 ba = convertFeatureInfoToJson( layers, result );
932 ba = result.toByteArray();
937 QImage *QgsRenderer::createImage(
const QSize &size )
const 939 std::unique_ptr<QImage> image;
947 image = qgis::make_unique<QImage>( size, QImage::Format_ARGB32_Premultiplied );
952 image = qgis::make_unique<QImage>( size, QImage::Format_RGB32 );
957 if ( image->isNull() )
959 throw QgsException( QStringLiteral(
"createImage: image could not be created, check for out of memory conditions" ) );
962 const qreal dpm = mContext.
dotsPerMm() * 1000.0;
963 image->setDotsPerMeterX( dpm );
964 image->setDotsPerMeterY( dpm );
966 return image.release();
969 void QgsRenderer::configureMapSettings(
const QPaintDevice *paintDevice,
QgsMapSettings &mapSettings,
bool mandatoryCrsParam )
const 973 throw QgsException( QStringLiteral(
"configureMapSettings: no paint device" ) );
976 mapSettings.
setOutputSize( QSize( paintDevice->width(), paintDevice->height() ) );
981 if ( !mWmsParameters.
bbox().isEmpty() && mapExtent.
isEmpty() )
987 QString
crs = mWmsParameters.
crs();
988 if ( crs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 )
990 crs = QString(
"EPSG:4326" );
993 else if ( crs.isEmpty() && !mandatoryCrsParam )
995 crs = QString(
"EPSG:4326" );
1044 else if ( backgroundColor.isValid() )
1061 int myRed = mProject->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
1062 int myGreen = mProject->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
1063 int myBlue = mProject->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
1064 int myAlpha = mProject->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
1068 QDomDocument QgsRenderer::featureInfoDocument( QList<QgsMapLayer *> &layers,
const QgsMapSettings &mapSettings,
1069 const QImage *outputImage,
const QString &version )
const 1073 bool ijDefined = ( !mWmsParameters.
i().isEmpty() && !mWmsParameters.
j().isEmpty() );
1075 bool xyDefined = ( !mWmsParameters.
x().isEmpty() && !mWmsParameters.
y().isEmpty() );
1077 bool filtersDefined = !mWmsParameters.
filters().isEmpty();
1079 bool filterGeomDefined = !mWmsParameters.
filterGeom().isEmpty();
1082 if ( featureCount < 1 )
1087 int i = mWmsParameters.
iAsInt();
1088 int j = mWmsParameters.
jAsInt();
1089 if ( xyDefined && !ijDefined )
1091 i = mWmsParameters.
xAsInt();
1092 j = mWmsParameters.
yAsInt();
1096 if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
1098 i *= ( outputImage->width() /
static_cast<double>( width ) );
1099 j *= ( outputImage->height() /
static_cast<double>( height ) );
1103 std::unique_ptr<QgsRectangle> featuresRect;
1104 std::unique_ptr<QgsGeometry> filterGeom;
1105 std::unique_ptr<QgsPointXY> infoPoint;
1107 if ( i != -1 && j != -1 )
1110 infoPointToMapCoordinates( i, j, infoPoint.get(), mapSettings );
1112 else if ( filtersDefined )
1116 else if ( filterGeomDefined )
1121 QDomDocument result;
1123 QDomElement getFeatureInfoElement;
1125 if ( infoFormat == QgsWmsParameters::Format::GML )
1127 getFeatureInfoElement = result.createElement( QStringLiteral(
"wfs:FeatureCollection" ) );
1128 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:wfs" ), QStringLiteral(
"http://www.opengis.net/wfs" ) );
1129 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1130 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1131 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
1132 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1133 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:qgs" ), QStringLiteral(
"http://qgis.org/gml" ) );
1134 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1135 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" ) );
1140 if ( featureInfoElemName.isEmpty() )
1142 featureInfoElemName = QStringLiteral(
"GetFeatureInfoResponse" );
1145 if ( featureInfoElemNs.isEmpty() )
1147 getFeatureInfoElement = result.createElement( featureInfoElemName );
1151 getFeatureInfoElement = result.createElementNS( featureInfoElemNs, featureInfoElemName );
1155 if ( !featureInfoSchema.isEmpty() )
1157 getFeatureInfoElement.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1158 getFeatureInfoElement.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), featureInfoSchema );
1161 result.appendChild( getFeatureInfoElement );
1171 for (
const QString &queryLayer : queryLayers )
1173 bool validLayer =
false;
1174 bool queryableLayer =
true;
1181 if ( !queryableLayer )
1186 QDomElement layerElement;
1187 if ( infoFormat == QgsWmsParameters::Format::GML )
1189 layerElement = getFeatureInfoElement;
1193 layerElement = result.createElement( QStringLiteral(
"Layer" ) );
1194 QString layerName = queryLayer;
1197 QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.constFind( layerName );
1198 if ( layerAliasIt != layerAliasMap.constEnd() )
1200 layerName = layerAliasIt.value();
1203 layerElement.setAttribute( QStringLiteral(
"name" ), layerName );
1204 getFeatureInfoElement.appendChild( layerElement );
1207 layerElement.setAttribute( QStringLiteral(
"id" ), layer->id() );
1216 ( void )featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, featuresRect.get(), filterGeom.get() );
1236 if ( infoFormat == QgsWmsParameters::Format::GML )
1238 layerElement = result.createElement( QStringLiteral(
"gml:featureMember" ) );
1239 getFeatureInfoElement.appendChild( layerElement );
1242 ( void )featureInfoFromRasterLayer( rasterLayer, mapSettings, &layerInfoPoint, result, layerElement, version );
1250 param.
mValue = queryLayer;
1254 else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.
isValidGroup( queryLayer ) ) )
1257 param.
mValue = queryLayer;
1259 bool hasGroupAndQueryable {
false };
1264 for (
const auto &ql : constNicks )
1268 const auto &constLayers { mContext.
layerGroups()[ql] };
1269 for (
const auto &ml : constLayers )
1271 if ( ( ! ml->shortName().isEmpty() && ml->shortName() == queryLayer ) || ( ml->name() == queryLayer ) )
1277 hasGroupAndQueryable =
true;
1286 if ( ! hasGroupAndQueryable )
1296 if ( infoFormat == QgsWmsParameters::Format::GML )
1298 QDomElement bBoxElem = result.createElement( QStringLiteral(
"gml:boundedBy" ) );
1299 QDomElement boxElem;
1301 if ( gmlVersion < 3 )
1311 if ( crs.isValid() )
1313 boxElem.setAttribute( QStringLiteral(
"srsName" ), crs.authid() );
1315 bBoxElem.appendChild( boxElem );
1316 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1320 QDomElement bBoxElem = result.createElement( QStringLiteral(
"BoundingBox" ) );
1322 bBoxElem.setAttribute( QStringLiteral(
"minx" ),
qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1323 bBoxElem.setAttribute( QStringLiteral(
"maxx" ),
qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1324 bBoxElem.setAttribute( QStringLiteral(
"miny" ),
qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1325 bBoxElem.setAttribute( QStringLiteral(
"maxy" ),
qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
1326 getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() );
1330 if ( sia2045 && infoFormat == QgsWmsParameters::Format::XML )
1332 convertFeatureInfoToSia2045( result );
1338 bool QgsRenderer::featureInfoFromVectorLayer(
QgsVectorLayer *layer,
1341 QDomDocument &infoDocument,
1342 QDomElement &layerElement,
1345 const QString &version,
1357 std::unique_ptr<QgsGeometry> layerFilterGeom;
1360 layerFilterGeom.reset(
new QgsGeometry( *filterGeom ) );
1374 searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
1376 else if ( layerFilterGeom )
1378 searchRect = layerFilterGeom->boundingBox();
1380 else if ( !mWmsParameters.
bbox().isEmpty() )
1382 searchRect = layerRect;
1389 int featureCounter = 0;
1396 bool hasGeometry = addWktGeometry || featureBBox || layerFilterGeom;
1409 if ( layerFilterGeom )
1411 fReq.
setFilterExpression( QString(
"intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
1414 #ifdef HAVE_SERVER_PYTHON_PLUGINS 1415 mContext.accessControl()->filterFeatures( layer, fReq );
1417 QStringList attributes;
1418 for (
const QgsField &field : fields )
1420 attributes.append( field.name() );
1422 attributes = mContext.accessControl()->layerAttributes( layer, attributes );
1427 std::unique_ptr< QgsFeatureRenderer > r2( layer->
renderer() ? layer->
renderer()->
clone() : nullptr );
1430 r2->startRender( renderContext, layer->
fields() );
1433 bool featureBBoxInitialized =
false;
1442 if ( featureCounter > nFeatures )
1457 bool render = r2->willRenderFeature( feature, renderContext );
1470 if ( !featureBBoxInitialized && featureBBox->
isEmpty() )
1473 featureBBoxInitialized =
true;
1488 if ( mWmsParameters.
infoFormat() == QgsWmsParameters::Format::GML )
1493 QDomElement elem = createFeatureGML(
1494 &feature, layer, infoDocument, outputCrs, mapSettings, typeName, withGeom, gmlVersion
1495 #ifdef HAVE_SERVER_PYTHON_PLUGINS
1499 QDomElement featureMemberElem = infoDocument.createElement( QStringLiteral(
"gml:featureMember" ) );
1500 featureMemberElem.appendChild( elem );
1501 layerElement.appendChild( featureMemberElem );
1506 QDomElement featureElement = infoDocument.createElement( QStringLiteral(
"Feature" ) );
1507 featureElement.setAttribute( QStringLiteral(
"id" ),
FID_TO_STRING( feature.
id() ) );
1508 layerElement.appendChild( featureElement );
1512 for (
int i = 0; i < featureAttributes.count(); ++i )
1515 if ( excludedAttributes.contains( fields.at( i ).name() ) )
1519 #ifdef HAVE_SERVER_PYTHON_PLUGINS 1521 if ( !attributes.contains( fields.at( i ).name() ) )
1530 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1531 attributeElement.setAttribute( QStringLiteral(
"name" ), attributeName );
1533 attributeElement.setAttribute( QStringLiteral(
"value" ),
1535 replaceValueMapAndRelation(
1537 featureAttributes[i] ),
1540 featureElement.appendChild( attributeElement );
1545 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
1547 QDomElement maptipElem = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1548 maptipElem.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"maptip" ) );
1550 featureElement.appendChild( maptipElem );
1556 QDomElement bBoxElem = infoDocument.createElement( QStringLiteral(
"BoundingBox" ) );
1557 bBoxElem.setAttribute( version == QLatin1String(
"1.1.1" ) ?
"SRS" :
"CRS", outputCrs.
authid() );
1562 featureElement.appendChild( bBoxElem );
1578 if ( segmentizeWktGeometry )
1586 geom.
set( segmentizedGeom );
1590 QDomElement geometryElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1591 geometryElement.setAttribute( QStringLiteral(
"name" ), QStringLiteral(
"geometry" ) );
1592 geometryElement.setAttribute( QStringLiteral(
"value" ), geom.
asWkt( mContext.
precision() ) );
1593 geometryElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"derived" ) );
1594 featureElement.appendChild( geometryElement );
1601 r2->stopRender( renderContext );
1607 bool QgsRenderer::featureInfoFromRasterLayer(
QgsRasterLayer *layer,
1610 QDomDocument &infoDocument,
1611 QDomElement &layerElement,
1612 const QString &version )
const 1641 if ( !identifyResult.
isValid() )
1644 QMap<int, QVariant> attributes = identifyResult.
results();
1646 if ( mWmsParameters.
infoFormat() == QgsWmsParameters::Format::GML )
1652 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
1655 feature.
setAttribute( index++, QString::number( it.value().toDouble() ) );
1662 QDomElement elem = createFeatureGML(
1663 &feature,
nullptr, infoDocument, layerCrs, mapSettings, typeName,
false, gmlVersion,
nullptr );
1664 layerElement.appendChild( elem );
1668 for (
auto it = attributes.constBegin(); it != attributes.constEnd(); ++it )
1670 QDomElement attributeElement = infoDocument.createElement( QStringLiteral(
"Attribute" ) );
1671 attributeElement.setAttribute( QStringLiteral(
"name" ), layer->
bandName( it.key() ) );
1672 attributeElement.setAttribute( QStringLiteral(
"value" ), QString::number( it.value().toDouble() ) );
1673 layerElement.appendChild( attributeElement );
1679 bool QgsRenderer::testFilterStringSafety(
const QString &filter )
const 1682 if ( filter.contains( QLatin1String(
";" ) ) )
1687 QStringList tokens = filter.split(
' ', QString::SkipEmptyParts );
1688 groupStringList( tokens, QStringLiteral(
"'" ) );
1689 groupStringList( tokens, QStringLiteral(
"\"" ) );
1691 for (
auto tokenIt = tokens.constBegin() ; tokenIt != tokens.constEnd(); ++tokenIt )
1694 if ( tokenIt->compare( QLatin1String(
"," ) ) == 0
1695 || tokenIt->compare( QLatin1String(
"(" ) ) == 0
1696 || tokenIt->compare( QLatin1String(
")" ) ) == 0
1697 || tokenIt->compare( QLatin1String(
"=" ) ) == 0
1698 || tokenIt->compare( QLatin1String(
"!=" ) ) == 0
1699 || tokenIt->compare( QLatin1String(
"<" ) ) == 0
1700 || tokenIt->compare( QLatin1String(
"<=" ) ) == 0
1701 || tokenIt->compare( QLatin1String(
">" ) ) == 0
1702 || tokenIt->compare( QLatin1String(
">=" ) ) == 0
1703 || tokenIt->compare( QLatin1String(
"%" ) ) == 0
1704 || tokenIt->compare( QLatin1String(
"AND" ), Qt::CaseInsensitive ) == 0
1705 || tokenIt->compare( QLatin1String(
"OR" ), Qt::CaseInsensitive ) == 0
1706 || tokenIt->compare( QLatin1String(
"IN" ), Qt::CaseInsensitive ) == 0
1707 || tokenIt->compare( QLatin1String(
"LIKE" ), Qt::CaseInsensitive ) == 0
1708 || tokenIt->compare( QLatin1String(
"ILIKE" ), Qt::CaseInsensitive ) == 0
1709 || tokenIt->compare( QLatin1String(
"DMETAPHONE" ), Qt::CaseInsensitive ) == 0
1710 || tokenIt->compare( QLatin1String(
"SOUNDEX" ), Qt::CaseInsensitive ) == 0 )
1717 tokenIt->toDouble( &isNumeric );
1726 if ( *tokenIt == QLatin1String(
"''" ) )
1732 if ( tokenIt->size() > 2
1733 && ( *tokenIt )[0] == QChar(
'\'' )
1734 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'\'' )
1735 && ( *tokenIt )[1] != QChar(
'\'' )
1736 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'\'' ) )
1742 if ( tokenIt->size() > 2
1743 && ( *tokenIt )[0] == QChar(
'"' )
1744 && ( *tokenIt )[tokenIt->size() - 1] == QChar(
'"' )
1745 && ( *tokenIt )[1] != QChar(
'"' )
1746 && ( *tokenIt )[tokenIt->size() - 2] != QChar(
'"' ) )
1757 void QgsRenderer::groupStringList( QStringList &list,
const QString &groupString )
1760 bool groupActive =
false;
1761 int startGroup = -1;
1762 QString concatString;
1764 for (
int i = 0; i < list.size(); ++i )
1766 QString &str = list[i];
1767 if ( str.startsWith( groupString ) )
1771 concatString.clear();
1776 if ( i != startGroup )
1778 concatString.append(
" " );
1780 concatString.append( str );
1783 if ( str.endsWith( groupString ) )
1786 groupActive =
false;
1788 if ( startGroup != -1 )
1790 list[startGroup] = concatString;
1791 for (
int j = startGroup + 1; j <= endGroup; ++j )
1793 list.removeAt( startGroup + 1 );
1798 concatString.clear();
1804 void QgsRenderer::convertFeatureInfoToSia2045( QDomDocument &doc )
const 1806 QDomDocument SIAInfoDoc;
1807 QDomElement infoDocElement = doc.documentElement();
1808 QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement,
false ).toElement();
1809 SIAInfoDoc.appendChild( SIAInfoDocElement );
1811 QString currentAttributeName;
1812 QString currentAttributeValue;
1813 QDomElement currentAttributeElem;
1814 QString currentLayerName;
1815 QDomElement currentLayerElem;
1816 QDomNodeList layerNodeList = infoDocElement.elementsByTagName( QStringLiteral(
"Layer" ) );
1817 for (
int i = 0; i < layerNodeList.size(); ++i )
1819 currentLayerElem = layerNodeList.at( i ).toElement();
1820 currentLayerName = currentLayerElem.attribute( QStringLiteral(
"name" ) );
1822 QDomElement currentFeatureElem;
1824 QDomNodeList featureList = currentLayerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
1825 if ( featureList.isEmpty() )
1828 QDomNodeList attributeList = currentLayerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
1829 QDomElement rasterLayerElem;
1830 if ( !attributeList.isEmpty() )
1832 rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
1834 for (
int j = 0; j < attributeList.size(); ++j )
1836 currentAttributeElem = attributeList.at( j ).toElement();
1837 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
1838 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
1839 QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
1840 QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
1841 outAttributeElem.appendChild( outAttributeText );
1842 rasterLayerElem.appendChild( outAttributeElem );
1844 if ( !attributeList.isEmpty() )
1846 SIAInfoDocElement.appendChild( rasterLayerElem );
1852 QSet<QString> layerPropertyAttributes;
1853 QString currentLayerId = currentLayerElem.attribute( QStringLiteral(
"id" ) );
1854 if ( !currentLayerId.isEmpty() )
1859 QString WMSPropertyAttributesString = currentLayer->
customProperty( QStringLiteral(
"WMSPropertyAttributes" ) ).toString();
1860 if ( !WMSPropertyAttributesString.isEmpty() )
1862 QStringList propertyList = WMSPropertyAttributesString.split( QStringLiteral(
"//" ) );
1863 for (
auto propertyIt = propertyList.constBegin() ; propertyIt != propertyList.constEnd(); ++propertyIt )
1865 layerPropertyAttributes.insert( *propertyIt );
1871 QDomElement propertyRefChild;
1872 for (
int j = 0; j < featureList.size(); ++j )
1874 QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
1875 currentFeatureElem = featureList.at( j ).toElement();
1876 QDomNodeList attributeList = currentFeatureElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
1878 for (
int k = 0; k < attributeList.size(); ++k )
1880 currentAttributeElem = attributeList.at( k ).toElement();
1881 currentAttributeName = currentAttributeElem.attribute( QStringLiteral(
"name" ) );
1882 currentAttributeValue = currentAttributeElem.attribute( QStringLiteral(
"value" ) );
1883 if ( layerPropertyAttributes.contains( currentAttributeName ) )
1885 QDomElement propertyElem = SIAInfoDoc.createElement( QStringLiteral(
"property" ) );
1886 QDomElement identifierElem = SIAInfoDoc.createElement( QStringLiteral(
"identifier" ) );
1887 QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
1888 identifierElem.appendChild( identifierText );
1889 QDomElement valueElem = SIAInfoDoc.createElement( QStringLiteral(
"value" ) );
1890 QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
1891 valueElem.appendChild( valueText );
1892 propertyElem.appendChild( identifierElem );
1893 propertyElem.appendChild( valueElem );
1894 if ( propertyRefChild.isNull() )
1896 SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
1897 propertyRefChild = propertyElem;
1901 SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
1906 QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
1907 QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
1908 SIAAttributeElem.appendChild( SIAAttributeText );
1909 SIAFeatureElem.appendChild( SIAAttributeElem );
1912 SIAInfoDocElement.appendChild( SIAFeatureElem );
1919 QByteArray QgsRenderer::convertFeatureInfoToHtml(
const QDomDocument &doc )
const 1921 QString featureInfoString;
1924 featureInfoString.append(
"<HEAD>\n" );
1925 featureInfoString.append(
"<TITLE> GetFeatureInfo results </TITLE>\n" );
1926 featureInfoString.append(
"<META http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n" );
1927 featureInfoString.append(
"</HEAD>\n" );
1930 featureInfoString.append(
"<BODY>\n" );
1932 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
1935 for (
int i = 0; i < layerList.size(); ++i )
1937 QDomElement layerElem = layerList.at( i ).toElement();
1939 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
1940 featureInfoString.append(
"<TR><TH width=25%>Layer</TH><TD>" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"</TD></TR>\n" );
1941 featureInfoString.append(
"</BR>" );
1944 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
1945 QDomElement currentFeatureElement;
1947 if ( !featureNodeList.isEmpty() )
1949 for (
int j = 0; j < featureNodeList.size(); ++j )
1951 QDomElement featureElement = featureNodeList.at( j ).toElement();
1952 featureInfoString.append(
"<TABLE border=1 width=100%>\n" );
1953 featureInfoString.append(
"<TR><TH>Feature</TH><TD>" + featureElement.attribute( QStringLiteral(
"id" ) ) +
1957 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
1958 for (
int k = 0; k < attributeNodeList.size(); ++k )
1960 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
1961 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
1962 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
1965 featureInfoString.append(
"</TABLE>\n</BR>\n" );
1970 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
1971 for (
int j = 0; j < attributeNodeList.size(); ++j )
1973 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
1974 featureInfoString.append(
"<TR><TH>" + attributeElement.attribute( QStringLiteral(
"name" ) ) +
1975 "</TH><TD>" + attributeElement.attribute( QStringLiteral(
"value" ) ) +
"</TD></TR>\n" );
1979 featureInfoString.append(
"</TABLE>\n<BR></BR>\n" );
1983 featureInfoString.append(
"</BODY>\n" );
1985 return featureInfoString.toUtf8();
1988 QByteArray QgsRenderer::convertFeatureInfoToText(
const QDomDocument &doc )
const 1990 QString featureInfoString;
1993 featureInfoString.append(
"GetFeatureInfo results\n" );
1994 featureInfoString.append(
"\n" );
1996 QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
1999 for (
int i = 0; i < layerList.size(); ++i )
2001 QDomElement layerElem = layerList.at( i ).toElement();
2003 featureInfoString.append(
"Layer '" + layerElem.attribute( QStringLiteral(
"name" ) ) +
"'\n" );
2006 QDomNodeList featureNodeList = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2007 QDomElement currentFeatureElement;
2009 if ( !featureNodeList.isEmpty() )
2011 for (
int j = 0; j < featureNodeList.size(); ++j )
2013 QDomElement featureElement = featureNodeList.at( j ).toElement();
2014 featureInfoString.append(
"Feature " + featureElement.attribute( QStringLiteral(
"id" ) ) +
"\n" );
2017 QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral(
"Attribute" ) );
2018 for (
int k = 0; k < attributeNodeList.size(); ++k )
2020 QDomElement attributeElement = attributeNodeList.at( k ).toElement();
2021 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2022 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2028 QDomNodeList attributeNodeList = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2029 for (
int j = 0; j < attributeNodeList.size(); ++j )
2031 QDomElement attributeElement = attributeNodeList.at( j ).toElement();
2032 featureInfoString.append( attributeElement.attribute( QStringLiteral(
"name" ) ) +
" = '" +
2033 attributeElement.attribute( QStringLiteral(
"value" ) ) +
"'\n" );
2037 featureInfoString.append(
"\n" );
2040 return featureInfoString.toUtf8();
2043 QByteArray QgsRenderer::convertFeatureInfoToJson(
const QList<QgsMapLayer *> &layers,
const QDomDocument &doc )
const 2047 {
"type",
"FeatureCollection" },
2048 {
"features", json::array() },
2052 const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral(
"Layer" ) );
2053 for (
int i = 0; i < layerList.size(); ++i )
2055 const QDomElement layerElem = layerList.at( i ).toElement();
2056 const QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
2061 if ( mContext.
layerNickname( *l ).compare( layerName ) == 0 )
2077 const QDomNodeList featuresNode = layerElem.elementsByTagName( QStringLiteral(
"Feature" ) );
2078 if ( featuresNode.isEmpty() )
2081 for (
int j = 0; j < featuresNode.size(); ++j )
2083 const QDomElement featureNode = featuresNode.at( j ).toElement();
2084 const QgsFeatureId fid = featureNode.attribute( QStringLiteral(
"id" ) ).toLongLong();
2090 const QDomNodeList attrs = featureNode.elementsByTagName(
"Attribute" );
2091 for (
int k = 0; k < attrs.count(); k++ )
2093 const QDomElement elm = attrs.at( k ).toElement();
2094 if ( elm.attribute( QStringLiteral(
"name" ) ).compare(
"geometry" ) == 0 )
2101 if ( ! wkt.isEmpty() )
2107 features << feature;
2110 if ( !attributes.isEmpty() )
2113 const QDomNodeList attributesNode = featureNode.elementsByTagName( QStringLiteral(
"Attribute" ) );
2114 for (
int k = 0; k < attributesNode.size(); ++k )
2116 const QDomElement attributeElement = attributesNode.at( k ).toElement();
2117 const QString fieldName = attributeElement.
attribute( QStringLiteral(
"name" ) );
2119 attributes << feature.fieldNameIndex( fieldName );
2129 for (
const auto &feature : qgis::as_const( features ) )
2137 auto properties = json::object();
2138 const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral(
"Attribute" ) );
2139 for (
int j = 0; j < attributesNode.size(); ++j )
2141 const QDomElement attrElmt = attributesNode.at( j ).toElement();
2142 const QString name = attrElmt.attribute( QStringLiteral(
"name" ) );
2143 const QString value = attrElmt.attribute( QStringLiteral(
"value" ) );
2144 properties[name.toStdString()] = value.toStdString();
2147 json[
"features"].push_back(
2149 {
"type",
"Feature" },
2150 {
"id", layer->
name().toStdString() },
2151 {
"properties", properties }
2157 return QByteArray::fromStdString(
json.dump( 2 ) );
2159 return QByteArray::fromStdString(
json.dump() );
2163 QDomElement QgsRenderer::createFeatureGML(
2172 QStringList *attributes )
const 2175 QDomElement typeNameElement = doc.createElement(
"qgs:" + typeName );
2176 typeNameElement.setAttribute( QStringLiteral(
"fid" ), typeName +
"." + QString::number( feat->
id() ) );
2179 if ( layer && layer->
crs() !=
crs )
2202 box = transformedBox;
2210 QDomElement bbElem = doc.createElement( QStringLiteral(
"gml:boundedBy" ) );
2211 QDomElement boxElem;
2223 boxElem.setAttribute( QStringLiteral(
"srsName" ), crs.
authid() );
2225 bbElem.appendChild( boxElem );
2226 typeNameElement.appendChild( bbElem );
2229 if ( withGeom && !geom.
isNull() )
2238 QDomElement geomElem = doc.createElement( QStringLiteral(
"qgs:geometry" ) );
2239 QDomElement gmlElem;
2249 if ( !gmlElem.isNull() )
2253 gmlElem.setAttribute( QStringLiteral(
"srsName" ), crs.
authid() );
2255 geomElem.appendChild( gmlElem );
2256 typeNameElement.appendChild( geomElem );
2263 for (
int i = 0; i < fields.
count(); ++i )
2265 QString attributeName = fields.
at( i ).
name();
2272 if ( attributes && !attributes->contains( attributeName ) )
2277 QDomElement fieldElem = doc.createElement(
"qgs:" + attributeName.replace(
' ',
'_' ) );
2278 QString fieldTextString = featureAttributes.at( i ).toString();
2283 QDomText fieldText = doc.createTextNode( fieldTextString );
2284 fieldElem.appendChild( fieldText );
2285 typeNameElement.appendChild( fieldElem );
2293 if ( !mapTip.isEmpty() && mWmsParameters.
withMapTip() )
2296 QDomElement fieldElem = doc.createElement( QStringLiteral(
"qgs:maptip" ) );
2297 QDomText maptipText = doc.createTextNode( fieldTextString );
2298 fieldElem.appendChild( maptipText );
2299 typeNameElement.appendChild( fieldElem );
2303 return typeNameElement;
2306 QString QgsRenderer::replaceValueMapAndRelation(
QgsVectorLayer *vl,
int idx,
const QVariant &attributeVal )
2310 QString value( fieldFormatter->
representValue( vl, idx, setup.
config(), QVariant(), attributeVal ) );
2312 if ( setup.
config().value( QStringLiteral(
"AllowMulti" ) ).toBool() && value.startsWith( QLatin1String(
"{" ) ) && value.endsWith( QLatin1String(
"}" ) ) )
2314 value = value.mid( 1, value.size() - 2 );
2326 double mapUnitTolerance = 0.0;
2336 mapUnitTolerance = mapSettings.
extent().
width() / 400.0;
2348 mapUnitTolerance = mapSettings.
extent().
width() / 200.0;
2360 mapUnitTolerance = mapSettings.
extent().
width() / 100.0;
2364 QgsRectangle mapRectangle( infoPoint.
x() - mapUnitTolerance, infoPoint.
y() - mapUnitTolerance,
2365 infoPoint.
x() + mapUnitTolerance, infoPoint.
y() + mapUnitTolerance );
2369 QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
2371 QList<QgsMapLayer *> highlightLayers;
2374 QString crs = mWmsParameters.
crs();
2378 QDomDocument sldDoc;
2379 if ( !sldDoc.setContent( param.mSld,
true ) )
2386 std::unique_ptr<QgsFeatureRenderer> renderer;
2387 QDomElement el = sldDoc.documentElement();
2397 QString url = typeName +
"?crs=" +
crs;
2398 if ( ! param.mLabel.isEmpty() )
2400 url +=
"&field=label:string";
2405 std::unique_ptr<QgsVectorLayer> layer = qgis::make_unique<QgsVectorLayer>( url, param.mName, QLatin1Literal(
"memory" ), options );
2406 if ( !layer->isValid() )
2413 if ( ! param.mLabel.isEmpty() )
2424 switch ( param.mGeom.type() )
2429 palSettings.
dist = 2;
2440 QVariant x( pt.
x() );
2444 QVariant y( pt.
y() );
2448 QVariant hali(
"Center" );
2452 QVariant vali(
"Half" );
2459 palSettings.
dist = 2;
2468 if ( param.mColor.isValid() )
2470 textFormat.
setColor( param.mColor );
2473 if ( param.mSize > 0 )
2475 textFormat.
setSize( param.mSize );
2483 if ( ! param.mFont.isEmpty() )
2485 textFormat.
setFont( param.mFont );
2488 if ( param.mBufferColor.isValid() )
2490 bufferSettings.
setColor( param.mBufferColor );
2493 if ( param.mBufferSize > 0 )
2496 bufferSettings.
setSize( param.mBufferSize );
2503 layer->setLabeling( simpleLabeling );
2504 layer->setLabelsEnabled(
true );
2506 fet.setGeometry( param.mGeom );
2510 layer->setRenderer( renderer.release() );
2513 if ( layer->isValid() )
2515 highlightLayers.append( layer.release() );
2519 mTemporaryLayers.append( highlightLayers );
2520 return highlightLayers;
2523 QList<QgsMapLayer *> QgsRenderer::externalLayers(
const QList<QgsWmsParametersExternalLayer> ¶ms )
2525 QList<QgsMapLayer *> layers;
2529 std::unique_ptr<QgsMapLayer> layer = qgis::make_unique< QgsRasterLayer >( param.mUri, param.mName, QStringLiteral(
"wms" ) );
2531 if ( layer->isValid() )
2534 mTemporaryLayers.append( layer.release() );
2535 layers << mTemporaryLayers.last();
2542 void QgsRenderer::removeTemporaryLayers()
2544 qDeleteAll( mTemporaryLayers );
2545 mTemporaryLayers.clear();
2548 QPainter *QgsRenderer::layersRendering(
const QgsMapSettings &mapSettings, QImage &image )
const 2550 QPainter *painter =
nullptr;
2554 #ifdef HAVE_SERVER_PYTHON_PLUGINS 2555 mContext.accessControl()->resolveFilterFeatures( mapSettings.
layers() );
2559 renderJob.
render( mapSettings, &image );
2560 painter = renderJob.takePainter();
2562 if ( !renderJob.errors().isEmpty() )
2564 QString layerWMSName;
2565 QString firstErrorLayerId = renderJob.errors().at( 0 ).layerID;
2572 throw QgsException( QStringLiteral(
"Map rendering error in layer '%1'" ).arg( layerWMSName ) );
2578 void QgsRenderer::setLayerOpacity(
QgsMapLayer *layer,
int opacity )
const 2580 if ( opacity >= 0 && opacity <= 255 )
2582 switch ( layer->
type() )
2595 rasterRenderer->
setOpacity( opacity / 255. );
2606 void QgsRenderer::setLayerFilter(
QgsMapLayer *layer,
const QList<QgsWmsParametersFilter> &filters )
2616 QDomDocument filterXml;
2618 if ( !filterXml.setContent( filter.mFilter,
true, &errorMsg ) )
2621 QStringLiteral(
"Filter string rejected. Error message: %1. The XML string was: %2" ).arg( errorMsg, filter.mFilter ) );
2623 QDomElement filterElem = filterXml.firstChildElement();
2628 mFeatureFilter.
setFilter( filteredLayer, *expression );
2634 if ( !testFilterStringSafety( filter.mFilter ) )
2637 " has been rejected because of security reasons." 2638 " Note: Text strings have to be enclosed in single or double quotes." 2639 " A space between each word / special character is mandatory." 2640 " Allowed Keywords and special characters are " 2641 " AND,OR,IN,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX." 2642 " Not allowed are semicolons in the filter expression." ).arg(
2646 QString newSubsetString = filter.mFilter;
2649 newSubsetString.prepend(
") AND (" );
2650 newSubsetString.append(
")" );
2651 newSubsetString.prepend( filteredLayer->
subsetString() );
2652 newSubsetString.prepend(
"(" );
2660 void QgsRenderer::setLayerSelection(
QgsMapLayer *layer,
const QStringList &fids )
const 2666 for (
const QString &
id : fids )
2676 void QgsRenderer::setLayerAccessControlFilter(
QgsMapLayer *layer )
const 2678 #ifdef HAVE_SERVER_PYTHON_PLUGINS 2696 void QgsRenderer::annotationsRendering( QPainter *painter )
const 2699 const QList< QgsAnnotation * > annotations = annotationManager->
annotations();
2704 if ( !annotation || !annotation->isVisible() )
2707 annotation->render( renderContext );
2711 QImage *QgsRenderer::scaleImage(
const QImage *image )
const 2716 QImage *scaledImage =
nullptr;
2717 const int width = mWmsParameters.
widthAsInt();
2719 if ( width != image->width() || height != image->height() )
2721 scaledImage =
new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
2727 void QgsRenderer::handlePrintErrors(
const QgsLayout *layout )
const 2733 QList< QgsLayoutItemMap * > mapList;
2736 QList< QgsLayoutItemMap * >::const_iterator mapIt = mapList.constBegin();
2737 for ( ; mapIt != mapList.constEnd(); ++mapIt )
2739 if ( !( *mapIt )->renderingErrors().isEmpty() )
2747 void QgsRenderer::configureLayers( QList<QgsMapLayer *> &layers,
QgsMapSettings *settings )
2751 for (
auto layer : layers )
2762 setLayerSld( layer, mContext.
sld( *layer ) );
2766 setLayerStyle( layer, mContext.
style( *layer ) );
2771 setLayerOpacity( layer, param.
mOpacity );
2776 setLayerFilter( layer, param.
mFilter );
2781 setLayerSelection( layer, param.
mSelection );
2786 updateExtent( layer, *settings );
2791 setLayerAccessControlFilter( layer );
2806 void QgsRenderer::setLayerStyle(
QgsMapLayer *layer,
const QString &style )
const 2808 if ( style.isEmpty() )
2817 QStringLiteral(
"Style '%1' does not exist for layer '%2'" ).arg( style, layer->
name() ) );
2821 void QgsRenderer::setLayerSld(
QgsMapLayer *layer,
const QDomElement &sld )
const 2833 if ( !mWmsParameters.
bbox().isEmpty() )
2836 std::unique_ptr<QImage> tmp( createImage( mContext.
mapSize(
false ) ) );
2837 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.
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.
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.
double calculate(const QgsRectangle &mapExtent, double canvasWidth)
Calculate the scale denominator.
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.
QgsMapLayerType type() const
Returns the type of the layer.
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.
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.
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< 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.
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.
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.
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.
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
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
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.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
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 layer's data provider, it may be nullptr.
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.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
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.
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)
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.
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.
const QgsProject * project() const
Returns the project.
Median cut implementation.
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).
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.
#define FID_TO_STRING(fid)
QgsEditorWidgetSetup editorWidgetSetup(int index) const
The editor widget setup defines which QgsFieldFormatter and editor widget will be used for the field ...
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...
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.
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.
QPointF point
Top-left corner of the legend item.
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 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.
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.
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.
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.
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
Y-coordinate data defined label position.
bool nextFeature(QgsFeature &f)
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.
double labelXOffset
offset from the left side where label should start
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).
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...