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