44 #include <QMouseEvent> 54 , mLastMapUnitsPerPixel( -1.0 )
55 , mCoordinatePrecision( 6 )
120 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
126 identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
138 layerCount = layerList.
count();
141 for (
int i = 0; i < layerCount; i++ )
148 layer = layerList.
value( i );
153 if ( noIdentifyLayerIdList.
contains( layer->
id() ) )
156 if (
identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
186 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
213 commonDerivedAttributes.
insert(
tr(
"(clicked coordinate X)" ), formatXCoordinate( point ) );
214 commonDerivedAttributes.
insert(
tr(
"(clicked coordinate Y)" ), formatYCoordinate( point ) );
216 int featureCount = 0;
262 for ( ; f_it != featureList.
end(); ++f_it )
278 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
289 return featureCount > 0;
295 derivedAttributes.
insert(
tr(
"Closest vertex number" ), str );
300 derivedAttributes.
insert(
"Closest vertex X", formatXCoordinate( closestPointMapCoords ) );
301 derivedAttributes.
insert(
"Closest vertex Y", formatYCoordinate( closestPointMapCoords ) );
303 if ( closestPoint.
is3D() )
306 derivedAttributes.
insert(
"Closest vertex Z", str );
311 derivedAttributes.
insert(
"Closest vertex M", str );
316 double radius, centerX, centerY;
322 geometry.
vertexAt( vIdAfter ), radius, centerX, centerY );
327 QString QgsMapToolIdentify::formatCoordinate(
const QgsPoint& canvasPoint )
const 330 mCoordinatePrecision );
333 QString QgsMapToolIdentify::formatXCoordinate(
const QgsPoint& canvasPoint )
const 335 QString coordinate = formatCoordinate( canvasPoint );
336 return coordinate.
split(
',' ).
at( 0 );
339 QString QgsMapToolIdentify::formatYCoordinate(
const QgsPoint& canvasPoint )
const 341 QString coordinate = formatCoordinate( canvasPoint );
342 return coordinate.
split(
',' ).
at( 1 );
374 derivedAttributes.
insert(
tr(
"Parts" ), str );
376 derivedAttributes.
insert(
tr(
"Part number" ), str );
383 QString str = formatDistance( dist );
384 derivedAttributes.
insert(
tr(
"Length" ), str );
390 derivedAttributes.
insert(
tr(
"Vertices" ), str );
393 closestVertexAttributes( *curve, vId, layer, derivedAttributes );
397 str = formatXCoordinate( pnt );
398 derivedAttributes.
insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
399 str = formatYCoordinate( pnt );
400 derivedAttributes.
insert(
tr(
"firstY" ), str );
402 str = formatXCoordinate( pnt );
403 derivedAttributes.
insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
404 str = formatYCoordinate( pnt );
405 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 );
431 QString str = formatXCoordinate( pnt );
432 derivedAttributes.
insert(
"X", str );
433 str = formatYCoordinate( pnt );
434 derivedAttributes.
insert(
"Y", str );
439 derivedAttributes.
insert(
"Z", str );
444 derivedAttributes.
insert(
"M", str );
448 return derivedAttributes;
506 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
507 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
508 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
509 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
513 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
529 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
530 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
534 QgsDebugMsg(
QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
536 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
539 derivedAttributes.
insert(
tr(
"(clicked coordinate X)" ), formatXCoordinate( pointInCanvasCrs ) );
540 derivedAttributes.
insert(
tr(
"(clicked coordinate Y)" ), formatYCoordinate( pointInCanvasCrs ) );
542 if ( identifyResult.
isValid() )
548 Q_FOREACH (
int bandNo, values.
keys() )
551 if ( values.
value( bandNo ).isNull() )
553 valueString =
tr(
"no data" );
561 if ( static_cast<QMetaType::Type>( value.type() ) == QMetaType::Float )
573 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
577 Q_FOREACH (
int i, values.
keys() )
580 if ( value.
type() == QVariant::Bool && !value.
toBool() )
586 if ( value.
type() == QVariant::String )
594 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
612 featureType.
remove(
"_feature" );
614 if ( sublayer.
compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
618 if ( featureType.
compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.
isEmpty() )
620 labels << featureType;
624 derAttributes.
unite( featureDerivedAttributes( &feature, layer ) );
626 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.
join(
" / " ), featureStore.
fields(), feature, derAttributes );
628 identifyResult.mParams.
insert(
"getFeatureInfoUrl", featureStore.
params().
value(
"getFeatureInfoUrl" ) );
629 results->
append( identifyResult );
637 Q_FOREACH (
int bandNo, values.
keys() )
641 attributes.
insert(
"", value );
644 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
652 attributes.
insert(
tr(
"Error" ), value );
654 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
689 QString QgsMapToolIdentify::formatDistance(
double distance )
const 692 bool baseUnit = settings.
value(
"/qgis/measure/keepbaseunit",
false ).
toBool();
697 QString QgsMapToolIdentify::formatArea(
double area )
const 700 bool baseUnit = settings.
value(
"/qgis/measure/keepbaseunit",
false ).
toBool();
708 if (
identifyRasterLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel ) )
Wrapper for iterator of features from vector data provider or vector layer.
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.
double convertLengthMeasurement(double length, QGis::UnitType toUnits) const
Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different d...
virtual QStringList subLayers() const override
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
static QString printValue(double value)
Print double value with all necessary significant digits.
QgsPoint asPoint() const
Return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
void setXMaximum(double x)
Set the maximum x value.
QString toString(qlonglong i) const
Use exact geometry intersection (slower) instead of bounding boxes.
QMap< Key, T > & unite(const QMap< Key, T > &other)
static bool hasM(Type type)
Tests whether a WKB type contains m values.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
virtual QgsCoordinateReferenceSystem crs()=0
Get the QgsCoordinateReferenceSystem for this layer.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
virtual QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
const T & at(int i) const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
#define Q_NOWARN_DEPRECATED_PUSH
bool hasCrsTransformEnabled()
A simple helper method to find out if on the fly projections are enabled or not.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
#define FID_TO_STRING(fid)
static void circleCenterRadius(const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QgsPointV2 &pt3, double &radius, double ¢erX, double ¢erY)
Returns radius and center of the circle through pt1, pt2, pt3.
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.
Abstract base class for all geometries.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
QgsPoint toMapCoordinates(int x, int y) const
A geometry is the spatial representation of a feature.
static QgsPointV2 closestVertex(const QgsAbstractGeometryV2 &geom, const QgsPointV2 &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
depends on scale if feature will be rendered (rule based )
QString join(const QString &separator) const
bool setEllipsoid(const QString &ellipsoid)
Sets ellipsoid by its acronym.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString & remove(int position, int n)
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 z() const
Returns the point's z-coordinate.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
double y() const
Returns the point's y-coordinate.
QgsMapLayer::LayerType type() const
Get the type of the layer.
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
Returns whether the renderer will render a feature or not.
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
double y() const
Get the y value of the point.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
QgsFields fields() const
Returns the list of fields of this layer.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
Raster identify results container.
QList< Key > keys() const
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
QString number(int n, int base)
bool isValid() const
Returns true if valid.
int count(const T &value) const
virtual QgsRasterIdentifyResult identify(const QgsPoint &thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent=QgsRectangle(), int theWidth=0, int theHeight=0, int theDpi=96)
Identify raster value(s) found on the point position.
void append(const T &value)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
int toInt(bool *ok) const
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.
double scale() const
Return the calculated scale of the map.
QGis::UnitType mapUnits() const
Get the current canvas map units.
bool isMeasure() const
Returns true if the geometry contains m values.
double width() const
Width of the rectangle.
Point geometry type, with support for z-dimension and m-values.
void setYMinimum(double y)
Set the minimum y value.
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setOverrideCursor(const QCursor &cursor)
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
void restoreOverrideCursor()
double x() const
Returns the point's x-coordinate.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
A class to represent a point.
QString toString() const
String representation of the point (x,y)
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
QMap< int, QVariant > results() const
Get results.
double measureArea(const QgsGeometry *geometry) const
Measures the area of a geometry.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
#define Q_NOWARN_DEPRECATED_POP
General purpose distance and area calculator.
double measurePerimeter(const QgsGeometry *geometry) const
Measures the perimeter of a polygon geometry.
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual QgsPointV2 endPoint() const =0
Returns the end point of the curve.
Contains information about the context of a rendering operation.
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
QgsError error() const
Get error.
void setYMaximum(double y)
Set the maximum y value.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
void convertMeasurement(double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea) const
Helper for conversion between physical units.
static QgsProject * instance()
Returns the QgsProject singleton instance.
static AreaUnit distanceToAreaUnit(QGis::UnitType distanceUnit)
Converts a distance unit to its corresponding area unit, eg meters to square meters.
QMap< QString, QVariant > params() const
Get map of optional parameters.
static QString formatArea(double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string.
UnitType
Map units that qgis supports.
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
virtual QgsPointV2 startPoint() const =0
Returns the starting point of the curve.
double measureLength(const QgsGeometry *geometry) const
Measures the length of a geometry.
QgsFields & fields()
Get fields list.
static Type flatType(Type type)
Returns the flat type for a WKB type.
QString name
Read property of QString layerName.
iterator insert(const Key &key, const T &value)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
static QString formatDistance(double distance, int decimals, QGis::UnitType unit, bool keepBaseUnit=false)
Returns an distance formatted as a friendly string.
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.
const char * identify_cursor[]
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
features may be filtered, i.e. some features may not be rendered (categorized, rule based ...
long srsid() const
Returns the SrsId, if available.
Abstract base class for curved geometry type.
virtual QgsRectangle extent()
Return the extent of the layer.
Represents a vector layer which manages a vector based data sets.
int compare(const QString &other) const
QString message(QgsErrorMessage::Format theFormat=QgsErrorMessage::Html) const
Full error messages description.
double m() const
Returns the point's m value.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QgsFeatureList & features()
Get features list reference.
QgsMapLayer * layer(int index)
return the map layer at position index in the layer stack
double x() const
Get the x value of the point.
virtual QgsPointV2 vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
void setXMinimum(double x)
Set the minimum x value.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
void setEllipsoidalMode(bool flag)
Sets whether coordinates must be projected to ellipsoid before measuring.
double height() const
Height of the rectangle.
const T value(const Key &key) const
Base class for raster data providers.