45 #include <QMouseEvent>    55   , mLastMapUnitsPerPixel( -1.0 )
    56   , mCoordinatePrecision( 6 )
    88   return identify( x, y, mode, QList<QgsMapLayer *>(), layerType );
    93   QList<IdentifyResult> results;
   110     QPoint globalPos = 
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
   113   else if ( mode == 
ActiveLayer && layerList.isEmpty() )
   119       emit 
identifyMessage( tr( 
"No active layer. To identify features, you must choose an active layer." ) );
   123     QApplication::setOverrideCursor( Qt::WaitCursor );
   125     identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
   129     QApplication::setOverrideCursor( Qt::WaitCursor );
   134     if ( layerList.isEmpty() )
   137       layerCount = layerList.count();
   140     for ( 
int i = 0; i < layerCount; i++ )
   144       if ( layerList.isEmpty() )
   147         layer = layerList.value( i );
   152       if ( noIdentifyLayerIdList.contains( layer->
id() ) )
   155       if ( 
identifyLayer( &results, layer,  mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
   166   QApplication::restoreOverrideCursor();
   185     return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
   208   QApplication::setOverrideCursor( Qt::WaitCursor );
   210   QMap< QString, QString > commonDerivedAttributes;
   212   commonDerivedAttributes.insert( tr( 
"(clicked coordinate X)" ), formatXCoordinate( point ) );
   213   commonDerivedAttributes.insert( tr( 
"(clicked coordinate Y)" ), formatYCoordinate( point ) );
   215   int featureCount = 0;
   247   QgsFeatureList::iterator f_it = featureList.begin();
   253   std::unique_ptr< QgsFeatureRenderer > renderer( layer->
renderer() ? layer->
renderer()->
clone() : nullptr );
   257     renderer->startRender( context, layer->
fields() );
   261   for ( ; f_it != featureList.end(); ++f_it )
   263     QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
   268     if ( filter && !renderer->willRenderFeature( *f_it, context ) )
   273     derivedAttributes.unite( featureDerivedAttributes( &( *f_it ), layer, 
toLayerCoordinates( layer, point ) ) );
   275     derivedAttributes.insert( tr( 
"feature id" ), fid < 0 ? tr( 
"new feature" ) : 
FID_TO_STRING( fid ) );
   277     results->append( 
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
   282     renderer->stopRender( context );
   285   QgsDebugMsg( 
"Feature count on identify: " + QString::number( featureCount ) );
   287   QApplication::restoreOverrideCursor();
   288   return featureCount > 0;
   293   QString str = QLocale::system().toString( vId.
vertex + 1 );
   294   derivedAttributes.insert( tr( 
"Closest vertex number" ), str );
   299   derivedAttributes.insert( QStringLiteral( 
"Closest vertex X" ), formatXCoordinate( closestPointMapCoords ) );
   300   derivedAttributes.insert( QStringLiteral( 
"Closest vertex Y" ), formatYCoordinate( closestPointMapCoords ) );
   302   if ( closestPoint.
is3D() )
   304     str = QLocale::system().
toString( closestPoint.
z(), 
'g', 10 );
   305     derivedAttributes.insert( QStringLiteral( 
"Closest vertex Z" ), str );
   309     str = QLocale::system().toString( closestPoint.
m(), 
'g', 10 );
   310     derivedAttributes.insert( QStringLiteral( 
"Closest vertex M" ), str );
   315     double radius, centerX, centerY;
   321                                           geometry.
vertexAt( vIdAfter ), radius, centerX, centerY );
   322     derivedAttributes.insert( QStringLiteral( 
"Closest vertex radius" ), QLocale::system().toString( radius ) );
   326 QString QgsMapToolIdentify::formatCoordinate( 
const QgsPointXY &canvasPoint )
 const   329          mCoordinatePrecision );
   332 QString QgsMapToolIdentify::formatXCoordinate( 
const QgsPointXY &canvasPoint )
 const   334   QString coordinate = formatCoordinate( canvasPoint );
   335   return coordinate.split( 
',' ).at( 0 );
   338 QString QgsMapToolIdentify::formatYCoordinate( 
const QgsPointXY &canvasPoint )
 const   340   QString coordinate = formatCoordinate( canvasPoint );
   341   return coordinate.split( 
',' ).at( 1 );
   348   QMap< QString, QString > derivedAttributes;
   371     QString str = QLocale::system().toString( static_cast<const QgsGeometryCollection *>( feature->
geometry().
constGet() )->numGeometries() );
   372     derivedAttributes.insert( tr( 
"Parts" ), str );
   373     str = QLocale::system().toString( vId.
part + 1 );
   374     derivedAttributes.insert( tr( 
"Part number" ), str );
   381     QString str = formatDistance( dist );
   382     derivedAttributes.insert( tr( 
"Length" ), str );
   387       str = QLocale::system().toString( geom->
nCoordinates() );
   388       derivedAttributes.insert( tr( 
"Vertices" ), str );
   390       closestVertexAttributes( *geom, vId, layer, derivedAttributes );
   392       if ( 
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom ) )
   396         str = formatXCoordinate( pnt );
   397         derivedAttributes.insert( tr( 
"firstX", 
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
   398         str = formatYCoordinate( pnt );
   399         derivedAttributes.insert( tr( 
"firstY" ), str );
   401         str = formatXCoordinate( pnt );
   402         derivedAttributes.insert( tr( 
"lastX", 
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
   403         str = formatYCoordinate( pnt );
   404         derivedAttributes.insert( tr( 
"lastY" ), str );
   412     QString str = formatArea( area );
   413     derivedAttributes.insert( tr( 
"Area" ), str );
   417     str = formatDistance( perimeter );
   418     derivedAttributes.insert( tr( 
"Perimeter" ), str );
   421     derivedAttributes.insert( tr( 
"Vertices" ), str );
   424     closestVertexAttributes( *feature->
geometry().
constGet(), vId, layer, derivedAttributes );
   432       QString str = formatXCoordinate( pnt );
   433       derivedAttributes.insert( QStringLiteral( 
"X" ), str );
   434       str = formatYCoordinate( pnt );
   435       derivedAttributes.insert( QStringLiteral( 
"Y" ), str );
   439         str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->
geometry().
constGet() )->z(), 
'g', 10 );
   440         derivedAttributes.insert( QStringLiteral( 
"Z" ), str );
   444         str = QLocale::system().toString( static_cast<const QgsPoint *>( feature->
geometry().
constGet() )->m(), 
'g', 10 );
   445         derivedAttributes.insert( QStringLiteral( 
"M" ), str );
   455         closestVertexAttributes( *geom, vId, layer, derivedAttributes );
   460   return derivedAttributes;
   485     QgsDebugMsg( QString( 
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
   488   QgsDebugMsg( QString( 
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
   493   QMap< QString, QString > attributes, derivedAttributes;
   518     r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
   519     r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
   520     r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
   521     r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
   525     identifyResult = dprovider->
identify( point, format, r, 1, 1 );
   541     int width = std::round( viewExtent.
width() / mapUnitsPerPixel );
   542     int height = std::round( viewExtent.
height() / mapUnitsPerPixel );
   544     QgsDebugMsg( QString( 
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
   545     QgsDebugMsg( QString( 
"width = %1 height = %2" ).arg( width ).arg( height ) );
   546     QgsDebugMsg( QString( 
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
   548     identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
   551   derivedAttributes.insert( tr( 
"(clicked coordinate X)" ), formatXCoordinate( pointInCanvasCrs ) );
   552   derivedAttributes.insert( tr( 
"(clicked coordinate Y)" ), formatYCoordinate( pointInCanvasCrs ) );
   554   if ( identifyResult.
isValid() )
   556     QMap<int, QVariant> values = identifyResult.
results();
   560       for ( 
auto it = values.constBegin(); it != values.constEnd(); ++it )
   563         if ( it.value().isNull() )
   565           valueString = tr( 
"no data" );
   569           QVariant value( it.value() );
   573           if ( static_cast<QMetaType::Type>( value.type() ) == QMetaType::Float )
   584       QString label = layer->
name();
   585       results->append( 
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
   589       for ( 
auto it = values.constBegin(); it != values.constEnd(); ++it )
   591         QVariant value = it.value();
   592         if ( value.type() == QVariant::Bool && !value.toBool() )
   598         if ( value.type() == QVariant::String )
   602           QString label = layer->
subLayers().value( it.key() );
   604           attributes.insert( tr( 
"Error" ), value.toString() );
   606           results->append( 
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
   622             QString sublayer = featureStore.params().value( QStringLiteral( 
"sublayer" ) ).toString();
   623             QString featureType = featureStore.params().value( QStringLiteral( 
"featureType" ) ).toString();
   625             featureType.remove( QStringLiteral( 
"_feature" ) );
   627             if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
   631             if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
   633               labels << featureType;
   636             QMap< QString, QString > derAttributes = derivedAttributes;
   637             derAttributes.unite( featureDerivedAttributes( &feature, layer ) );
   639             IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join( QStringLiteral( 
" / " ) ), featureStore.fields(), feature, derAttributes );
   641             identifyResult.mParams.insert( QStringLiteral( 
"getFeatureInfoUrl" ), featureStore.params().value( QStringLiteral( 
"getFeatureInfoUrl" ) ) );
   642             results->append( identifyResult );
   649       QgsDebugMsg( QString( 
"%1 HTML or text values" ).arg( values.size() ) );
   650       for ( 
auto it = values.constBegin(); it != values.constEnd(); ++it )
   652         QString value = it.value().toString();
   654         attributes.insert( QLatin1String( 
"" ), value );
   656         QString label = layer->
subLayers().value( it.key() );
   657         results->append( 
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
   665     attributes.insert( tr( 
"Error" ), value );
   666     QString label = tr( 
"Identify error" );
   667     results->append( 
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
   683 QString QgsMapToolIdentify::formatDistance( 
double distance )
 const   686   bool baseUnit = settings.
value( QStringLiteral( 
"qgis/measure/keepbaseunit" ), 
true ).toBool();
   691 QString QgsMapToolIdentify::formatArea( 
double area )
 const   694   bool baseUnit = settings.
value( QStringLiteral( 
"qgis/measure/keepbaseunit" ), 
true ).toBool();
   701   QList<IdentifyResult> results;
   702   if ( 
identifyRasterLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel ) )
 bool isMeasure() const
Returns true if the geometry contains m values. 
 
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection, bool flag=false) const
Return the setting value for a setting based on an enum. 
 
Wrapper for iterator of features from vector data provider or vector layer. 
 
A container for features with the same fields and crs. 
 
bool contains(const QgsRectangle &rect) const
Return true when rectangle contains other rectangle. 
 
A rectangle specified with double values. 
 
Base class for all map layer types. 
 
QStringList subLayers() const override
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS. 
 
static QString printValue(double value)
Print double value with all necessary significant digits. 
 
void setXMaximum(double x)
Set the maximum x value. 
 
Use exact geometry intersection (slower) instead of bounding boxes. 
 
This class is a composition of two QSettings instances: 
 
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type. 
 
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. 
 
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ...
 
QList< QgsFeatureStore > QgsFeatureStoreList
 
QList< QgsFeature > QgsFeatureList
 
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.) 
 
A class to represent a 2D point. 
 
#define FID_TO_STRING(fid)
 
int layerCount() const
return number of layers on the map 
 
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas. 
 
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
 
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale. 
 
A geometry is the spatial representation of a feature. 
 
QString toString(int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision. 
 
double convertLengthMeasurement(double length, QgsUnitTypes::DistanceUnit toUnits) const
Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different d...
 
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym. 
 
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
 
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point. 
 
double convertAreaMeasurement(double area, QgsUnitTypes::AreaUnit toUnits) const
Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different ar...
 
bool hasGeometry() const
Returns true if the feature has an associated geometry. 
 
QgsMapLayer::LayerType type() const
Returns the type of the layer. 
 
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension. 
 
Map canvas is a class for displaying all GIS data types on a canvas. 
 
QgsCoordinateTransformContext transformContext() const
Returns a copy of the project's coordinate transform context, which stores various information regard...
 
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system 
 
virtual QgsRectangle extent() const
Returns the extent of the layer. 
 
Raster identify results container. 
 
QgsRasterDataProvider * dataProvider() override
 
bool isValid() const
Returns true if valid. 
 
Type
The WKB type describes the number of dimensions a geometry has. 
 
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject. 
 
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas. 
 
QgsFields fields() const override
Returns the list of fields of this layer. 
 
Utility class for identifying a unique vertex within a geometry. 
 
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
 
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 scale() const
Returns the calculated map scale. 
 
double width() const
Returns the width of the rectangle. 
 
void setYMinimum(double y)
Set the minimum y value. 
 
QgsRectangle extent() const
Returns the current zoom extent of the map canvas. 
 
This class wraps a request for features to a vector layer (or directly its vector data provider)...
 
bool isSpatial() const override
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
 
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors. 
 
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system. 
 
QgsFeatureRenderer * renderer()
Return renderer. 
 
Abstract base class for curved geometry type. 
 
double measureLength(const QgsGeometry &geometry) const
Measures the length of a geometry. 
 
Abstract base class for all geometries. 
 
QgsGeometry geometry() const
Returns the geometry associated with this feature. 
 
Point geometry type, with support for z-dimension and m-values. 
 
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType. 
 
double measurePerimeter(const QgsGeometry &geometry) const
Measures the perimeter of a polygon geometry. 
 
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override
Query the layer for features specified in request. 
 
QMap< int, QVariant > results() const
Get results. 
 
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive. 
 
QgsMapLayer * currentLayer()
returns current layer (set by legend widget) 
 
QgsExpressionContext & expressionContext()
Gets the expression context. 
 
DistanceUnit
Units of distance. 
 
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering. 
 
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way. 
 
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
 
QgsUnitTypes::DistanceUnit mapUnits() const
Convience function for returning the current canvas map units. 
 
Contains information about the context of a rendering operation. 
 
QString message(QgsErrorMessage::Format format=QgsErrorMessage::Html) const
Full error messages description. 
 
QgsPointXY asPoint() const
Returns contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
 
QgsError error() const
Get error. 
 
void setYMaximum(double y)
Set the maximum y value. 
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key. 
 
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS 
 
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings 
 
static QgsProject * instance()
Returns the QgsProject singleton instance. 
 
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. 
 
static void circleCenterRadius(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double &radius, double ¢erX, double ¢erY)
Returns radius and center of the circle through pt1, pt2, pt3. 
 
static QString formatArea(double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string. 
 
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform. 
 
static bool hasM(Type type)
Tests whether a WKB type contains m values. 
 
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor. 
 
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs. 
 
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. 
 
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer. 
 
bool nextFeature(QgsFeature &f)
 
virtual QString generateBandName(int bandNumber) const
helper function to create zero padded band names 
 
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id. 
 
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry. 
 
Represents a vector layer which manages a vector based data sets. 
 
static Type flatType(Type type)
Returns the flat type for a WKB type. 
 
static Q_INVOKABLE QgsUnitTypes::AreaUnit distanceToAreaUnit(QgsUnitTypes::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding area unit, e.g., meters to square meters. 
 
bool is3D() const
Returns true if the geometry is 3D and contains a z-value. 
 
QgsPointXY toMapCoordinates(int x, int y) const
 
QgsMapLayer * layer(int index)
return the map layer at position index in the layer stack 
 
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer. 
 
double measureArea(const QgsGeometry &geometry) const
Measures the area of a geometry. 
 
void setXMinimum(double x)
Set the minimum x value. 
 
double height() const
Returns the height of the rectangle. 
 
Base class for raster data providers. 
 
static QString formatDistance(double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit=false)
Returns an distance formatted as a friendly string.