40 #include <QMouseEvent>
50 , mLastMapUnitsPerPixel( -1.0 )
113 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
119 identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
131 layerCount = layerList.
count();
134 for (
int i = 0; i < layerCount; i++ )
141 layer = layerList.
value( i );
146 if ( noIdentifyLayerIdList.
contains( layer->
id() ) )
149 if (
identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
179 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
208 commonDerivedAttributes.
insert(
tr(
"(clicked coordinate)" ), point.
toString() );
210 int featureCount = 0;
256 for ( ; f_it != featureList.
end(); ++f_it )
268 derivedAttributes.
unite( featureDerivedAttributes( &( *f_it ), layer ) );
272 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
283 return featureCount > 0;
313 convertMeasurement( calc, dist, myDisplayUnits,
false );
315 derivedAttributes.
insert(
tr(
"Length" ), str );
317 derivedAttributes.
insert(
tr(
"Vertices" ), str );
323 derivedAttributes.
insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
325 derivedAttributes.
insert(
tr(
"firstY" ), str );
328 derivedAttributes.
insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
330 derivedAttributes.
insert(
tr(
"lastY" ), str );
338 convertMeasurement( calc, area, myDisplayUnits,
true );
340 derivedAttributes.
insert(
tr(
"Area" ), str );
341 convertMeasurement( calc, perimeter, myDisplayUnits,
false );
342 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
343 derivedAttributes.
insert(
tr(
"Perimeter" ), str );
351 derivedAttributes.
insert(
"X", str );
353 derivedAttributes.
insert(
"Y", str );
356 return derivedAttributes;
414 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
415 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
416 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
417 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
421 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
437 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
438 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
442 QgsDebugMsg(
QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
444 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
449 if ( identifyResult.
isValid() )
455 Q_FOREACH (
int bandNo, values.
keys() )
458 if ( values.
value( bandNo ).isNull() )
460 valueString =
tr(
"no data" );
464 double value = values.
value( bandNo ).toDouble();
470 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
474 Q_FOREACH (
int i, values.
keys() )
477 if ( value.
type() == QVariant::Bool && !value.
toBool() )
483 if ( value.
type() == QVariant::String )
491 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
509 featureType.
remove(
"_feature" );
511 if ( sublayer.
compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
515 if ( featureType.
compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.
isEmpty() )
517 labels << featureType;
521 derAttributes.
unite( featureDerivedAttributes( &feature, layer ) );
523 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.
join(
" / " ), featureStore.
fields(), feature, derAttributes );
525 identifyResult.mParams.
insert(
"getFeatureInfoUrl", featureStore.
params().
value(
"getFeatureInfoUrl" ) );
526 results->
append( identifyResult );
534 Q_FOREACH (
int bandNo, values.
keys() )
538 attributes.
insert(
"", value );
541 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
549 attributes.
insert(
tr(
"Error" ), value );
551 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
578 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.
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
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)
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
Get the SrsId - if possible.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
UnitType
Map units that qgis supports.
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
float minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
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.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
A geometry is the spatial representation of a feature.
QString join(const QString &separator) const
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
WkbType
Used for symbology operations.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString & remove(int position, int n)
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
return 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.
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.
virtual void stopRender(QgsRenderContext &context)=0
Raster identify results container.
QList< Key > keys() const
const QString & name() const
Get the display name of the layer.
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 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
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
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
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 perimeter of polygon
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::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
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)
General purpose distance and area calculator.
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
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
Contains information about the context of a rendering operation.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
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
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
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.
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)
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
void setXMinimum(double x)
Set the minimum x value.
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=0) const
Key value accessors.
double height() const
Height of the rectangle.
const T value(const Key &key) const
Base class for raster data providers.