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 );
215 commonDerivedAttributes.
insert(
tr(
"(clicked coordinate X)" ), formatXCoordinate( point ) );
216 commonDerivedAttributes.
insert(
tr(
"(clicked coordinate Y)" ), formatYCoordinate( point ) );
218 int featureCount = 0;
264 for ( ; f_it != featureList.
end(); ++f_it )
280 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
291 return featureCount > 0;
297 derivedAttributes.
insert(
tr(
"Closest vertex number" ), str );
302 derivedAttributes.
insert(
"Closest vertex X", formatXCoordinate( closestPointMapCoords ) );
303 derivedAttributes.
insert(
"Closest vertex Y", formatYCoordinate( closestPointMapCoords ) );
305 if ( closestPoint.
is3D() )
308 derivedAttributes.
insert(
"Closest vertex Z", str );
313 derivedAttributes.
insert(
"Closest vertex M", str );
317 QString QgsMapToolIdentify::formatCoordinate(
const QgsPoint& canvasPoint )
const 320 mCoordinatePrecision );
323 QString QgsMapToolIdentify::formatXCoordinate(
const QgsPoint& canvasPoint )
const 325 QString coordinate = formatCoordinate( canvasPoint );
326 return coordinate.
split(
',' ).
at( 0 );
329 QString QgsMapToolIdentify::formatYCoordinate(
const QgsPoint& canvasPoint )
const 331 QString coordinate = formatCoordinate( canvasPoint );
332 return coordinate.
split(
',' ).
at( 1 );
364 derivedAttributes.
insert(
tr(
"Parts" ), str );
366 derivedAttributes.
insert(
tr(
"Part number" ), str );
373 QString str = formatDistance( dist );
374 derivedAttributes.
insert(
tr(
"Length" ), str );
380 derivedAttributes.
insert(
tr(
"Vertices" ), str );
383 closestVertexAttributes( *curve, vId, layer, derivedAttributes );
387 str = formatXCoordinate( pnt );
388 derivedAttributes.
insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
389 str = formatYCoordinate( pnt );
390 derivedAttributes.
insert(
tr(
"firstY" ), str );
392 str = formatXCoordinate( pnt );
393 derivedAttributes.
insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
394 str = formatYCoordinate( pnt );
395 derivedAttributes.
insert(
tr(
"lastY" ), str );
402 QString str = formatArea( area );
403 derivedAttributes.
insert(
tr(
"Area" ), str );
407 str = formatDistance( perimeter );
408 derivedAttributes.
insert(
tr(
"Perimeter" ), str );
411 derivedAttributes.
insert(
tr(
"Vertices" ), str );
421 QString str = formatXCoordinate( pnt );
422 derivedAttributes.
insert(
"X", str );
423 str = formatYCoordinate( pnt );
424 derivedAttributes.
insert(
"Y", str );
429 derivedAttributes.
insert(
"Z", str );
434 derivedAttributes.
insert(
"M", str );
438 return derivedAttributes;
496 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
497 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
498 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
499 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
503 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
519 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
520 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
524 QgsDebugMsg(
QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
526 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
529 derivedAttributes.
insert(
tr(
"(clicked coordinate X)" ), formatXCoordinate( pointInCanvasCrs ) );
530 derivedAttributes.
insert(
tr(
"(clicked coordinate Y)" ), formatYCoordinate( pointInCanvasCrs ) );
532 if ( identifyResult.
isValid() )
538 Q_FOREACH (
int bandNo, values.
keys() )
541 if ( values.
value( bandNo ).isNull() )
543 valueString =
tr(
"no data" );
547 double value = values.
value( bandNo ).toDouble();
553 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
557 Q_FOREACH (
int i, values.
keys() )
560 if ( value.
type() == QVariant::Bool && !value.
toBool() )
566 if ( value.
type() == QVariant::String )
574 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
592 featureType.
remove(
"_feature" );
594 if ( sublayer.
compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
598 if ( featureType.
compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.
isEmpty() )
600 labels << featureType;
604 derAttributes.
unite( featureDerivedAttributes( &feature, layer ) );
606 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.
join(
" / " ), featureStore.
fields(), feature, derAttributes );
608 identifyResult.mParams.
insert(
"getFeatureInfoUrl", featureStore.
params().
value(
"getFeatureInfoUrl" ) );
609 results->
append( identifyResult );
617 Q_FOREACH (
int bandNo, values.
keys() )
621 attributes.
insert(
"", value );
624 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
632 attributes.
insert(
tr(
"Error" ), value );
634 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
669 QString QgsMapToolIdentify::formatDistance(
double distance )
const 672 bool baseUnit = settings.
value(
"/qgis/measure/keepbaseunit",
false ).
toBool();
677 QString QgsMapToolIdentify::formatArea(
double area )
const 680 bool baseUnit = settings.
value(
"/qgis/measure/keepbaseunit",
false ).
toBool();
689 if (
identifyRasterLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel ) )
bool isValid() const
Returns true if valid.
Wrapper for iterator of features from vector data provider or vector layer.
Container for features with the same fields and crs.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
Base class for all map layer types.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
virtual QStringList subLayers() const override
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.
QgsMapLayer::LayerType type() const
Get the type of the layer.
static QString printValue(double value)
Print double value with all necessary significant digits.
void convertMeasurement(double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea) const
Helper for conversion between physical units.
double scale() const
Return the calculated scale of the map.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
int layerCount() const
return number of layers on the map
QString name() const
Get the display name of the layer.
void setXMaximum(double x)
Set the maximum x value.
QString toString(qlonglong i) const
Use exact geometry intersection (slower) instead of bounding boxes.
double x() const
Returns the point's x-coordinate.
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.
QgsFields fields() const
Returns the list of fields of this layer.
long srsid() const
Returns the SrsId, if available.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
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.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
const T & at(int i) const
float minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
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)
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
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)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
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.
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)
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
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.
QMap< int, QVariant > results() const
Get results.
double x() const
Get the x value of the point.
int nCoordinates() const
Returns the number of nodes contained in the geometry.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
double y() const
Returns the point's y-coordinate.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
Raster identify results container.
QList< Key > keys() const
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QgsRasterIdentifyResult identify(const QgsPoint &thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent=QgsRectangle(), int theWidth=0, int theHeight=0)
Identify raster value(s) found on the point position.
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
int toInt(bool *ok) const
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
double z() const
Returns the point's z-coordinate.
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
double convertAreaMeasurement(double area, QgsUnitTypes::AreaUnit toUnits) const
Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different ar...
float maximumScale() const
Returns the maximum scale denominator at which the layer is visible.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
Point geometry type, with support for z-dimension and m-values.
void setYMinimum(double y)
Set the minimum y value.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setOverrideCursor(const QCursor &cursor)
QString toString() const
String representation of the point (x,y)
void restoreOverrideCursor()
double measurePerimeter(const QgsGeometry *geometry) const
Measures the perimeter of a polygon geometry.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
virtual QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
QGis::UnitType mapUnits() const
Get the current canvas map units.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString message(QgsErrorMessage::Format theFormat=QgsErrorMessage::Html) const
Full error messages description.
A class to represent a point.
double measureArea(const QgsGeometry *geometry) const
Measures the area of a geometry.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsPoint toMapCoordinates(int x, int y) const
static QString textUnit(double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit=false)
Returns a measurement formatted as a friendly string.
#define Q_NOWARN_DEPRECATED_POP
General purpose distance and area calculator.
double measureLength(const QgsGeometry *geometry) const
Measures the length of a geometry.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
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.
void setYMaximum(double y)
Set the maximum y value.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
static QgsProject * instance()
access to canonical QgsProject instance
static AreaUnit distanceToAreaUnit(QGis::UnitType distanceUnit)
Converts a distance unit to its corresponding area unit, eg meters to square meters.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
static QString formatArea(double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string.
double m() const
Returns the point's m value.
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 y() const
Get the y value of the point.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QgsFields & fields()
Get fields list.
static Type flatType(Type type)
Returns the flat type for a WKB type.
iterator insert(const Key &key, const T &value)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
Custom exception class for Coordinate Reference System related exceptions.
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)
Abstract base class for curved geometry type.
double convertLengthMeasurement(double length, QGis::UnitType toUnits) const
Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different d...
double width() const
Width of the rectangle.
QgsPoint asPoint() const
Return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
QgsError error() const
Get error.
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
QMap< QString, QVariant > params() const
Get map of optional parameters.
QgsFeatureList & features()
Get features list reference.
QgsMapLayer * layer(int index)
return the map layer at position index in the layer stack
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.
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.