38 #include <QMessageBox>
39 #include <QMouseEvent>
49 QPixmap myIdentifyQPixmap = QPixmap((
const char ** )
identify_cursor );
50 mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
79 return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
84 QList<IdentifyResult> results;
98 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
107 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
111 QApplication::setOverrideCursor( Qt::WaitCursor );
117 QApplication::setOverrideCursor( Qt::WaitCursor );
122 if ( layerList.isEmpty() )
125 layerCount = layerList.count();
128 for (
int i = 0; i < layerCount; i++ )
132 if ( layerList.isEmpty() )
135 layer = layerList.value( i );
140 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
154 QApplication::restoreOverrideCursor();
173 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
198 QMap< QString, QString > commonDerivedAttributes;
200 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
206 if ( identifyValue <= 0.0 )
209 int featureCount = 0;
241 QgsFeatureList::iterator f_it = featureList.begin();
253 for ( ; f_it != featureList.end(); ++f_it )
255 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
266 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
268 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
276 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
278 return featureCount > 0;
285 QMap< QString, QString > derivedAttributes;
308 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
309 derivedAttributes.insert(
tr(
"Length" ), str );
314 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
315 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
316 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
317 derivedAttributes.insert(
tr(
"firstY" ), str );
319 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
320 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
321 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
322 derivedAttributes.insert(
tr(
"lastY" ), str );
331 QString str = calc.
textUnit( area, 3, myDisplayUnits,
true );
332 derivedAttributes.insert(
tr(
"Area" ), str );
334 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
335 derivedAttributes.insert(
tr(
"Perimeter" ), str );
342 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
343 derivedAttributes.insert(
"X", str );
344 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
345 derivedAttributes.insert(
"Y", str );
348 return derivedAttributes;
354 if ( !layer )
return false;
370 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
373 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
377 QMap< QString, QString > attributes, derivedAttributes;
379 QMap<int, QVariant> values;
414 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
415 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
417 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
418 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
419 QgsDebugMsg( QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
421 values = dprovider->
identify( point, format, viewExtent, width, height ).
results();
424 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
430 foreach (
int bandNo, values.keys() )
433 if ( values.value( bandNo ).isNull() )
435 valueString =
tr(
"no data" );
439 double value = values.value( bandNo ).toDouble();
444 QString label = layer->
name();
445 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
449 foreach (
int i, values.keys() )
451 QVariant value = values.value( i );
452 if ( value.type() == QVariant::Bool && !value.toBool() )
458 if ( value.type() == QVariant::String )
462 QString label = layer->
subLayers().value( i );
464 attributes.insert(
tr(
"Error" ), value.toString() );
466 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
481 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
482 QString featureType = featureStore.
params().value(
"featureType" ).toString();
484 featureType.remove(
"_feature" );
486 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
490 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
492 labels << featureType;
497 QMap< QString, QString > derAttributes = derivedAttributes;
500 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join(
" / " ), featureStore.
fields(), feature, derAttributes );
502 identifyResult.
mParams.insert(
"getFeatureInfoUrl", featureStore.
params().value(
"getFeatureInfoUrl" ) );
503 results->append( identifyResult );
510 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
511 foreach (
int bandNo, values.keys() )
513 QString value = values.value( bandNo ).toString();
515 attributes.insert(
"", value );
517 QString label = layer->
subLayers().value( bandNo );
518 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
545 QList<IdentifyResult> results;
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.
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.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
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)
A geometry is the spatial representation of a feature.
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
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.
double measurePerimeter(QgsGeometry *geometry)
measures perimeter of polygon
double measure(QgsGeometry *geometry)
general measurement (line distance or polygon area)
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.
bool hasScaleBasedVisibility()
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.
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
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
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...
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.