51 #include "qgssettings.h"
59 #include <QMouseEvent>
68 , mLastMapUnitsPerPixel( -1.0 )
69 , mCoordinatePrecision( 6 )
101 return identify( x, y, mode, QList<QgsMapLayer *>(), layerType, identifyContext );
111 return identify( geometry, mode, QList<QgsMapLayer *>(), layerType, identifyContext );
116 QList<IdentifyResult> results;
118 mLastGeometry = geometry;
126 QgsSettings settings;
127 mode = settings.enumValue( QStringLiteral(
"Map/identifyMode" ),
ActiveLayer );
133 int x = canvasPt.x(), y = canvasPt.y();
134 QList<IdentifyResult> results =
identify( x, y,
TopDownAll, layerList, layerType, identifyContext );
135 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
138 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
144 emit
identifyMessage( tr(
"No active layer. To identify features, you must choose an active layer." ) );
150 QApplication::setOverrideCursor( Qt::WaitCursor );
152 identifyLayer( &results, layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel, layerType, identifyContext );
156 QApplication::setOverrideCursor( Qt::WaitCursor );
159 if ( layerList.isEmpty() )
162 layerCount = layerList.count();
165 for (
int i = 0; i < layerCount; i++ )
169 if ( layerList.isEmpty() )
172 layer = layerList.value( i );
180 if (
identifyLayer( &results, layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel, layerType, identifyContext ) )
191 QApplication::restoreOverrideCursor();
198 mOverrideCanvasSearchRadius = searchRadiusMapUnits;
203 mOverrideCanvasSearchRadius = -1;
225 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), geometry, viewExtent, mapUnitsPerPixel, identifyContext );
229 return identifyVectorLayer( results, qobject_cast<QgsVectorLayer *>( layer ), geometry, identifyContext );
233 return identifyMeshLayer( results, qobject_cast<QgsMeshLayer *>( layer ), geometry, identifyContext );
237 return identifyVectorTileLayer( results, qobject_cast<QgsVectorTileLayer *>( layer ), geometry, identifyContext );
241 return identifyPointCloudLayer( results, qobject_cast<QgsPointCloudLayer *>( layer ), geometry, identifyContext );
266 double searchRadius = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
269 QList<QgsMeshDatasetIndex> datasetIndexList;
276 const QgsDateTimeRange &time = identifyContext.
temporalRange();
277 if ( activeScalarGroup >= 0 )
279 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
282 for (
int groupIndex : allGroup )
284 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
291 if ( activeScalarGroup >= 0 )
293 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
297 for (
int groupIndex : allGroup )
299 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
302 datasetIndexList.append( groupIndex );
310 if ( !index.isValid() )
314 QMap< QString, QString > derivedAttributes;
316 QMap<QString, QString> attribute;
320 const double scalar = scalarValue.
scalar();
321 attribute.insert( tr(
"Scalar Value" ), std::isnan( scalar ) ? tr(
"no data" ) : QString::number( scalar ) );
327 const double vectorX = vectorValue.
x();
328 const double vectorY = vectorValue.
y();
329 if ( std::isnan( vectorX ) || std::isnan( vectorY ) )
330 attribute.insert( tr(
"Vector Value" ), tr(
"no data" ) );
333 attribute.insert( tr(
"Vector Magnitude" ), QString::number( vectorValue.
scalar() ) );
334 derivedAttributes.insert( tr(
"Vector x-component" ), QString::number( vectorY ) );
335 derivedAttributes.insert( tr(
"Vector y-component" ), QString::number( vectorX ) );
342 derivedAttributes.insert( tr(
"Time Step" ), layer->
formatTime( meta.
time() ) );
343 derivedAttributes.insert( tr(
"Source" ), groupMeta.
uri() );
345 QString resultName = groupMeta.
name();
346 if ( isTemporal && ( index.group() == activeScalarGroup || index.group() == activeVectorGroup ) )
347 resultName.append( tr(
" (active)" ) );
354 results->append( result );
357 QMap<QString, QString> derivedGeometry;
362 derivedGeometry.insert( tr(
"Snapped Vertex Position X" ), QString::number( vertexPoint.
x() ) );
363 derivedGeometry.insert( tr(
"Snapped Vertex Position Y" ), QString::number( vertexPoint.
y() ) );
369 derivedGeometry.insert( tr(
"Face Centroid X" ), QString::number( faceCentroid.
x() ) );
370 derivedGeometry.insert( tr(
"Face Centroid Y" ), QString::number( faceCentroid.
y() ) );
376 derivedGeometry.insert( tr(
"Point on Edge X" ), QString::number( pointOnEdge.
x() ) );
377 derivedGeometry.insert( tr(
"Point on Edge Y" ), QString::number( pointOnEdge.
y() ) );
385 results->append( result );
392 Q_UNUSED( identifyContext )
404 QMap< QString, QString > commonDerivedAttributes;
407 bool isPointOrRectangle;
412 isPointOrRectangle =
true;
413 point = selectionGeom.
asPoint();
423 int featureCount = 0;
425 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
435 double sr = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
442 if ( !isPointOrRectangle )
457 for (
int row = tileRange.
startRow(); row <= tileRange.
endRow(); ++row )
462 QByteArray data = layer->
getRawTile( tileID );
463 if ( data.isEmpty() )
467 if ( !decoder.
decode( tileID, data ) )
470 QMap<QString, QgsFields> perLayerFields;
471 const QStringList layerNames = decoder.
layers();
472 for (
const QString &layerName : layerNames )
474 QSet<QString> fieldNames = qgis::listToSet( decoder.
layerFieldNames( layerName ) );
479 const QStringList featuresLayerNames = features.keys();
480 for (
const QString &layerName : featuresLayerNames )
482 const QgsFields fFields = perLayerFields[layerName];
483 const QVector<QgsFeature> &layerFeatures = features[layerName];
486 if ( f.geometry().intersects( r ) && ( !selectionGeomPrepared || selectionGeomPrepared->intersects( f.geometry().constGet() ) ) )
488 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
489 derivedAttributes.insert( tr(
"Feature ID" ),
FID_TO_STRING( f.id() ) );
491 results->
append( IdentifyResult( layer, layerName, fFields, f, derivedAttributes ) );
505 QgsDebugMsg( QStringLiteral(
"Caught CRS exception %1" ).arg( cse.
what() ) );
508 return featureCount > 0;
513 Q_UNUSED( identifyContext )
519 const double searchRadiusMapUnits = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
521 const QVector<QVariantMap> points = renderer->
identify( layer, context, geometry, searchRadiusMapUnits );
530 QMap< QString, QString > derivedAttributes;
531 derivedAttributes.insert( tr(
"(clicked coordinate X)" ), formatXCoordinate( point ) );
532 derivedAttributes.insert( tr(
"(clicked coordinate Y)" ), formatYCoordinate( point ) );
534 derivedAttributes.insert( tr(
"(clicked coordinate Z)" ), QString::number( point.
z(),
'f' ) );
535 return derivedAttributes;
545 QgsDebugMsg( QStringLiteral(
"Out of scale limits" ) );
549 QString temporalFilter;
557 temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->
temporalProperties() )->createFilterString( temporalContext, identifyContext.
temporalRange() );
562 QApplication::setOverrideCursor( Qt::WaitCursor );
564 QMap< QString, QString > commonDerivedAttributes;
567 bool isPointOrRectangle;
572 isPointOrRectangle =
true;
573 point = selectionGeom.
asPoint();
583 int featureCount = 0;
586 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
596 double sr = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
603 if ( !isPointOrRectangle )
617 if ( !temporalFilter.isEmpty() )
624 if ( !selectionGeomPrepared || selectionGeomPrepared->intersects( f.
geometry().
constGet() ) )
632 QgsDebugMsg( QStringLiteral(
"Caught CRS exception %1" ).arg( cse.
what() ) );
640 std::unique_ptr< QgsFeatureRenderer > renderer( layer->
renderer() ? layer->
renderer()->
clone() :
nullptr );
648 for (
const QgsFeature &feature : std::as_const( featureList ) )
650 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
655 if ( filter && !renderer->willRenderFeature( feature, context ) )
661 if ( !isSingleClick )
663 derivedAttributes.unite( featureDerivedAttributes( feature, layer,
toLayerCoordinates( layer, point ) ) );
665 derivedAttributes.insert( tr(
"Feature ID" ), fid < 0 ? tr(
"new feature" ) :
FID_TO_STRING( fid ) );
667 results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), feature, derivedAttributes ) );
675 QgsDebugMsgLevel(
"Feature count on identify: " + QString::number( featureCount ), 2 );
677 QApplication::restoreOverrideCursor();
678 return featureCount > 0;
690 QString
str = QLocale().toString( vId.
vertex + 1 );
691 derivedAttributes.insert( tr(
"Closest vertex number" ),
str );
696 derivedAttributes.insert( tr(
"Closest vertex X" ), formatXCoordinate( closestPointMapCoords ) );
697 derivedAttributes.insert( tr(
"Closest vertex Y" ), formatYCoordinate( closestPointMapCoords ) );
699 if ( closestPoint.
is3D() )
701 str = QLocale().toString( closestPoint.
z(),
'g', 10 );
702 derivedAttributes.insert( tr(
"Closest vertex Z" ),
str );
706 str = QLocale().toString( closestPoint.
m(),
'g', 10 );
707 derivedAttributes.insert( tr(
"Closest vertex M" ),
str );
712 double radius, centerX, centerY;
718 geometry.
vertexAt( vIdAfter ), radius, centerX, centerY );
719 derivedAttributes.insert( QStringLiteral(
"Closest vertex radius" ), QLocale().toString( radius ) );
723 void QgsMapToolIdentify::closestPointAttributes(
const QgsAbstractGeometry &geometry,
const QgsPointXY &layerPoint, QMap<QString, QString> &derivedAttributes )
727 derivedAttributes.insert( tr(
"Closest X" ), formatXCoordinate( closestPoint ) );
728 derivedAttributes.insert( tr(
"Closest Y" ), formatYCoordinate( closestPoint ) );
730 if ( closestPoint.
is3D() )
732 const QString
str = QLocale().toString( closestPoint.
z(),
'g', 10 );
733 derivedAttributes.insert( tr(
"Interpolated Z" ),
str );
737 const QString
str = QLocale().toString( closestPoint.
m(),
'g', 10 );
738 derivedAttributes.insert( tr(
"Interpolated M" ),
str );
742 QString QgsMapToolIdentify::formatCoordinate(
const QgsPointXY &canvasPoint )
const
745 mCoordinatePrecision );
748 QString QgsMapToolIdentify::formatXCoordinate(
const QgsPointXY &canvasPoint )
const
750 QString coordinate = formatCoordinate( canvasPoint );
751 return coordinate.split(
',' ).at( 0 );
754 QString QgsMapToolIdentify::formatYCoordinate(
const QgsPointXY &canvasPoint )
const
756 QString coordinate = formatCoordinate( canvasPoint );
757 return coordinate.split(
',' ).at( 1 );
764 QMap< QString, QString > derivedAttributes;
793 derivedAttributes.insert( tr(
"Parts" ),
str );
796 str = QLocale().toString( vId.
part + 1 );
797 derivedAttributes.insert( tr(
"Part number" ),
str );
802 ? displayDistanceUnits() : layer->
crs().mapUnits();
804 ? displayAreaUnits() :
QgsUnitTypes::distanceToAreaUnit( layer->
crs().mapUnits() );
813 str = formatDistance( dist );
814 derivedAttributes.insert( tr(
"Length (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
819 derivedAttributes.insert( tr(
"Length (Cartesian)" ),
str );
821 derivedAttributes.insert( tr(
"Length (Cartesian — 2D)" ),
str );
824 str = formatDistance( qgsgeometry_cast< const QgsLineString * >( feature.
geometry().
constGet() )->length3D()
826 derivedAttributes.insert( tr(
"Length (Cartesian — 3D)" ),
str );
833 derivedAttributes.insert( tr(
"Vertices" ),
str );
837 closestVertexAttributes( *geom, vId, layer, derivedAttributes );
838 closestPointAttributes( *geom, layerPoint, derivedAttributes );
841 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom ) )
845 str = formatXCoordinate( pnt );
846 derivedAttributes.insert( tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ),
str );
847 str = formatYCoordinate( pnt );
848 derivedAttributes.insert( tr(
"firstY" ),
str );
850 str = formatXCoordinate( pnt );
851 derivedAttributes.insert( tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ),
str );
852 str = formatYCoordinate( pnt );
853 derivedAttributes.insert( tr(
"lastY" ),
str );
864 str = formatArea( area );
865 derivedAttributes.insert( tr(
"Area (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
869 derivedAttributes.insert( tr(
"Area (Cartesian)" ),
str );
875 str = formatDistance( perimeter );
876 derivedAttributes.insert( tr(
"Perimeter (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
880 derivedAttributes.insert( tr(
"Perimeter (Cartesian)" ),
str );
883 derivedAttributes.insert( tr(
"Vertices" ),
str );
888 closestVertexAttributes( *feature.
geometry().
constGet(), vId, layer, derivedAttributes );
889 closestPointAttributes( *feature.
geometry().
constGet(), layerPoint, derivedAttributes );
898 QString
str = formatXCoordinate( pnt );
899 derivedAttributes.insert( tr(
"X" ),
str );
900 str = formatYCoordinate( pnt );
901 derivedAttributes.insert( tr(
"Y" ),
str );
906 derivedAttributes.insert( tr(
"Z" ),
str );
911 derivedAttributes.insert( tr(
"M" ),
str );
922 closestVertexAttributes( *geom, vId, layer, derivedAttributes );
932 return derivedAttributes;
938 return identifyRasterLayer( results, layer, point, viewExtent, mapUnitsPerPixel, identifyContext );
947 std::unique_ptr< QgsRasterDataProvider > dprovider( layer->
dataProvider()->
clone() );
951 int capabilities = dprovider->capabilities();
960 dprovider->temporalCapabilities()->setRequestedTemporalRange( identifyContext.
temporalRange() );
971 QgsDebugMsg( QStringLiteral(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
974 QgsDebugMsg( QStringLiteral(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
979 QMap< QString, QString > attributes, derivedAttributes;
1004 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
1005 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
1006 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
1007 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
1011 identifyResult = dprovider->identify( point, format, r, 1, 1 );
1027 int width =
static_cast< int >( std::round( viewExtent.
width() / mapUnitsPerPixel ) );
1028 int height =
static_cast< int >( std::round( viewExtent.
height() / mapUnitsPerPixel ) );
1030 QgsDebugMsg( QStringLiteral(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
1031 QgsDebugMsg( QStringLiteral(
"width = %1 height = %2" ).arg( width ).arg( height ) );
1032 QgsDebugMsg( QStringLiteral(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
1034 identifyResult = dprovider->identify( point, format, viewExtent, width, height );
1039 if ( identifyResult.
isValid() )
1041 QMap<int, QVariant> values = identifyResult.
results();
1045 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1047 QString valueString;
1048 if ( it.value().isNull() )
1050 valueString = tr(
"no data" );
1054 QVariant value( it.value() );
1058 if (
static_cast<QMetaType::Type
>( value.type() ) == QMetaType::Float )
1067 attributes.insert( dprovider->generateBandName( it.key() ), valueString );
1069 QString label = layer->
name();
1070 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
1074 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1076 QVariant value = it.value();
1077 if ( value.type() == QVariant::Bool && !value.toBool() )
1083 if ( value.type() == QVariant::String )
1087 QString label = layer->
subLayers().value( it.key() );
1089 attributes.insert( tr(
"Error" ), value.toString() );
1091 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
1101 for (
const QgsFeature &feature : storeFeatures )
1107 QString sublayer = featureStore.params().value( QStringLiteral(
"sublayer" ) ).toString();
1108 QString featureType = featureStore.params().value( QStringLiteral(
"featureType" ) ).toString();
1110 featureType.remove( QStringLiteral(
"_feature" ) );
1112 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
1116 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
1118 labels << featureType;
1121 QMap< QString, QString > derAttributes = derivedAttributes;
1122 derAttributes.unite( featureDerivedAttributes( feature, layer,
toLayerCoordinates( layer, point ) ) );
1124 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join( QLatin1String(
" / " ) ), featureStore.fields(), feature, derAttributes );
1126 identifyResult.
mParams.insert( QStringLiteral(
"getFeatureInfoUrl" ), featureStore.params().value( QStringLiteral(
"getFeatureInfoUrl" ) ) );
1127 results->append( identifyResult );
1134 QgsDebugMsg( QStringLiteral(
"%1 HTML or text values" ).arg( values.size() ) );
1135 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1137 QString value = it.value().toString();
1139 attributes.insert( QString(), value );
1141 QString label = layer->
subLayers().value( it.key() );
1142 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
1150 attributes.insert( tr(
"Error" ), value );
1151 QString label = tr(
"Identify error" );
1152 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
1168 QString QgsMapToolIdentify::formatDistance(
double distance )
const
1170 return formatDistance( distance, displayDistanceUnits() );
1173 QString QgsMapToolIdentify::formatArea(
double area )
const
1175 return formatArea( area, displayAreaUnits() );
1180 QgsSettings settings;
1181 bool baseUnit = settings.value( QStringLiteral(
"qgis/measure/keepbaseunit" ),
true ).toBool();
1188 QgsSettings settings;
1189 bool baseUnit = settings.value( QStringLiteral(
"qgis/measure/keepbaseunit" ),
true ).toBool();
1196 QList<IdentifyResult> results;
1197 if (
identifyRasterLayer( &results, layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel ) )
1207 for (
const QVariantMap &pt : identified )
1209 QMap<QString, QString> ptStr;
1210 QString classification;
1211 for (
auto attrIt = pt.constBegin(); attrIt != pt.constEnd(); ++attrIt )
1213 if ( attrIt.key().compare( QLatin1String(
"Z" ), Qt::CaseInsensitive ) == 0
1217 ptStr[ tr(
"Z (original)" ) ] = attrIt.value().toString();
1218 ptStr[ tr(
"Z (adjusted)" ) ] = QString::number( attrIt.value().toDouble() * elevationProps->
zScale() + elevationProps->
zOffset() );
1220 else if ( attrIt.key().compare( QLatin1String(
"Classification" ), Qt::CaseInsensitive ) == 0 )
1223 ptStr[ attrIt.key() ] = QStringLiteral(
"%1 (%2)" ).arg( attrIt.value().toString(), classification );
1227 ptStr[attrIt.key()] = attrIt.value().toString();
1230 QgsMapToolIdentify::IdentifyResult res( layer, classification.isEmpty() ? QString::number(
id ) : QStringLiteral(
"%1 (%2)" ).arg(
id ).arg( classification ), ptStr, QMap<QString, QString>() );
1231 results.append( res );
Abstract base class for all geometries.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
static QString formatDistance(double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit=false)
Returns an distance formatted as a friendly string.
double measureArea(const QgsGeometry &geometry) const
Measures the area of a geometry.
double measurePerimeter(const QgsGeometry &geometry) const
Measures the perimeter of a polygon geometry.
double measureLength(const QgsGeometry &geometry) const
Measures the length of a geometry.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
static QString formatArea(double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
double convertAreaMeasurement(double area, QgsUnitTypes::AreaUnit toUnits) const
Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different ar...
double convertLengthMeasurement(double length, QgsUnitTypes::DistanceUnit toUnits) const
Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different d...
QString message(QgsErrorMessage::Format format=QgsErrorMessage::Html) const
Full error messages description.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
A container for features with the same fields and crs.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
const QgsSymbol * embeddedSymbol() const
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Container of fields for a vector layer.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
static QgsPoint closestPoint(const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point.
static void circleCenterRadius(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double &radius, double ¢erX, double ¢erY) SIP_HOLDGIL
Returns radius and center of the circle through pt1, pt2, pt3.
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
QgsWkbTypes::GeometryType type
double area() const
Returns the planar, 2-dimensional area of the geometry.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
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.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
Identify contexts are used to encapsulate the settings to be used to perform an identify action.
bool isTemporal() const
Returns true if the temporal range setting is enabled.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range to be used with the identify action.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsUnitTypes::DistanceUnit mapUnits() const
Convenience function for returning the current canvas map units.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
int layerCount() const
Returns number of layers on the map.
double scale() const
Returns the last reported scale of the canvas.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
QgsMapLayer * layer(int index)
Returns the map layer at position index in the layer stack.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
virtual bool isVisibleInTemporalRange(const QgsDateTimeRange &range) const
Returns true if the layer should be visible and rendered for the specified time range.
Base class for all map layer types.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
virtual QgsRectangle extent() const
Returns the extent of the layer.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
QgsCoordinateReferenceSystem crs
@ Identifiable
If the layer is identifiable using the identify map tool and as a WMS layer.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
double scale() const
Returns the calculated map scale.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetValue represents single dataset value.
double y() const
Returns y value.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
double x() const
Returns x value.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active scalar group depending on the time range.
QgsPointXY snapOnElement(QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius)
Returns the position of the snapped point on the mesh element closest to point intersecting with the ...
QList< int > enabledDatasetGroupsIndexes() const
Returns the list of indexes of enables dataset groups handled by the layer.
QgsMeshDatasetIndex staticVectorDatasetIndex() const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
QgsMeshDatasetIndex activeVectorDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active vector group depending on the time range If the temporal properties...
QgsMeshDatasetIndex staticScalarDatasetIndex() const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset metadata.
QgsMeshDatasetIndex datasetIndexAtTime(const QgsDateTimeRange &timeRange, int datasetGroupIndex) const
Returns dataset index from datasets group depending on the time range.
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, int valueIndex) const
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QString formatTime(double hours)
Returns (date) time in hours formatted to human readable form.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
static QMap< int, QString > translatedLasClassificationCodes()
Returns the map of LAS classification code to translated string value, corresponding to the ASPRS Sta...
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
double zScale() const
Returns the z scale, which is a scaling factor which should be applied to z values from the layer.
Represents a map layer supporting display of point clouds.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
QgsPointCloudRenderer * renderer()
Returns the 2D renderer for the point cloud.
Abstract base class for 2d point cloud renderers.
QVector< QVariantMap > identify(QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry, double toleranceForPointIdentification=0)
Returns the list of visible points of the point cloud layer layer and an extent defined by a geometry...
virtual void startRender(QgsPointCloudRenderContext &context)
Must be called when a new render cycle is started.
virtual void stopRender(QgsPointCloudRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
A class to represent a 2D point.
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
QString toString(int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision.
Point geometry type, with support for z-dimension and m-values.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
static QString printValue(double value)
Print double value with all necessary significant digits.
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
QgsRasterDataProvider * clone() const override=0
Clone itself, create deep copy.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
Raster identify results container.
QgsError error() const
Returns the last error.
bool isValid() const
Returns true if valid.
QMap< int, QVariant > results() const
Returns the identify results.
@ IdentifyValue
Numerical values.
@ Identify
At least one identify format supported.
@ IdentifyFeature
WMS GML -> feature.
Represents a raster layer.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QStringList subLayers() const override
Returns the sublayers of this layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
A rectangle specified with double values.
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
bool contains(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle contains other rectangle.
Contains information about the context of a rendering operation.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
static QString symbolTypeToString(Qgis::SymbolType type)
Returns a translated string version of the specified symbol type.
QColor color() const
Returns the symbol's color.
Qgis::SymbolType type() const
Returns the symbol's type.
bool isActive() const
Returns true if the temporal property is active.
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
QgsTileRange tileRangeFromExtent(const QgsRectangle &mExtent)
Returns tile range that fully covers the given extent.
static QgsTileMatrix fromWebMercator(int mZoomLevel)
Returns a tile matrix for the usual web mercator.
Range of tiles in a tile matrix to be rendered.
int endColumn() const
Returns index of the last column in the range.
int endRow() const
Returns index of the last row in the range.
int startRow() const
Returns index of the first row in the range.
int startColumn() const
Returns index of the first column in the range.
Stores coordinates of a tile in a tile matrix set.
Helper functions for various unit types.
DistanceUnit
Units of distance.
static Q_INVOKABLE QgsUnitTypes::AreaUnit distanceToAreaUnit(QgsUnitTypes::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding area unit, e.g., meters to square meters.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QgsUnitTypes::DistanceUnitType unitType(QgsUnitTypes::DistanceUnit unit)
Returns the type for a distance unit.
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features. Since QGIS 3....
virtual Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
Encapsulates the context in which a QgsVectorLayer's temporal capabilities will be applied.
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
Represents a vector layer which manages a vector based data sets.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns temporal properties associated with the vector layer.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
Implements a map layer that is dedicated to rendering of vector tiles.
QByteArray getRawTile(QgsTileXYZ tileID)
Fetches raw tile data for the give tile coordinates.
int sourceMinZoom() const
Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)
int sourceMaxZoom() const
Returns maximum zoom level at which source has any valid tiles (negative = unconstrained)
This class is responsible for decoding raw tile data written with Mapbox Vector Tiles encoding.
QStringList layerFieldNames(const QString &layerName) const
Returns a list of all field names in a tile. It can only be called after a successful decode()
QStringList layers() const
Returns a list of sub-layer names in a tile. It can only be called after a successful decode()
QgsVectorTileFeatures layerFeatures(const QMap< QString, QgsFields > &perLayerFields, const QgsCoordinateTransform &ct, const QSet< QString > *layerSubset=nullptr) const
Returns decoded features grouped by sub-layers.
bool decode(QgsTileXYZ tileID, const QByteArray &rawTileData)
Tries to decode raw tile data, returns true on success.
static int scaleToZoomLevel(double mapScale, int sourceMinZoom, int sourceMaxZoom)
Finds best fitting zoom level (assuming GoogleCRS84Quad tile matrix set) given map scale denominator ...
static QgsFields makeQgisFields(QSet< QString > flds)
Returns QgsFields instance based on the set of field names.
static bool isMultiType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Type
The WKB type describes the number of dimensions a geometry has.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
CONSTLATIN1STRING geoNone()
Constant that holds the string representation for "No ellips/No CRS".
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsFeature > QgsFeatureList
#define FID_TO_STRING(fid)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QVector< QgsFeatureStore > QgsFeatureStoreList
#define QgsDebugMsgLevel(str, level)
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)
const QgsCoordinateReferenceSystem & crs
Utility class for identifying a unique vertex within a geometry.
VertexType type
Vertex type.
bool isValid() const SIP_HOLDGIL
Returns true if the vertex id is valid.
@ CurveVertex
An intermediate point on a segment defining the curvature of the segment.