QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsmaptoolidentify.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptoolidentify.cpp - map tool for identifying features
3  ---------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsapplication.h"
17 #include "qgscursors.h"
18 #include "qgsdistancearea.h"
19 #include "qgsfeature.h"
20 #include "qgsfeaturestore.h"
21 #include "qgsfield.h"
22 #include "qgsgeometry.h"
23 #include "qgsidentifymenu.h"
24 #include "qgslogger.h"
25 #include "qgsmapcanvas.h"
26 #include "qgsmaptoolidentify.h"
27 #include "qgsmaptopixel.h"
28 #include "qgsmessageviewer.h"
29 #include "qgsmaplayer.h"
30 #include "qgsrasterlayer.h"
33 #include "qgsvectordataprovider.h"
34 #include "qgsvectorlayer.h"
35 #include "qgsproject.h"
36 #include "qgsmaplayerregistry.h"
37 #include "qgsrendererv2.h"
38 
39 #include <QSettings>
40 #include <QMouseEvent>
41 #include <QCursor>
42 #include <QPixmap>
43 #include <QStatusBar>
44 #include <QVariant>
45 #include <QMenu>
46 
48  : QgsMapTool( canvas )
49  , mIdentifyMenu( new QgsIdentifyMenu( mCanvas ) )
50 {
51  // set cursor
52  QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
53  mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
54 }
55 
57 {
58  delete mIdentifyMenu;
59 }
60 
61 void QgsMapToolIdentify::canvasMoveEvent( QMouseEvent * e )
62 {
63  Q_UNUSED( e );
64 }
65 
66 void QgsMapToolIdentify::canvasPressEvent( QMouseEvent * e )
67 {
68  Q_UNUSED( e );
69 }
70 
72 {
73  Q_UNUSED( e );
74 }
75 
76 QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( int x, int y, QList<QgsMapLayer *> layerList, IdentifyMode mode )
77 {
78  return identify( x, y, mode, layerList, AllLayers );
79 }
80 
81 QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( int x, int y, IdentifyMode mode, LayerType layerType )
82 {
83  return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
84 }
85 
86 QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType )
87 {
88  QList<IdentifyResult> results;
89 
90  mLastPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( x, y );
91  mLastExtent = mCanvas->extent();
92  mLastMapUnitsPerPixel = mCanvas->mapUnitsPerPixel();
93 
94  if ( mode == DefaultQgsSetting )
95  {
96  QSettings settings;
97  mode = static_cast<IdentifyMode>( settings.value( "/Map/identifyMode", 0 ).toInt() );
98  }
99 
100  if ( mode == LayerSelection )
101  {
102  QList<IdentifyResult> results = identify( x, y, TopDownAll, layerList, layerType );
103  QPoint globalPos = mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
104  return mIdentifyMenu->exec( results, globalPos );
105  }
106  else if ( mode == ActiveLayer && layerList.isEmpty() )
107  {
108  QgsMapLayer *layer = mCanvas->currentLayer();
109 
110  if ( !layer )
111  {
112  emit identifyMessage( tr( "No active layer. To identify features, you must choose an active layer." ) );
113  return results;
114  }
115 
116  QApplication::setOverrideCursor( Qt::WaitCursor );
117 
118  identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
119  }
120  else
121  {
122  QApplication::setOverrideCursor( Qt::WaitCursor );
123 
124  QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
125 
126  int layerCount;
127  if ( layerList.isEmpty() )
128  layerCount = mCanvas->layerCount();
129  else
130  layerCount = layerList.count();
131 
132 
133  for ( int i = 0; i < layerCount; i++ )
134  {
135 
136  QgsMapLayer *layer;
137  if ( layerList.isEmpty() )
138  layer = mCanvas->layer( i );
139  else
140  layer = layerList.value( i );
141 
142  emit identifyProgress( i, mCanvas->layerCount() );
143  emit identifyMessage( tr( "Identifying on %1..." ).arg( layer->name() ) );
144 
145  if ( noIdentifyLayerIdList.contains( layer->id() ) )
146  continue;
147 
148  if ( identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
149  {
150  if ( mode == TopDownStopAtFirst )
151  break;
152  }
153  }
154 
156  emit identifyMessage( tr( "Identifying done." ) );
157  }
158 
159  QApplication::restoreOverrideCursor();
160 
161  return results;
162 }
163 
165 {
167 }
168 
170 {
172 }
173 
174 bool QgsMapToolIdentify::identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType )
175 {
176  if ( layer->type() == QgsMapLayer::RasterLayer && layerType.testFlag( RasterLayer ) )
177  {
178  return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
179  }
180  else if ( layer->type() == QgsMapLayer::VectorLayer && layerType.testFlag( VectorLayer ) )
181  {
182  return identifyVectorLayer( results, qobject_cast<QgsVectorLayer *>( layer ), point );
183  }
184  else
185  {
186  return false;
187  }
188 }
189 
190 bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point )
191 {
192  if ( !layer || !layer->hasGeometryType() )
193  return false;
194 
195  if ( layer->hasScaleBasedVisibility() &&
196  ( layer->minimumScale() > mCanvas->mapSettings().scale() ||
197  layer->maximumScale() <= mCanvas->mapSettings().scale() ) )
198  {
199  QgsDebugMsg( "Out of scale limits" );
200  return false;
201  }
202 
203  QApplication::setOverrideCursor( Qt::WaitCursor );
204 
205  QMap< QString, QString > commonDerivedAttributes;
206 
207  commonDerivedAttributes.insert( tr( "(clicked coordinate)" ), point.toString() );
208 
209  int featureCount = 0;
210 
211  QgsFeatureList featureList;
212 
213  // toLayerCoordinates will throw an exception for an 'invalid' point.
214  // For example, if you project a world map onto a globe using EPSG 2163
215  // and then click somewhere off the globe, an exception will be thrown.
216  try
217  {
218  // create the search rectangle
219  double searchRadius = searchRadiusMU( mCanvas );
220 
221  QgsRectangle r;
222  r.setXMinimum( point.x() - searchRadius );
223  r.setXMaximum( point.x() + searchRadius );
224  r.setYMinimum( point.y() - searchRadius );
225  r.setYMaximum( point.y() + searchRadius );
226 
227  r = toLayerCoordinates( layer, r );
228 
229  QgsFeatureIterator fit = layer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) );
230  QgsFeature f;
231  while ( fit.nextFeature( f ) )
232  featureList << QgsFeature( f );
233  }
234  catch ( QgsCsException & cse )
235  {
236  Q_UNUSED( cse );
237  // catch exception for 'invalid' point and proceed with no features found
238  QgsDebugMsg( QString( "Caught CRS exception %1" ).arg( cse.what() ) );
239  }
240 
241  QgsFeatureList::iterator f_it = featureList.begin();
242 
243  bool filter = false;
244 
246  QgsFeatureRendererV2* renderer = layer->rendererV2();
247  if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
248  {
249  // setup scale for scale dependent visibility (rule based)
250  renderer->startRender( context, layer->pendingFields() );
251  filter = renderer->capabilities() & QgsFeatureRendererV2::Filter;
252  }
253 
254  for ( ; f_it != featureList.end(); ++f_it )
255  {
256  QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
257 
258  QgsFeatureId fid = f_it->id();
259 
260  if ( filter && !renderer->willRenderFeature( *f_it ) )
261  continue;
262 
263  featureCount++;
264 
265  derivedAttributes.unite( featureDerivedAttributes( &( *f_it ), layer ) );
266 
267  derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : FID_TO_STRING( fid ) );
268 
269  results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
270  }
271 
272  if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
273  {
274  renderer->stopRender( context );
275  }
276 
277  QgsDebugMsg( "Feature count on identify: " + QString::number( featureCount ) );
278 
279  QApplication::restoreOverrideCursor();
280  return featureCount > 0;
281 }
282 
283 QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer )
284 {
285  // Calculate derived attributes and insert:
286  // measure distance or area depending on geometry type
287  QMap< QString, QString > derivedAttributes;
288 
289  // init distance/area calculator
290  QString ellipsoid = QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE );
291  QgsDistanceArea calc;
293  calc.setEllipsoid( ellipsoid );
294  calc.setSourceCrs( layer->crs().srsid() );
295 
297  QGis::GeometryType geometryType = QGis::NoGeometry;
298 
299  if ( feature->geometry() )
300  {
301  geometryType = feature->geometry()->type();
302  wkbType = feature->geometry()->wkbType();
303  }
304 
305  if ( geometryType == QGis::Line )
306  {
307  double dist = calc.measure( feature->geometry() );
308  QGis::UnitType myDisplayUnits;
309  convertMeasurement( calc, dist, myDisplayUnits, false );
310  QString str = calc.textUnit( dist, 3, myDisplayUnits, false ); // dist and myDisplayUnits are out params
311  derivedAttributes.insert( tr( "Length" ), str );
312  if ( wkbType == QGis::WKBLineString || wkbType == QGis::WKBLineString25D )
313  {
314  // Add the start and end points in as derived attributes
315  QgsPoint pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, feature->geometry()->asPolyline().first() );
316  str = QLocale::system().toString( pnt.x(), 'g', 10 );
317  derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
318  str = QLocale::system().toString( pnt.y(), 'g', 10 );
319  derivedAttributes.insert( tr( "firstY" ), str );
320  pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, feature->geometry()->asPolyline().last() );
321  str = QLocale::system().toString( pnt.x(), 'g', 10 );
322  derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
323  str = QLocale::system().toString( pnt.y(), 'g', 10 );
324  derivedAttributes.insert( tr( "lastY" ), str );
325  }
326  }
327  else if ( geometryType == QGis::Polygon )
328  {
329  double area = calc.measure( feature->geometry() );
330  double perimeter = calc.measurePerimeter( feature->geometry() );
331  QGis::UnitType myDisplayUnits;
332  convertMeasurement( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params
333  QString str = calc.textUnit( area, 3, myDisplayUnits, true );
334  derivedAttributes.insert( tr( "Area" ), str );
335  convertMeasurement( calc, perimeter, myDisplayUnits, false ); // perimeter and myDisplayUnits are out params
336  str = calc.textUnit( perimeter, 3, myDisplayUnits, false );
337  derivedAttributes.insert( tr( "Perimeter" ), str );
338  }
339  else if ( geometryType == QGis::Point &&
340  ( wkbType == QGis::WKBPoint || wkbType == QGis::WKBPoint25D ) )
341  {
342  // Include the x and y coordinates of the point as a derived attribute
343  QgsPoint pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, feature->geometry()->asPoint() );
344  QString str = QLocale::system().toString( pnt.x(), 'g', 10 );
345  derivedAttributes.insert( "X", str );
346  str = QLocale::system().toString( pnt.y(), 'g', 10 );
347  derivedAttributes.insert( "Y", str );
348  }
349 
350  return derivedAttributes;
351 }
352 
353 bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel )
354 {
355  QgsDebugMsg( "point = " + point.toString() );
356  if ( !layer )
357  return false;
358 
359  QgsRasterDataProvider *dprovider = layer->dataProvider();
360  int capabilities = dprovider->capabilities();
361  if ( !dprovider || !( capabilities & QgsRasterDataProvider::Identify ) )
362  return false;
363 
364  QgsPoint pointInCanvasCrs = point;
365  try
366  {
367  point = toLayerCoordinates( layer, point );
368  }
369  catch ( QgsCsException &cse )
370  {
371  Q_UNUSED( cse );
372  QgsDebugMsg( QString( "coordinate not reprojectable: %1" ).arg( cse.what() ) );
373  return false;
374  }
375  QgsDebugMsg( QString( "point = %1 %2" ).arg( point.x() ).arg( point.y() ) );
376 
377  if ( !layer->extent().contains( point ) ) return false;
378 
379  QMap< QString, QString > attributes, derivedAttributes;
380 
381  QgsRaster::IdentifyFormat format = QgsRasterDataProvider::identifyFormatFromName( layer->customProperty( "identify/format" ).toString() );
382 
383  // check if the format is really supported otherwise use first supported format
384  if ( !( QgsRasterDataProvider::identifyFormatToCapability( format ) & capabilities ) )
385  {
387  else if ( capabilities & QgsRasterInterface::IdentifyValue ) format = QgsRaster::IdentifyFormatValue;
388  else if ( capabilities & QgsRasterInterface::IdentifyHtml ) format = QgsRaster::IdentifyFormatHtml;
389  else if ( capabilities & QgsRasterInterface::IdentifyText ) format = QgsRaster::IdentifyFormatText;
390  else return false;
391  }
392 
393  QgsRasterIdentifyResult identifyResult;
394  // We can only use current map canvas context (extent, width, height) if layer is not reprojected,
395  if ( mCanvas->hasCrsTransformEnabled() && dprovider->crs() != mCanvas->mapSettings().destinationCrs() )
396  {
397  // To get some reasonable response for point/line WMS vector layers we must
398  // use a context with approximately a resolution in layer CRS units
399  // corresponding to current map canvas resolution (for examplei UMN Mapserver
400  // in msWMSFeatureInfo() -> msQueryByRect() is using requested pixel
401  // + TOLERANCE (layer param) for feature selection)
402  //
403  QgsRectangle r;
404  r.setXMinimum( pointInCanvasCrs.x() - mapUnitsPerPixel / 2. );
405  r.setXMaximum( pointInCanvasCrs.x() + mapUnitsPerPixel / 2. );
406  r.setYMinimum( pointInCanvasCrs.y() - mapUnitsPerPixel / 2. );
407  r.setYMaximum( pointInCanvasCrs.y() + mapUnitsPerPixel / 2. );
408  r = toLayerCoordinates( layer, r ); // will be a bit larger
409  // Mapserver (6.0.3, for example) does not work with 1x1 pixel box
410  // but that is fixed (the rect is enlarged) in the WMS provider
411  identifyResult = dprovider->identify( point, format, r, 1, 1 );
412  }
413  else
414  {
415  // It would be nice to use the same extent and size which was used for drawing,
416  // so that WCS can use cache from last draw, unfortunately QgsRasterLayer::draw()
417  // is doing some tricks with extent and size to allign raster to output which
418  // would be difficult to replicate here.
419  // Note: cutting the extent may result in slightly different x and y resolutions
420  // and thus shifted point calculated back in QGIS WMS (using average resolution)
421  //viewExtent = dprovider->extent().intersect( &viewExtent );
422 
423  // Width and height are calculated from not projected extent and we hope that
424  // are similar to source width and height used to reproject layer for drawing.
425  // TODO: may be very dangerous, because it may result in different resolutions
426  // in source CRS, and WMS server (QGIS server) calcs wrong coor using average resolution.
427  int width = qRound( viewExtent.width() / mapUnitsPerPixel );
428  int height = qRound( viewExtent.height() / mapUnitsPerPixel );
429 
430  QgsDebugMsg( QString( "viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.width() ).arg( viewExtent.height() ) );
431  QgsDebugMsg( QString( "width = %1 height = %2" ).arg( width ).arg( height ) );
432  QgsDebugMsg( QString( "xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.width() / width ).arg( viewExtent.height() / height ).arg( mapUnitsPerPixel ) );
433 
434  identifyResult = dprovider->identify( point, format, viewExtent, width, height );
435  }
436 
437  derivedAttributes.insert( tr( "(clicked coordinate)" ), point.toString() );
438 
439  if ( identifyResult.isValid() )
440  {
441  QMap<int, QVariant> values = identifyResult.results();
442  QgsGeometry geometry;
443  if ( format == QgsRaster::IdentifyFormatValue )
444  {
445  foreach ( int bandNo, values.keys() )
446  {
447  QString valueString;
448  if ( values.value( bandNo ).isNull() )
449  {
450  valueString = tr( "no data" );
451  }
452  else
453  {
454  double value = values.value( bandNo ).toDouble();
455  valueString = QgsRasterBlock::printValue( value );
456  }
457  attributes.insert( dprovider->generateBandName( bandNo ), valueString );
458  }
459  QString label = layer->name();
460  results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
461  }
462  else if ( format == QgsRaster::IdentifyFormatFeature )
463  {
464  foreach ( int i, values.keys() )
465  {
466  QVariant value = values.value( i );
467  if ( value.type() == QVariant::Bool && !value.toBool() )
468  {
469  // sublayer not visible or not queryable
470  continue;
471  }
472 
473  if ( value.type() == QVariant::String )
474  {
475  // error
476  // TODO: better error reporting
477  QString label = layer->subLayers().value( i );
478  attributes.clear();
479  attributes.insert( tr( "Error" ), value.toString() );
480 
481  results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
482  continue;
483  }
484 
485  // list of feature stores for a single sublayer
486  QgsFeatureStoreList featureStoreList = values.value( i ).value<QgsFeatureStoreList>();
487 
488  foreach ( QgsFeatureStore featureStore, featureStoreList )
489  {
490  foreach ( QgsFeature feature, featureStore.features() )
491  {
492  attributes.clear();
493  // WMS sublayer and feature type, a sublayer may contain multiple feature types.
494  // Sublayer name may be the same as layer name and feature type name
495  // may be the same as sublayer. We try to avoid duplicities in label.
496  QString sublayer = featureStore.params().value( "sublayer" ).toString();
497  QString featureType = featureStore.params().value( "featureType" ).toString();
498  // Strip UMN MapServer '_feature'
499  featureType.remove( "_feature" );
500  QStringList labels;
501  if ( sublayer.compare( layer->name(), Qt::CaseInsensitive ) != 0 )
502  {
503  labels << sublayer;
504  }
505  if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
506  {
507  labels << featureType;
508  }
509 
510  QMap< QString, QString > derAttributes = derivedAttributes;
511  derAttributes.unite( featureDerivedAttributes( &feature, layer ) );
512 
513  IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join( " / " ), featureStore.fields(), feature, derAttributes );
514 
515  identifyResult.mParams.insert( "getFeatureInfoUrl", featureStore.params().value( "getFeatureInfoUrl" ) );
516  results->append( identifyResult );
517  }
518  }
519  }
520  }
521  else // text or html
522  {
523  QgsDebugMsg( QString( "%1 html or text values" ).arg( values.size() ) );
524  foreach ( int bandNo, values.keys() )
525  {
526  QString value = values.value( bandNo ).toString();
527  attributes.clear();
528  attributes.insert( "", value );
529 
530  QString label = layer->subLayers().value( bandNo );
531  results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
532  }
533  }
534  }
535  else
536  {
537  attributes.clear();
538  QString value = identifyResult.error().message( QgsErrorMessage::Text );
539  attributes.insert( tr( "Error" ), value );
540  QString label = tr( "Identify error" );
541  results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
542  }
543 
544  return true;
545 }
546 
547 void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea )
548 {
549  // Helper for converting between meters and feet
550  // The parameter &u is out only...
551 
552  // Get the canvas units
553  QGis::UnitType myUnits = mCanvas->mapUnits();
554 
555  calc.convertMeasurement( measure, myUnits, displayUnits(), isArea );
556  u = myUnits;
557 }
558 
559 QGis::UnitType QgsMapToolIdentify::displayUnits()
560 {
561  return mCanvas->mapUnits();
562 }
563 
565 {
566  QgsDebugMsg( "Entered" );
567  QList<IdentifyResult> results;
568  if ( identifyRasterLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel ) )
569  {
570  emit changedRasterResults( results );
571  }
572 }
573 
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.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
QgsMapLayer::LayerType type() const
Get the type of the layer.
Definition: qgsmaplayer.cpp:89
static QString printValue(double value)
Print double value with all necessary significant digits.
static double searchRadiusMU(const QgsRenderContext &context)
Get search radius in map units for given context.
Definition: qgsmaptool.cpp:212
double scale() const
Return the calculated scale of the map.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
void changedRasterResults(QList< IdentifyResult > &)
int layerCount() const
return number of layers on the map
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:163
Use exact geometry intersection (slower) instead of bounding boxes.
void identifyProgress(int, int)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
virtual QgsCoordinateReferenceSystem crs()=0
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QList< QgsFeatureStore > QgsFeatureStoreList
UnitType
Map units that qgis supports.
Definition: qgis.h:229
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:322
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.
Definition: qgsfeature.cpp:112
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
float minimumScale() const
bool hasCrsTransformEnabled()
A simple helper method to find out if on the fly projections are enabled or not.
#define FID_TO_STRING(fid)
Definition: qgsfeature.h:83
virtual void activate()
called when set as currently active map tool
virtual void canvasMoveEvent(QMouseEvent *e)
Overridden mouse move event.
QGis::GeometryType type()
Returns type of the vector.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QList< QgsMapToolIdentify::IdentifyResult > exec(const QList< QgsMapToolIdentify::IdentifyResult > idResults, QPoint pos)
exec
GeometryType
Definition: qgis.h:155
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
WkbType
Used for symbology operations.
Definition: qgis.h:53
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
bool identifyLayer(QList< IdentifyResult > *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType=AllLayers)
call the right method depending on layer type
QgsMapToolIdentify(QgsMapCanvas *canvas)
constructor
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
QMap< int, QVariant > results() const
Get results.
double x() const
Definition: qgspoint.h:126
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void canvasPressEvent(QMouseEvent *e)
Overridden mouse press event.
virtual void stopRender(QgsRenderContext &context)=0
Raster identify results container.
const QString & name() const
Get the display name of the layer.
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:77
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:188
QgsIdentifyMenu * mIdentifyMenu
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.
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:191
QStringList readListEntry(const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const
key value accessors
void formatChanged(QgsRasterLayer *layer)
virtual QStringList subLayers() const
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.
virtual void deactivate()
called when map tool is being deactivated
bool hasScaleBasedVisibility() const
double measurePerimeter(QgsGeometry *geometry)
measures perimeter of polygon
double measure(QgsGeometry *geometry)
general measurement (line distance or polygon area)
float maximumScale() const
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:168
QgsPoint toLayerCoordinates(QgsMapLayer *layer, const QPoint &point)
transformation from screen coordinates to layer's coordinates
Definition: qgsmaptool.cpp:48
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)
Definition: qgspoint.cpp:126
IdentifyFormat
Definition: qgsraster.h:54
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Definition: qgsmaplayer.cpp:95
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.)
void identifyMessage(QString)
The QgsIdentifyMenu class builds a menu to be used with identify results (.
QGis::UnitType mapUnits() const
Get the current canvas map units.
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:93
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.
Definition: qgserror.cpp:50
A class to represent a point.
Definition: qgspoint.h:63
virtual void canvasReleaseEvent(QMouseEvent *e)
Overridden mouse release event.
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)
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
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 ...
QString what() const
Definition: qgsexception.h:35
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.
Definition: qgsrectangle.h:173
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
QList< IdentifyResult > identify(int x, int y, QList< QgsMapLayer * > layerList=QList< QgsMapLayer * >(), IdentifyMode mode=DefaultQgsSetting)
Performs the identification.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
const CORE_EXPORT QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:73
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
bool identifyRasterLayer(QList< IdentifyResult > *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel)
qint64 QgsFeatureId
Definition: qgsfeature.h:30
double y() const
Definition: qgspoint.h:134
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[]
Definition: qgscursors.cpp:135
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:198
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.
Definition: qgsrectangle.h:158
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:203
Base class for raster data providers.
bool identifyVectorLayer(QList< IdentifyResult > *results, QgsVectorLayer *layer, QgsPoint point)
#define tr(sourceText)