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;
255 for ( ; f_it != featureList.
end(); ++f_it )
266 derivedAttributes.
unite( featureDerivedAttributes( &( *f_it ), layer ) );
270 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
281 return featureCount > 0;
310 convertMeasurement( calc, dist, myDisplayUnits,
false );
312 derivedAttributes.
insert(
tr(
"Length" ), str );
318 derivedAttributes.
insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
320 derivedAttributes.
insert(
tr(
"firstY" ), str );
323 derivedAttributes.
insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
325 derivedAttributes.
insert(
tr(
"lastY" ), str );
333 convertMeasurement( calc, area, myDisplayUnits,
true );
335 derivedAttributes.
insert(
tr(
"Area" ), str );
336 convertMeasurement( calc, perimeter, myDisplayUnits,
false );
337 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
338 derivedAttributes.
insert(
tr(
"Perimeter" ), str );
346 derivedAttributes.
insert(
"X", str );
348 derivedAttributes.
insert(
"Y", str );
351 return derivedAttributes;
409 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
410 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
411 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
412 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
416 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
432 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
433 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
437 QgsDebugMsg(
QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
439 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
444 if ( identifyResult.
isValid() )
450 foreach (
int bandNo, values.
keys() )
453 if ( values.
value( bandNo ).isNull() )
455 valueString =
tr(
"no data" );
459 double value = values.
value( bandNo ).toDouble();
465 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
469 foreach (
int i, values.
keys() )
472 if ( value.
type() == QVariant::Bool && !value.
toBool() )
478 if ( value.
type() == QVariant::String )
486 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
504 featureType.
remove(
"_feature" );
506 if ( sublayer.
compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
510 if ( featureType.
compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.
isEmpty() )
512 labels << featureType;
516 derAttributes.
unite( featureDerivedAttributes( &feature, layer ) );
518 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.
join(
" / " ), featureStore.
fields(), feature, derAttributes );
520 identifyResult.mParams.
insert(
"getFeatureInfoUrl", featureStore.
params().
value(
"getFeatureInfoUrl" ) );
521 results->
append( identifyResult );
529 foreach (
int bandNo, values.
keys() )
533 attributes.
insert(
"", value );
536 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
544 attributes.
insert(
tr(
"Error" ), value );
546 results->
append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
573 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.
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
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)
virtual QgsCoordinateReferenceSystem crs()=0
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
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.
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.
WkbType
Used for symbology operations.
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)
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.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
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.
double measure(const QgsGeometry *geometry) const
general measurement (line distance or polygon area)
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.
QStringList readListEntry(const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const
key value accessors
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
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.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
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...
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.
UnitType
Map units that qgis supports.
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QgsFields & fields()
Get fields list.
iterator insert(const Key &key, const T &value)
static QgsRaster::IdentifyFormat identifyFormatFromName(QString formatName)
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.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
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
double height() const
Height of the rectangle.
const T value(const Key &key) const
Base class for raster data providers.