40 #include <QMouseEvent> 50 , mLastMapUnitsPerPixel( -1.0 )
53 QPixmap myIdentifyQPixmap = QPixmap((
const char ** )
identify_cursor );
54 mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
84 return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
89 QList<IdentifyResult> results;
98 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
104 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
107 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
113 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
117 QApplication::setOverrideCursor( Qt::WaitCursor );
119 identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
123 QApplication::setOverrideCursor( Qt::WaitCursor );
128 if ( layerList.isEmpty() )
131 layerCount = layerList.count();
134 for (
int i = 0; i < layerCount; i++ )
138 if ( layerList.isEmpty() )
141 layer = layerList.value( i );
146 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
149 if (
identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
160 QApplication::restoreOverrideCursor();
179 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
204 QApplication::setOverrideCursor( Qt::WaitCursor );
206 QMap< QString, QString > commonDerivedAttributes;
208 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
210 int featureCount = 0;
242 QgsFeatureList::iterator f_it = featureList.begin();
255 for ( ; f_it != featureList.end(); ++f_it )
257 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
266 derivedAttributes.unite( featureDerivedAttributes( &( *f_it ), layer ) );
268 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
270 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
278 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
280 QApplication::restoreOverrideCursor();
281 return featureCount > 0;
284 QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes(
QgsFeature *feature,
QgsMapLayer *layer )
288 QMap< QString, QString > derivedAttributes;
310 convertMeasurement( calc, dist, myDisplayUnits,
false );
311 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
312 derivedAttributes.insert(
tr(
"Length" ), str );
317 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
318 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
319 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
320 derivedAttributes.insert(
tr(
"firstY" ), str );
322 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
323 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
324 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
325 derivedAttributes.insert(
tr(
"lastY" ), str );
333 convertMeasurement( calc, area, myDisplayUnits,
true );
334 QString str = calc.
textUnit( area, 3, 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 );
345 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
346 derivedAttributes.insert(
"X", str );
347 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
348 derivedAttributes.insert(
"Y", str );
351 return derivedAttributes;
376 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
379 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
384 QMap< QString, QString > attributes, 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 );
435 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
436 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
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 );
442 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
444 if ( identifyResult.
isValid() )
446 QMap<int, QVariant> values = identifyResult.
results();
450 foreach (
int bandNo, values.keys() )
453 if ( values.value( bandNo ).isNull() )
455 valueString =
tr(
"no data" );
459 double value = values.value( bandNo ).toDouble();
464 QString label = layer->
name();
465 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
469 foreach (
int i, values.keys() )
471 QVariant value = values.value( i );
472 if ( value.type() == QVariant::Bool && !value.toBool() )
478 if ( value.type() == QVariant::String )
482 QString label = layer->
subLayers().value( i );
484 attributes.insert(
tr(
"Error" ), value.toString() );
486 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
501 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
502 QString featureType = featureStore.
params().value(
"featureType" ).toString();
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;
515 QMap< QString, QString > derAttributes = derivedAttributes;
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 );
528 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
529 foreach (
int bandNo, values.keys() )
531 QString value = values.value( bandNo ).toString();
533 attributes.insert(
"", value );
535 QString label = layer->
subLayers().value( bandNo );
536 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
544 attributes.insert(
tr(
"Error" ), value );
545 QString label =
tr(
"Identify error" );
546 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
572 QList<IdentifyResult> results;
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.
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.
Use exact geometry intersection (slower) instead of bounding boxes.
virtual QgsCoordinateReferenceSystem crs()=0
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QList< QgsFeatureStore > QgsFeatureStoreList
QList< QgsFeature > QgsFeatureList
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.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
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.
#define FID_TO_STRING(fid)
QGis::GeometryType type() const
Returns type of the vector.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
WkbType
Used for symbology operations.
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...
Map canvas is a class for displaying all GIS data types on a canvas.
QMap< int, QVariant > results() const
Get results.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void stopRender(QgsRenderContext &context)=0
Raster identify results container.
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.
QStringList readListEntry(const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const
key value accessors
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
double measurePerimeter(QgsGeometry *geometry)
measures perimeter of polygon
double measure(QgsGeometry *geometry)
general measurement (line distance or polygon area)
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)...
QString toString() const
String representation of the point (x,y)
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 wkb (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...
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 CORE_EXPORT QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
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.
void convertMeasurement(double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea)
Helper for conversion between physical units.
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.
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.
Base class for raster data providers.