28#include "moc_qgsmaptoolidentify.cpp"
69 , mLastMapUnitsPerPixel( -1.0 )
70 , mCoordinatePrecision( 6 )
102 return identify( x, y, mode, QList<QgsMapLayer *>(), layerType, identifyContext );
112 return identify( geometry, mode, QList<QgsMapLayer *>(), layerType, identifyContext );
117 QList<IdentifyResult> results;
119 mLastGeometry = geometry;
120 mLastExtent =
mCanvas->extent();
121 mLastMapUnitsPerPixel =
mCanvas->mapUnitsPerPixel();
123 mCoordinatePrecision = QgsCoordinateUtils::calculateCoordinatePrecision( mLastMapUnitsPerPixel,
mCanvas->mapSettings().destinationCrs() );
134 int x = canvasPt.x(), y = canvasPt.y();
135 QList<IdentifyResult> results =
identify( x, y,
TopDownAll, layerList, layerType, identifyContext );
136 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
139 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
145 emit
identifyMessage( tr(
"No active layer. To identify features, you must choose an active layer." ) );
151 QApplication::setOverrideCursor( Qt::WaitCursor );
153 identifyLayer( &results,
layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel, layerType, identifyContext );
157 QApplication::setOverrideCursor( Qt::WaitCursor );
159 QList< QgsMapLayer * > targetLayers;
160 if ( layerList.isEmpty() )
161 targetLayers =
mCanvas->layers(
true );
163 targetLayers = layerList;
165 const int layerCount = targetLayers.size();
166 for (
int i = 0; i < layerCount; i++ )
176 if (
identifyLayer( &results,
layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel, layerType, identifyContext ) )
187 QApplication::restoreOverrideCursor();
194 mOverrideCanvasSearchRadius = searchRadiusMapUnits;
199 mOverrideCanvasSearchRadius = -1;
231 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>(
layer ), geometry, viewExtent, mapUnitsPerPixel, identifyContext );
245 return identifyVectorTileLayer( results, qobject_cast<QgsVectorTileLayer *>(
layer ), geometry, identifyContext );
252 return identifyPointCloudLayer( results, qobject_cast<QgsPointCloudLayer *>(
layer ), geometry, identifyContext );
289 double searchRadius = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
292 QList<QgsMeshDatasetIndex> datasetIndexList;
293 int activeScalarGroup =
layer->rendererSettings().activeScalarDatasetGroup();
294 int activeVectorGroup =
layer->rendererSettings().activeVectorDatasetGroup();
296 const QList<int> allGroup =
layer->enabledDatasetGroupsIndexes();
300 if ( activeScalarGroup >= 0 )
301 datasetIndexList.append(
layer->activeScalarDatasetAtTime( time ) );
302 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
303 datasetIndexList.append(
layer->activeVectorDatasetAtTime( time ) );
305 for (
int groupIndex : allGroup )
307 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
308 datasetIndexList.append(
layer->datasetIndexAtTime( time, groupIndex ) );
314 if ( activeScalarGroup >= 0 )
315 datasetIndexList.append(
layer->staticScalarDatasetIndex() );
316 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
317 datasetIndexList.append(
layer->staticVectorDatasetIndex() );
320 for (
int groupIndex : allGroup )
322 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
324 if ( !
layer->datasetGroupMetadata( groupIndex ).isTemporal() )
325 datasetIndexList.append( groupIndex );
333 if ( !index.isValid() )
337 QMap< QString, QString > derivedAttributes;
339 QMap<QString, QString> attribute;
343 const double scalar = scalarValue.
scalar();
344 attribute.insert( tr(
"Scalar Value" ), std::isnan( scalar ) ? tr(
"no data" ) : QLocale().toString( scalar ) );
350 const double vectorX = vectorValue.
x();
351 const double vectorY = vectorValue.
y();
352 if ( std::isnan( vectorX ) || std::isnan( vectorY ) )
353 attribute.insert( tr(
"Vector Value" ), tr(
"no data" ) );
356 attribute.insert( tr(
"Vector Magnitude" ), QLocale().toString( vectorValue.
scalar() ) );
357 derivedAttributes.insert( tr(
"Vector x-component" ), QLocale().toString( vectorY ) );
358 derivedAttributes.insert( tr(
"Vector y-component" ), QLocale().toString( vectorX ) );
365 derivedAttributes.insert( tr(
"Time Step" ),
layer->formatTime( meta.
time() ) );
366 derivedAttributes.insert( tr(
"Source" ), groupMeta.
uri() );
368 QString resultName = groupMeta.
name();
369 if ( isTemporal && ( index.group() == activeScalarGroup || index.group() == activeVectorGroup ) )
370 resultName.append( tr(
" (active)" ) );
377 results->append( result );
380 QMap<QString, QString> derivedGeometry;
385 derivedGeometry.insert( tr(
"Snapped Vertex Position X" ), QLocale().toString( vertexPoint.
x() ) );
386 derivedGeometry.insert( tr(
"Snapped Vertex Position Y" ), QLocale().toString( vertexPoint.
y() ) );
392 derivedGeometry.insert( tr(
"Face Centroid X" ), QLocale().toString( faceCentroid.
x() ) );
393 derivedGeometry.insert( tr(
"Face Centroid Y" ), QLocale().toString( faceCentroid.
y() ) );
399 derivedGeometry.insert( tr(
"Point on Edge X" ), QLocale().toString( pointOnEdge.
x() ) );
400 derivedGeometry.insert( tr(
"Point on Edge Y" ), QLocale().toString( pointOnEdge.
y() ) );
408 results->append( result );
415 Q_UNUSED( identifyContext )
427 QMap< QString, QString > commonDerivedAttributes;
430 bool isPointOrRectangle;
435 isPointOrRectangle =
true;
436 point = selectionGeom.
asPoint();
446 int featureCount = 0;
448 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
458 double sr = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
465 if ( !isPointOrRectangle )
476 const double tileScale =
layer->tileMatrixSet().calculateTileScaleForMap(
478 mCanvas->mapSettings().destinationCrs(),
479 mCanvas->mapSettings().extent(),
483 const int tileZoom =
layer->tileMatrixSet().scaleToZoomLevel( tileScale );
487 const QVector< QgsTileXYZ> tiles =
layer->tileMatrixSet().tilesInRange( tileRange, tileZoom );
492 if ( data.
data.isEmpty() )
496 if ( !decoder.decode( data ) )
499 QMap<QString, QgsFields> perLayerFields;
500 const QStringList layerNames = decoder.layers();
501 for (
const QString &layerName : layerNames )
503 QSet<QString> fieldNames = qgis::listToSet( decoder.layerFieldNames( layerName ) );
508 const QStringList featuresLayerNames = features.keys();
509 for (
const QString &layerName : featuresLayerNames )
511 const QgsFields fFields = perLayerFields[layerName];
512 const QVector<QgsFeature> &layerFeatures = features[layerName];
515 if ( f.geometry().intersects( r ) && ( !selectionGeomPrepared || selectionGeomPrepared->intersects( f.geometry().constGet() ) ) )
517 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
518 derivedAttributes.insert( tr(
"Feature ID" ),
FID_TO_STRING( f.id() ) );
519 derivedAttributes.insert( tr(
"Tile column" ), QString::number( tileID.column() ) );
520 derivedAttributes.insert( tr(
"Tile row" ), QString::number( tileID.row() ) );
521 derivedAttributes.insert( tr(
"Tile zoom" ), QString::number( tileID.zoomLevel() ) );
523 results->
append( IdentifyResult(
layer, layerName, fFields, f, derivedAttributes ) );
538 return featureCount > 0;
556 const double searchRadiusMapUnits = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
558 const QVector<QVariantMap> points = renderer->
identify(
layer, context, geometry, searchRadiusMapUnits );
567 QMap< QString, QString > derivedAttributes;
571 formatCoordinate( point, x, y );
573 derivedAttributes.insert( tr(
"(clicked coordinate X)" ), x );
574 derivedAttributes.insert( tr(
"(clicked coordinate Y)" ), y );
576 derivedAttributes.insert( tr(
"(clicked coordinate Z)" ), QLocale().toString( point.
z(),
'f' ) );
577 return derivedAttributes;
591 QString temporalFilter;
599 temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >(
layer->
temporalProperties() )->createFilterString( temporalContext, identifyContext.
temporalRange() );
604 QApplication::setOverrideCursor( Qt::WaitCursor );
606 QMap< QString, QString > commonDerivedAttributes;
609 bool isPointOrRectangle;
614 isPointOrRectangle =
true;
615 point = *qgsgeometry_cast< const QgsPoint *>( selectionGeom.
constGet() );
626 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
636 double sr = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
643 if ( !isPointOrRectangle )
657 if ( !temporalFilter.isEmpty() )
664 if ( !selectionGeomPrepared || selectionGeomPrepared->intersects( f.
geometry().
constGet() ) )
680 std::unique_ptr< QgsFeatureRenderer > renderer(
layer->renderer() ?
layer->renderer()->
clone() : nullptr );
689 if ( !isSingleClick )
692 const int featureCount =
identifyVectorLayer( results,
layer, featureList, filter ? renderer.get() : nullptr, commonDerivedAttributes,
693 [point,
layer, this]( const
QgsFeature & feature )->QMap< QString, QString >
702 QApplication::restoreOverrideCursor();
703 return featureCount > 0;
708 int featureCount = 0;
709 for (
const QgsFeature &feature : std::as_const( features ) )
711 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
719 derivedAttributes.insert( deriveAttributesForFeature( feature ) );
720 derivedAttributes.insert( tr(
"Feature ID" ), fid < 0 ? tr(
"new feature" ) :
FID_TO_STRING( fid ) );
722 results->append( IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), feature, derivedAttributes ) );
732 bool showTransformedZ, QMap< QString, QString > &derivedAttributes )
741 QString
str = QLocale().toString( vId.
vertex + 1 );
742 derivedAttributes.insert( tr(
"Closest vertex number" ),
str );
745 QgsPoint closestPointMapCoords = closestPoint;
746 if ( layerToMapTransform.
isValid() )
760 formatCoordinate( closestPointMapCoords, x, y );
761 derivedAttributes.insert( tr(
"Closest vertex X" ), x );
762 derivedAttributes.insert( tr(
"Closest vertex Y" ), y );
764 if ( closestPoint.
is3D() )
766 str = QLocale().toString( closestPoint.
z(),
'g', 10 );
768 : tr(
"Closest vertex Z" ),
str );
770 if ( showTransformedZ && !std::isnan( closestPointMapCoords.
z() ) && !
qgsDoubleNear( closestPoint.
z(), closestPointMapCoords.
z() ) )
772 const QString
str = QLocale().toString( closestPointMapCoords.
z(),
'g', 10 );
778 str = QLocale().toString( closestPointMapCoords.
m(),
'g', 10 );
779 derivedAttributes.insert( tr(
"Closest vertex M" ),
str );
784 double radius, centerX, centerY;
790 geometry.
vertexAt( vIdAfter ), radius, centerX, centerY );
791 derivedAttributes.insert( QStringLiteral(
"Closest vertex radius" ), QLocale().toString( radius ) );
800 bool showTransformedZ,
801 QMap<QString, QString> &derivedAttributes )
804 QgsPoint closestPointMapCrs = closestPoint;
805 if ( layerToMapTransform.
isValid() )
819 formatCoordinate( closestPoint, x, y );
820 derivedAttributes.insert( tr(
"Closest X" ), x );
821 derivedAttributes.insert( tr(
"Closest Y" ), y );
823 if ( closestPoint.
is3D() )
825 const QString
str = QLocale().toString( closestPoint.
z(),
'g', 10 );
827 : tr(
"Interpolated Z" ),
str );
829 if ( showTransformedZ && !std::isnan( closestPointMapCrs.
z() ) && !
qgsDoubleNear( closestPoint.
z(), closestPointMapCrs.
z() ) )
831 const QString
str = QLocale().toString( closestPointMapCrs.
z(),
'g', 10 );
837 const QString
str = QLocale().toString( closestPoint.
m(),
'g', 10 );
838 derivedAttributes.insert( tr(
"Interpolated M" ),
str );
844 QgsCoordinateUtils::formatCoordinatePartsForProject(
QgsProject::instance(), canvasPoint, mapCrs,
845 coordinatePrecision, x, y );
848void QgsMapToolIdentify::formatCoordinate(
const QgsPointXY &canvasPoint, QString &x, QString &y )
const
850 formatCoordinate( canvasPoint, x, y,
mCanvas->mapSettings().destinationCrs(),
851 mCoordinatePrecision );
858 QMap< QString, QString > derivedAttributes;
885 derivedAttributes.insert( tr(
"Parts" ),
str );
888 str = QLocale().toString( vId.
part + 1 );
889 derivedAttributes.insert( tr(
"Part number" ),
str );
894 ? displayDistanceUnits() :
layer->
crs().mapUnits();
909 if ( layerToMapTransform.
isValid() )
932 QgsDebugError( QStringLiteral(
"An error occurred while calculating length" ) );
938 str = formatDistance( dist );
939 derivedAttributes.insert( tr(
"Length (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
942 str = formatDistance( layerCrsGeom->
length()
948 derivedAttributes.insert( tr(
"Length (Cartesian — 2D)" ),
str );
952 return total + qgsgeometry_cast< const QgsLineString * >( part )->length3D();
955 str = formatDistance( totalLength3d, cartesianDistanceUnits );
956 derivedAttributes.insert( tr(
"Length (Cartesian — 3D)" ),
str );
960 derivedAttributes.insert( tr(
"Length (Cartesian)" ),
str );
964 derivedAttributes.insert( tr(
"Vertices" ),
str );
968 closestVertexAttributes( layerToMapTransform, layerVertCrs, mapVertCrs, *layerCrsGeom, vId, showTransformedZ, derivedAttributes );
969 closestPointAttributes( layerToMapTransform, layerVertCrs, mapVertCrs, *layerCrsGeom, layerPoint, showTransformedZ, derivedAttributes );
972 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( layerCrsGeom ) )
978 formatCoordinate( pnt, x, y );
979 derivedAttributes.insert( tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), x );
980 derivedAttributes.insert( tr(
"firstY" ), y );
981 pnt =
mCanvas->mapSettings().layerToMapCoordinates(
layer,
QgsPointXY( curve->endPoint().x(), curve->endPoint().y() ) );
982 formatCoordinate( pnt, x, y );
983 derivedAttributes.insert( tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), x );
984 derivedAttributes.insert( tr(
"lastY" ), y );
998 QgsDebugError( QStringLiteral(
"An error occurred while calculating area" ) );
1004 str = formatArea( area );
1005 derivedAttributes.insert( tr(
"Area (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
1007 str = formatArea( layerCrsGeometry.
area()
1009 derivedAttributes.insert( tr(
"Area (Cartesian)" ),
str );
1013 double perimeter = 0;
1022 QgsDebugError( QStringLiteral(
"An error occurred while calculating perimeter" ) );
1024 str = formatDistance( perimeter );
1025 derivedAttributes.insert( tr(
"Perimeter (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
1029 derivedAttributes.insert( tr(
"Perimeter (Cartesian)" ),
str );
1032 derivedAttributes.insert( tr(
"Vertices" ),
str );
1037 closestVertexAttributes( layerToMapTransform, layerVertCrs, mapVertCrs, *layerCrsGeometry.
constGet(), vId, showTransformedZ, derivedAttributes );
1038 closestPointAttributes( layerToMapTransform, layerVertCrs, mapVertCrs, *layerCrsGeometry.
constGet(), layerPoint, showTransformedZ, derivedAttributes );
1044 if (
const QgsPoint *mapCrsPoint = qgsgeometry_cast< const QgsPoint * >( mapCrsGeometry.
constGet() ) )
1048 formatCoordinate(
QgsPointXY( mapCrsPoint->x(), mapCrsPoint->y() ), x, y );
1049 derivedAttributes.insert( tr(
"X" ), x );
1050 derivedAttributes.insert( tr(
"Y" ), y );
1052 const double originalZ =
QgsWkbTypes::hasZ( wkbType ) ? qgsgeometry_cast<const QgsPoint *>( layerCrsGeometry.
constGet() )->z()
1053 : std::numeric_limits< double >::quiet_NaN();
1054 const double mapCrsZ = mapCrsPoint->is3D() ? mapCrsPoint->z() : std::numeric_limits< double >::quiet_NaN();
1056 if ( !std::isnan( originalZ ) )
1058 const QString
str = QLocale().toString( originalZ,
'g', 10 );
1062 if ( showTransformedZ && !std::isnan( mapCrsZ ) && !
qgsDoubleNear( originalZ, mapCrsZ ) )
1064 const QString
str = QLocale().toString( mapCrsZ,
'g', 10 );
1070 const QString
str = QLocale().toString( qgsgeometry_cast<const QgsPoint *>( layerCrsGeometry.
constGet() )->m(),
'g', 10 );
1071 derivedAttributes.insert( tr(
"M" ),
str );
1081 closestVertexAttributes( layerToMapTransform, layerVertCrs, mapVertCrs, *geom, vId, showTransformedZ, derivedAttributes );
1091 return derivedAttributes;
1106 std::unique_ptr< QgsRasterDataProvider > dprovider(
layer->
dataProvider()->clone() );
1119 dprovider->temporalCapabilities()->setRequestedTemporalRange( identifyContext.
temporalRange() );
1136 QgsDebugError( QStringLiteral(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
1139 QgsDebugMsgLevel( QStringLiteral(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ), 2 );
1144 QMap< QString, QString > attributes, derivedAttributes;
1164 if ( dprovider->crs() !=
mCanvas->mapSettings().destinationCrs() )
1173 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
1174 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
1175 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
1176 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
1180 identifyResult = dprovider->identify( point, format, r, 1, 1 );
1196 int width =
static_cast< int >( std::round( viewExtent.
width() / mapUnitsPerPixel ) );
1197 int height =
static_cast< int >( std::round( viewExtent.
height() / mapUnitsPerPixel ) );
1199 QgsDebugMsgLevel( QStringLiteral(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ), 2 );
1200 QgsDebugMsgLevel( QStringLiteral(
"width = %1 height = %2" ).arg( width ).arg( height ), 2 );
1201 QgsDebugMsgLevel( QStringLiteral(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ), 2 );
1203 identifyResult = dprovider->identify( point, format, viewExtent, width, height );
1214 bool foundMatch =
false;
1215 QMap<int, QVariant> values = identifyResult.
results();
1216 QMap<int, QVariant> filteredValues;
1217 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1223 const double value = it.value().toDouble();
1227 filteredValues.insert( it.key(), it.value() );
1251 const double xres =
layer->rasterUnitsPerPixelX();
1252 const double yres =
layer->rasterUnitsPerPixelY();
1260 const int rasterCol =
static_cast< int >( std::floor( ( point.
x() - extent.
xMinimum() ) / xres ) );
1261 const int rasterRow =
static_cast< int >( std::floor( ( extent.
yMaximum() - point.
y() ) / yres ) );
1263 derivedAttributes.insert( tr(
"Column (0-based)" ), QLocale().toString( rasterCol ) );
1264 derivedAttributes.insert( tr(
"Row (0-based)" ), QLocale().toString( rasterRow ) );
1267 extent.
yMaximum() - ( rasterRow + 1 ) * yres,
1268 ( rasterCol + 1 ) * xres + extent.
xMinimum(),
1269 extent.
yMaximum() - ( rasterRow * yres ) );
1272 if ( identifyResult.
isValid() )
1274 QMap<int, QVariant> values = identifyResult.
results();
1277 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1279 QString valueString;
1282 valueString = tr(
"no data" );
1286 QVariant value( it.value() );
1290 if (
static_cast<QMetaType::Type
>( value.userType() ) == QMetaType::Float )
1299 attributes.insert( dprovider->generateBandName( it.key() ), valueString );
1305 const double doubleValue { it.value().toDouble( &ok ) };
1308 const QVariantList row = rat->row( doubleValue );
1309 if ( ! row.isEmpty() )
1311 for (
int colIdx = 0; colIdx < std::min( rat->fields().count( ), row.count() ); ++colIdx )
1322 switch ( ratField.type )
1324 case QMetaType::Type::QChar:
1325 case QMetaType::Type::Int:
1326 case QMetaType::Type::UInt:
1327 case QMetaType::Type::LongLong:
1328 case QMetaType::Type::ULongLong:
1329 ratValue = QLocale().toString( row.at( colIdx ).toLongLong() );
1331 case QMetaType::Type::Double:
1332 ratValue = QLocale().toString( row.at( colIdx ).toDouble( ) );
1335 ratValue = row.at( colIdx ).toString();
1337 attributes.insert( ratField.name, ratValue );
1347 if ( !pixelRect.
isNull() )
1354 results->append( result );
1358 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1360 QVariant value = it.value();
1361 if ( value.userType() == QMetaType::Type::Bool && !value.toBool() )
1367 if ( value.userType() == QMetaType::Type::QString )
1373 attributes.insert( tr(
"Error" ), value.toString() );
1375 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1385 for (
const QgsFeature &feature : storeFeatures )
1391 QString sublayer = featureStore.params().value( QStringLiteral(
"sublayer" ) ).toString();
1392 QString featureType = featureStore.params().value( QStringLiteral(
"featureType" ) ).toString();
1394 featureType.remove( QStringLiteral(
"_feature" ) );
1396 if ( sublayer.compare(
layer->
name(), Qt::CaseInsensitive ) != 0 )
1400 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
1402 labels << featureType;
1405 QMap< QString, QString > derAttributes = derivedAttributes;
1408 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>(
layer ), labels.join( QLatin1String(
" / " ) ), featureStore.fields(), feature, derAttributes );
1410 identifyResult.
mParams.insert( QStringLiteral(
"getFeatureInfoUrl" ), featureStore.params().value( QStringLiteral(
"getFeatureInfoUrl" ) ) );
1411 results->append( identifyResult );
1418 QgsDebugMsgLevel( QStringLiteral(
"%1 HTML or text values" ).arg( values.size() ), 2 );
1419 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1421 QString value = it.value().toString();
1423 attributes.insert( QString(), value );
1426 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1434 attributes.insert( tr(
"Error" ), value );
1435 QString label = tr(
"Identify error" );
1436 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1452QString QgsMapToolIdentify::formatDistance(
double distance )
const
1454 return formatDistance( distance, displayDistanceUnits() );
1457QString QgsMapToolIdentify::formatArea(
double area )
const
1459 return formatArea( area, displayAreaUnits() );
1462QString QgsMapToolIdentify::formatDistance(
double distance,
Qgis::DistanceUnit unit )
const
1465 bool baseUnit = settings.
value( QStringLiteral(
"qgis/measure/keepbaseunit" ),
true ).toBool();
1470QString QgsMapToolIdentify::formatArea(
double area,
Qgis::AreaUnit unit )
const
1473 bool baseUnit = settings.
value( QStringLiteral(
"qgis/measure/keepbaseunit" ),
true ).toBool();
1480 QList<IdentifyResult> results;
1498 for (
const QVariantMap &pt : identified )
1500 QMap<QString, QString> ptStr;
1501 QString classification;
1502 for (
auto attrIt = pt.constBegin(); attrIt != pt.constEnd(); ++attrIt )
1504 if ( attrIt.key().compare( QLatin1String(
"Z" ), Qt::CaseInsensitive ) == 0
1508 ptStr[ tr(
"Z (original)" ) ] = attrIt.value().toString();
1509 ptStr[ tr(
"Z (adjusted)" ) ] = QString::number( attrIt.value().toDouble() * elevationProps->
zScale() + elevationProps->
zOffset() );
1511 else if ( attrIt.key().compare( QLatin1String(
"Classification" ), Qt::CaseInsensitive ) == 0 )
1514 ptStr[ attrIt.key() ] = QStringLiteral(
"%1 (%2)" ).arg( attrIt.value().toString(), classification );
1518 ptStr[attrIt.key()] = attrIt.value().toString();
1522 QMap< QString, QString > derivedAttributes;
1523 QgsPoint layerPoint( pt.value(
"X" ).toDouble(), pt.value(
"Y" ).toDouble(), pt.value(
"Z" ).toDouble() );
1528 if ( layerToMapTransform.
isValid() )
1543 derivedAttributes.insert( tr(
"X" ), x );
1544 derivedAttributes.insert( tr(
"Y" ), y );
1546 const double originalZ = layerPoint.
z();
1547 const double mapCrsZ = mapCrsPoint.
is3D() ? mapCrsPoint.
z() : std::numeric_limits< double >::quiet_NaN();
1549 if ( !std::isnan( originalZ ) )
1551 const QString
str = QLocale().toString( originalZ,
'g', 10 );
1555 if ( showTransformedZ && !std::isnan( mapCrsZ ) && !
qgsDoubleNear( originalZ, mapCrsZ ) )
1557 const QString
str = QLocale().toString( mapCrsZ,
'g', 10 );
1562 results.append( res );
1572 if ( identified.empty() )
1582 QHash< QgsFeatureId, QVariant > featureDistances;
1583 QHash< QgsFeatureId, QVariant > featureElevations;
1586 for (
const QVariantMap &map : identified )
1588 if ( !map.contains( QStringLiteral(
"id" ) ) )
1590 QMap< QString, QString > attributes;
1591 if ( map.value( QStringLiteral(
"distance" ) ).isValid() )
1592 attributes.insert( tr(
"Distance along curve" ), QString::number( map.value( QStringLiteral(
"distance" ) ).toDouble() ) );
1593 if ( map.value( QStringLiteral(
"elevation" ) ).isValid() )
1594 attributes.insert( tr(
"Elevation" ), QString::number( map.value( QStringLiteral(
"elevation" ) ).toDouble() ) );
1600 const QgsFeatureId id = map.value( QStringLiteral(
"id" ) ).toLongLong();
1601 filterIds.insert(
id );
1603 featureDistances.insert(
id, map.value( QStringLiteral(
"distance" ) ) );
1604 featureElevations.insert(
id, map.value( QStringLiteral(
"elevation" ) ) );
1616 identifyVectorLayer( &results, vl, features,
nullptr, QMap< QString, QString >(), [
this, vl, &featureDistances, &featureElevations](
const QgsFeature & feature )->QMap< QString, QString >
1618 QMap< QString, QString > attributes = featureDerivedAttributes( feature, vl,
QgsPointXY() );
1620 if ( featureDistances.value( feature.
id() ).isValid() )
1621 attributes.insert( tr(
"Distance along curve" ), QString::number( featureDistances.value( feature.
id() ).toDouble() ) );
1622 if ( featureElevations.value( feature.
id() ).isValid() )
1623 attributes.insert( tr(
"Elevation" ), QString::number( featureElevations.value( feature.
id() ).toDouble() ) );
1633 for (
const QVariantMap &map : identified )
1635 QMap< QString, QString > attributes;
1636 if ( map.value( QStringLiteral(
"distance" ) ).isValid() )
1637 attributes.insert( tr(
"Distance along curve" ), QString::number( map.value( QStringLiteral(
"distance" ) ).toDouble() ) );
1638 if ( map.value( QStringLiteral(
"elevation" ) ).isValid() )
1639 attributes.insert( tr(
"Elevation" ), QString::number( map.value( QStringLiteral(
"elevation" ) ).toDouble() ) );
The Qgis class provides global constants for use throughout the application.
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features.
@ MediumString
A medium-length string, recommended for general purpose use.
DistanceUnit
Units of distance.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
@ EmbeddedSymbols
Retrieve any embedded feature symbology.
@ Curve
An intermediate point on a segment defining the curvature of the segment.
QFlags< RasterInterfaceCapability > RasterInterfaceCapabilities
Raster interface capabilities.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
@ IdentifyValue
Numerical values.
@ Identify
At least one identify format supported.
@ IdentifyFeature
WMS GML -> feature.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
RasterIdentifyFormat
Raster identify formats.
@ Feature
WMS GML/JSON -> feature.
@ Value
Numerical pixel value.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Forward
Forward transform (from source to destination)
Abstract base class for all geometries.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary const part after the last part of the geometry.
const_part_iterator const_parts_begin() const
Returns STL-style iterator pointing to the const first part of the geometry.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
@ Identify
Identify: obtain information about the object.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool hasVerticalAxis() const
Returns true if the CRS has a vertical axis.
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
QgsCoordinateReferenceSystem verticalCrs() const
Returns the vertical CRS associated with this CRS object.
Qgis::DistanceUnit mapUnits
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
static QString formatDistance(double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit=false)
Returns an distance formatted as a friendly string.
double measureArea(const QgsGeometry &geometry) const
Measures the area of a geometry.
double convertLengthMeasurement(double length, Qgis::DistanceUnit toUnits) const
Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different d...
double measurePerimeter(const QgsGeometry &geometry) const
Measures the perimeter of a polygon geometry.
double measureLength(const QgsGeometry &geometry) const
Measures the length of a geometry.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
double convertAreaMeasurement(double area, Qgis::AreaUnit toUnits) const
Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different ar...
static QString formatArea(double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string.
QgsRange which stores a range of double values.
bool isInfinite() const
Returns true if the range consists of all possible values.
QString message(QgsErrorMessage::Format format=QgsErrorMessage::Html) const
Full error messages description.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Abstract base class for all 2D vector feature renderers.
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
A container for features with the same fields and crs.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
const QgsSymbol * embeddedSymbol() const
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
int numGeometries() const
Returns the number of geometries within the collection.
static QgsPoint closestPoint(const QgsAbstractGeometry &geometry, const QgsPoint &point)
Returns the nearest point on a segment of a geometry for the specified point.
static void circleCenterRadius(const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, double &radius, double ¢erX, double ¢erY)
Returns radius and center of the circle through pt1, pt2, pt3.
static QgsPoint closestVertex(const QgsAbstractGeometry &geom, const QgsPoint &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
Identify contexts are used to encapsulate the settings to be used to perform an identify action.
bool isTemporal() const
Returns true if the temporal range setting is enabled.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range to be used with the identify action.
QgsDoubleRange zRange() const
Returns the range of z-values to identify within, or an infinite range if no filtering by z should be...
Map canvas is a class for displaying all GIS data types on a canvas.
virtual bool isVisibleInZRange(const QgsDoubleRange &range, QgsMapLayer *layer=nullptr) const
Returns true if the layer should be visible and rendered for the specified z range.
double zScale() const
Returns the z scale, which is a scaling factor which should be applied to z values from the layer.
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
virtual bool isVisibleInTemporalRange(const QgsDateTimeRange &range) const
Returns true if the layer should be visible and rendered for the specified time range.
Base class for all map layer types.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
virtual QgsRectangle extent() const
Returns the extent of the layer.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
QgsCoordinateReferenceSystem crs3D
QgsCoordinateReferenceSystem crs
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
@ Identifiable
If the layer is identifiable using the identify map tool and as a WMS layer.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetValue represents single dataset value.
double y() const
Returns y value.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
double x() const
Returns x value.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
static QMap< int, QString > translatedLasClassificationCodes()
Returns the map of LAS classification code to translated string value, corresponding to the ASPRS Sta...
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Represents a map layer supporting display of point clouds.
Abstract base class for 2d point cloud renderers.
QVector< QVariantMap > identify(QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry, double toleranceForPointIdentification=0)
Returns the list of visible points of the point cloud layer layer and an extent defined by a geometry...
virtual void startRender(QgsPointCloudRenderContext &context)
Must be called when a new render cycle is started.
virtual void stopRender(QgsPointCloudRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
A class to represent a 2D point.
QString toString(int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision.
bool isEmpty() const
Returns true if the geometry is empty.
Point geometry type, with support for z-dimension and m-values.
void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
QgsCoordinateReferenceSystem crs3D() const
Returns the CRS to use for the project when transforming 3D data, or when z/elevation value handling ...
QgsCoordinateReferenceSystem crs
bool overlaps(const QgsRange< T > &other) const
Returns true if this range overlaps another range.
The Field class represents a Raster Attribute Table field, including its name, usage and type.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
static QList< Qgis::RasterAttributeTableFieldUsage > valueAndColorFieldUsages()
Returns the list of field usages for colors and values.
static QString printValue(double value, bool localized=false)
Print double value with all necessary significant digits.
static Qgis::RasterInterfaceCapability identifyFormatToCapability(Qgis::RasterIdentifyFormat format)
Converts a raster identify format to a capability.
static Qgis::RasterIdentifyFormat identifyFormatFromName(const QString &formatName)
Converts a string formatName to a raster identify format.
Raster identify results container.
QgsError error() const
Returns the last error.
bool isValid() const
Returns true if valid.
QMap< int, QVariant > results() const
Returns the identify results.
Raster layer specific subclass of QgsMapLayerElevationProperties.
bool isEnabled() const
Returns true if the elevation properties are enabled, i.e.
QgsDoubleRange elevationRangeForPixelValue(QgsRasterLayer *layer, int band, double pixelValue) const
Returns the elevation range corresponding to a raw pixel value from the specified band.
Represents a raster layer.
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
double width() const
Returns the width of the rectangle.
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
double height() const
Returns the height of the rectangle.
Contains information about the context of a rendering operation.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setZRange(const QgsDoubleRange &range)
Sets the range of z-values which should be rendered.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
static QString symbolTypeToString(Qgis::SymbolType type)
Returns a translated string version of the specified symbol type.
QColor color() const
Returns the symbol's color.
Qgis::SymbolType type() const
Returns the symbol's type.
bool isActive() const
Returns true if the temporal property is active.
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
QgsTileRange tileRangeFromExtent(const QgsRectangle &mExtent) const
Returns tile range that fully covers the given extent.
Range of tiles in a tile matrix to be rendered.
Stores coordinates of a tile in a tile matrix set.
Helper functions for various unit types.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE Qgis::DistanceUnitType unitType(Qgis::DistanceUnit unit)
Returns the type for a distance unit.
static Q_INVOKABLE Qgis::AreaUnit distanceToAreaUnit(Qgis::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding area unit, e.g., meters to square meters.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Encapsulates the context in which a QgsVectorLayer's temporal capabilities will be applied.
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Implements a map layer that is dedicated to rendering of vector tiles.
This class is responsible for decoding raw tile data written with Mapbox Vector Tiles encoding.
Keeps track of raw tile data from one or more sources that need to be decoded.
QMap< QString, QByteArray > data
Raw tile data by source ID.
static QgsFields makeQgisFields(const QSet< QString > &flds)
Returns QgsFields instance based on the set of field names.
static bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
static Qgis::WkbType singleType(Qgis::WkbType type)
Returns the single type for a WKB type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
CONSTLATIN1STRING geoNone()
Constant that holds the string representation for "No ellips/No CRS".
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
#define FID_TO_STRING(fid)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QVector< QgsFeatureStore > QgsFeatureStoreList
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)
const QgsCoordinateReferenceSystem & crs
Utility class for identifying a unique vertex within a geometry.
bool isValid() const
Returns true if the vertex id is valid.
Qgis::VertexType type
Vertex type.