40 #include <QMessageBox>
41 #include <QMouseEvent>
52 QPixmap myIdentifyQPixmap = QPixmap((
const char ** )
identify_cursor );
53 mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
82 return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
87 QList<IdentifyResult> results;
101 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
109 QList<IdentifyResult>::const_iterator it = idResult.constBegin();
110 for ( ; it != idResult.constEnd(); ++it )
124 QMenu layerSelectionMenu;
125 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator resultIt =
mLayerIdResults.constBegin();
128 QAction*
action =
new QAction( resultIt.key()->name(), 0 );
129 action->setData( resultIt.key()->id() );
153 QObject::connect( action, SIGNAL( hovered() ),
this, SLOT(
handleMenuHover() ) );
154 layerSelectionMenu.addAction( action );
158 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
159 QAction* selectedAction = layerSelectionMenu.exec( globalPos );
160 if ( selectedAction )
163 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator sIt =
mLayerIdResults.find( selectedLayer );
166 results = sIt.value();
172 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
178 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
182 QApplication::setOverrideCursor( Qt::WaitCursor );
188 QApplication::setOverrideCursor( Qt::WaitCursor );
193 if ( layerList.isEmpty() )
196 layerCount = layerList.count();
199 for (
int i = 0; i < layerCount; i++ )
203 if ( layerList.isEmpty() )
206 layer = layerList.value( i );
211 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
225 QApplication::restoreOverrideCursor();
244 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
269 QMap< QString, QString > commonDerivedAttributes;
271 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
277 if ( identifyValue <= 0.0 )
280 int featureCount = 0;
312 QgsFeatureList::iterator f_it = featureList.begin();
324 for ( ; f_it != featureList.end(); ++f_it )
326 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
337 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
339 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
347 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
349 return featureCount > 0;
356 QMap< QString, QString > derivedAttributes;
379 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
380 derivedAttributes.insert(
tr(
"Length" ), str );
385 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
386 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
387 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
388 derivedAttributes.insert(
tr(
"firstY" ), str );
390 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
391 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
392 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
393 derivedAttributes.insert(
tr(
"lastY" ), str );
402 QString str = calc.
textUnit( area, 3, myDisplayUnits,
true );
403 derivedAttributes.insert(
tr(
"Area" ), str );
405 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
406 derivedAttributes.insert(
tr(
"Perimeter" ), str );
413 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
414 derivedAttributes.insert(
"X", str );
415 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
416 derivedAttributes.insert(
"Y", str );
419 return derivedAttributes;
425 if ( !layer )
return false;
442 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
445 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
449 QMap< QString, QString > attributes, derivedAttributes;
474 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
475 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
476 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
477 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
481 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
497 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
498 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
500 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
501 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
502 QgsDebugMsg( QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
504 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
507 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
509 if ( identifyResult.
isValid() )
511 QMap<int, QVariant> values = identifyResult.
results();
515 foreach (
int bandNo, values.keys() )
518 if ( values.value( bandNo ).isNull() )
520 valueString =
tr(
"no data" );
524 double value = values.value( bandNo ).toDouble();
529 QString label = layer->
name();
530 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
534 foreach (
int i, values.keys() )
536 QVariant value = values.value( i );
537 if ( value.type() == QVariant::Bool && !value.toBool() )
543 if ( value.type() == QVariant::String )
547 QString label = layer->
subLayers().value( i );
549 attributes.insert(
tr(
"Error" ), value.toString() );
551 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
566 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
567 QString featureType = featureStore.
params().value(
"featureType" ).toString();
569 featureType.remove(
"_feature" );
571 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
575 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
577 labels << featureType;
582 QMap< QString, QString > derAttributes = derivedAttributes;
585 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join(
" / " ), featureStore.
fields(), feature, derAttributes );
587 identifyResult.
mParams.insert(
"getFeatureInfoUrl", featureStore.
params().value(
"getFeatureInfoUrl" ) );
588 results->append( identifyResult );
595 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
596 foreach (
int bandNo, values.keys() )
598 QString value = values.value( bandNo ).toString();
600 attributes.insert(
"", value );
602 QString label = layer->
subLayers().value( bandNo );
603 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
611 attributes.insert(
tr(
"Error" ), value );
612 QString label =
tr(
"Identify error" );
613 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
639 QList<IdentifyResult> results;
654 QAction* senderAction = qobject_cast<QAction*>( sender() );
660 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator lIt =
mLayerIdResults.find( vl );
663 const QList<IdentifyResult>& idList = lIt.value();
664 QList<IdentifyResult>::const_iterator idListIt = idList.constBegin();
665 for ( ; idListIt != idList.constEnd(); ++idListIt )
668 hl->
setColor( QColor( 255, 0, 0 ) );
679 QList<QgsHighlight*>::const_iterator it =
mRubberBands.constBegin();
bool isValid() const
Returns true if valid.
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QString, QVariant > mParams
Additional params (e.g.
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.
QgsMapLayer::LayerType type() const
Get the type of the layer.
static QString printValue(double value)
Print double value with all necessary significant digits.
QgsRenderContext * rendererContext()
Accessor for render context.
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.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
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
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()
Returns type of the vector.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
WkbType
Used for symbology operations.
static const double DEFAULT_IDENTIFY_RADIUS
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.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point)
transform point coordinates from layer's CRS to output CRS
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
virtual QStringList subLayers() const
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.
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.
double scale() const
Scale denominator.
A class for highlight features on the map.
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::GeometryType geometryType() const
Returns point, line or polygon.
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 geometry.
bool isDrawing()
true if canvas currently drawing
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 ...
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void setColor(const QColor &color)
void setYMaximum(double y)
Set the maximum y value.
static QgsProject * instance()
access to canonical QgsProject instance
QgsMapRenderer * mapRenderer()
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.
virtual void startRender(QgsRenderContext &context, const QgsVectorLayer *vlayer)=0
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
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 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.
void setWidth(int width)
Set width.