65 , mLastMapUnitsPerPixel( -1.0 )
66 , mCoordinatePrecision( 6 )
98 return identify( x, y, mode, QList<QgsMapLayer *>(), layerType, identifyContext );
108 return identify( geometry, mode, QList<QgsMapLayer *>(), layerType, identifyContext );
113 QList<IdentifyResult> results;
115 mLastGeometry = geometry;
116 mLastExtent =
mCanvas->extent();
117 mLastMapUnitsPerPixel =
mCanvas->mapUnitsPerPixel();
119 mCoordinatePrecision = QgsCoordinateUtils::calculateCoordinatePrecision( mLastMapUnitsPerPixel,
mCanvas->mapSettings().destinationCrs() );
130 int x = canvasPt.x(), y = canvasPt.y();
131 QList<IdentifyResult> results =
identify( x, y,
TopDownAll, layerList, layerType, identifyContext );
132 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
135 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
141 emit
identifyMessage( tr(
"No active layer. To identify features, you must choose an active layer." ) );
147 QApplication::setOverrideCursor( Qt::WaitCursor );
149 identifyLayer( &results,
layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel, layerType, identifyContext );
153 QApplication::setOverrideCursor( Qt::WaitCursor );
155 QList< QgsMapLayer * > targetLayers;
156 if ( layerList.isEmpty() )
157 targetLayers =
mCanvas->layers(
true );
159 targetLayers = layerList;
161 const int layerCount = targetLayers.size();
162 for (
int i = 0; i < layerCount; i++ )
172 if (
identifyLayer( &results,
layer, mLastGeometry, mLastExtent, mLastMapUnitsPerPixel, layerType, identifyContext ) )
183 QApplication::restoreOverrideCursor();
190 mOverrideCanvasSearchRadius = searchRadiusMapUnits;
195 mOverrideCanvasSearchRadius = -1;
217 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>(
layer ), geometry, viewExtent, mapUnitsPerPixel, identifyContext );
229 return identifyVectorTileLayer( results, qobject_cast<QgsVectorTileLayer *>(
layer ), geometry, identifyContext );
233 return identifyPointCloudLayer( results, qobject_cast<QgsPointCloudLayer *>(
layer ), geometry, identifyContext );
258 double searchRadius = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
261 QList<QgsMeshDatasetIndex> datasetIndexList;
262 int activeScalarGroup =
layer->rendererSettings().activeScalarDatasetGroup();
263 int activeVectorGroup =
layer->rendererSettings().activeVectorDatasetGroup();
265 const QList<int> allGroup =
layer->enabledDatasetGroupsIndexes();
268 const QgsDateTimeRange &time = identifyContext.
temporalRange();
269 if ( activeScalarGroup >= 0 )
270 datasetIndexList.append(
layer->activeScalarDatasetAtTime( time ) );
271 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
272 datasetIndexList.append(
layer->activeVectorDatasetAtTime( time ) );
274 for (
int groupIndex : allGroup )
276 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
277 datasetIndexList.append(
layer->datasetIndexAtTime( time, groupIndex ) );
283 if ( activeScalarGroup >= 0 )
284 datasetIndexList.append(
layer->staticScalarDatasetIndex() );
285 if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
286 datasetIndexList.append(
layer->staticVectorDatasetIndex() );
289 for (
int groupIndex : allGroup )
291 if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
293 if ( !
layer->datasetGroupMetadata( groupIndex ).isTemporal() )
294 datasetIndexList.append( groupIndex );
302 if ( !index.isValid() )
306 QMap< QString, QString > derivedAttributes;
308 QMap<QString, QString> attribute;
312 const double scalar = scalarValue.
scalar();
313 attribute.insert( tr(
"Scalar Value" ), std::isnan( scalar ) ? tr(
"no data" ) : QLocale().toString( scalar ) );
319 const double vectorX = vectorValue.
x();
320 const double vectorY = vectorValue.
y();
321 if ( std::isnan( vectorX ) || std::isnan( vectorY ) )
322 attribute.insert( tr(
"Vector Value" ), tr(
"no data" ) );
325 attribute.insert( tr(
"Vector Magnitude" ), QLocale().toString( vectorValue.
scalar() ) );
326 derivedAttributes.insert( tr(
"Vector x-component" ), QLocale().toString( vectorY ) );
327 derivedAttributes.insert( tr(
"Vector y-component" ), QLocale().toString( vectorX ) );
334 derivedAttributes.insert( tr(
"Time Step" ),
layer->formatTime( meta.
time() ) );
335 derivedAttributes.insert( tr(
"Source" ), groupMeta.
uri() );
337 QString resultName = groupMeta.
name();
338 if ( isTemporal && ( index.group() == activeScalarGroup || index.group() == activeVectorGroup ) )
339 resultName.append( tr(
" (active)" ) );
346 results->append( result );
349 QMap<QString, QString> derivedGeometry;
354 derivedGeometry.insert( tr(
"Snapped Vertex Position X" ), QLocale().toString( vertexPoint.
x() ) );
355 derivedGeometry.insert( tr(
"Snapped Vertex Position Y" ), QLocale().toString( vertexPoint.
y() ) );
361 derivedGeometry.insert( tr(
"Face Centroid X" ), QLocale().toString( faceCentroid.
x() ) );
362 derivedGeometry.insert( tr(
"Face Centroid Y" ), QLocale().toString( faceCentroid.
y() ) );
368 derivedGeometry.insert( tr(
"Point on Edge X" ), QLocale().toString( pointOnEdge.
x() ) );
369 derivedGeometry.insert( tr(
"Point on Edge Y" ), QLocale().toString( pointOnEdge.
y() ) );
377 results->append( result );
384 Q_UNUSED( identifyContext )
396 QMap< QString, QString > commonDerivedAttributes;
399 bool isPointOrRectangle;
401 bool isSingleClick = selectionGeom.
type() == Qgis::GeometryType::Point;
404 isPointOrRectangle =
true;
405 point = selectionGeom.
asPoint();
415 int featureCount = 0;
417 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
427 double sr = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
434 if ( !isPointOrRectangle )
445 const int tileZoom =
layer->tileMatrixSet().scaleToZoomLevel(
mCanvas->scale() );
449 for (
int row = tileRange.
startRow(); row <= tileRange.
endRow(); ++row )
454 QByteArray data =
layer->getRawTile( tileID );
455 if ( data.isEmpty() )
459 if ( !decoder.decode( tileID, data ) )
462 QMap<QString, QgsFields> perLayerFields;
463 const QStringList layerNames = decoder.layers();
464 for (
const QString &layerName : layerNames )
466 QSet<QString> fieldNames = qgis::listToSet( decoder.layerFieldNames( layerName ) );
471 const QStringList featuresLayerNames = features.keys();
472 for (
const QString &layerName : featuresLayerNames )
474 const QgsFields fFields = perLayerFields[layerName];
475 const QVector<QgsFeature> &layerFeatures = features[layerName];
478 if ( f.geometry().intersects( r ) && ( !selectionGeomPrepared || selectionGeomPrepared->intersects( f.geometry().constGet() ) ) )
480 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
481 derivedAttributes.insert( tr(
"Feature ID" ),
FID_TO_STRING( f.id() ) );
483 results->
append( IdentifyResult(
layer, layerName, fFields, f, derivedAttributes ) );
497 QgsDebugMsg( QStringLiteral(
"Caught CRS exception %1" ).arg( cse.
what() ) );
500 return featureCount > 0;
505 Q_UNUSED( identifyContext )
511 const double searchRadiusMapUnits = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
513 const QVector<QVariantMap> points = renderer->
identify(
layer, context, geometry, searchRadiusMapUnits );
522 QMap< QString, QString > derivedAttributes;
526 formatCoordinate( point, x, y );
528 derivedAttributes.insert( tr(
"(clicked coordinate X)" ), x );
529 derivedAttributes.insert( tr(
"(clicked coordinate Y)" ), y );
531 derivedAttributes.insert( tr(
"(clicked coordinate Z)" ), QLocale().toString( point.
z(),
'f' ) );
532 return derivedAttributes;
542 QgsDebugMsg( QStringLiteral(
"Out of scale limits" ) );
546 QString temporalFilter;
554 temporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >(
layer->
temporalProperties() )->createFilterString( temporalContext, identifyContext.
temporalRange() );
559 QApplication::setOverrideCursor( Qt::WaitCursor );
561 QMap< QString, QString > commonDerivedAttributes;
564 bool isPointOrRectangle;
566 bool isSingleClick = selectionGeom.
type() == Qgis::GeometryType::Point;
569 isPointOrRectangle =
true;
570 point = *qgsgeometry_cast< const QgsPoint *>( selectionGeom.
constGet() );
581 std::unique_ptr<QgsGeometryEngine> selectionGeomPrepared;
591 double sr = mOverrideCanvasSearchRadius < 0 ?
searchRadiusMU(
mCanvas ) : mOverrideCanvasSearchRadius;
598 if ( !isPointOrRectangle )
612 if ( !temporalFilter.isEmpty() )
619 if ( !selectionGeomPrepared || selectionGeomPrepared->intersects( f.
geometry().
constGet() ) )
627 QgsDebugMsg( QStringLiteral(
"Caught CRS exception %1" ).arg( cse.
what() ) );
635 std::unique_ptr< QgsFeatureRenderer > renderer(
layer->renderer() ?
layer->renderer()->
clone() :
nullptr );
644 if ( !isSingleClick )
647 const int featureCount =
identifyVectorLayer( results,
layer, featureList, filter ? renderer.get() :
nullptr, commonDerivedAttributes,
648 [point,
layer,
this](
const QgsFeature & feature )->QMap< QString, QString >
650 return featureDerivedAttributes( feature, layer, toLayerCoordinates( layer, point ) );
657 QApplication::restoreOverrideCursor();
658 return featureCount > 0;
663 int featureCount = 0;
664 for (
const QgsFeature &feature : std::as_const( features ) )
666 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
674#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
675 derivedAttributes.unite( deriveAttributesForFeature( feature ) );
677 derivedAttributes.insert( deriveAttributesForFeature( feature ) );
680 derivedAttributes.insert( tr(
"Feature ID" ), fid < 0 ? tr(
"new feature" ) :
FID_TO_STRING( fid ) );
682 results->append( IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), feature, derivedAttributes ) );
697 QString
str = QLocale().toString( vId.
vertex + 1 );
698 derivedAttributes.insert( tr(
"Closest vertex number" ),
str );
702 QgsPoint closestPointMapCoords =
mCanvas->mapSettings().layerToMapCoordinates(
layer, closestPoint );
706 formatCoordinate( closestPointMapCoords, x, y );
707 derivedAttributes.insert( tr(
"Closest vertex X" ), x );
708 derivedAttributes.insert( tr(
"Closest vertex Y" ), y );
710 if ( closestPoint.
is3D() )
712 str = QLocale().toString( closestPointMapCoords.
z(),
'g', 10 );
713 derivedAttributes.insert( tr(
"Closest vertex Z" ),
str );
717 str = QLocale().toString( closestPointMapCoords.
m(),
'g', 10 );
718 derivedAttributes.insert( tr(
"Closest vertex M" ),
str );
721 if ( vId.
type == Qgis::VertexType::Curve )
723 double radius, centerX, centerY;
729 geometry.
vertexAt( vIdAfter ), radius, centerX, centerY );
730 derivedAttributes.insert( QStringLiteral(
"Closest vertex radius" ), QLocale().toString( radius ) );
734void QgsMapToolIdentify::closestPointAttributes(
const QgsAbstractGeometry &geometry,
const QgsPointXY &layerPoint, QMap<QString, QString> &derivedAttributes )
740 formatCoordinate( closestPoint, x, y );
741 derivedAttributes.insert( tr(
"Closest X" ), x );
742 derivedAttributes.insert( tr(
"Closest Y" ), y );
744 if ( closestPoint.
is3D() )
746 const QString
str = QLocale().toString( closestPoint.
z(),
'g', 10 );
747 derivedAttributes.insert( tr(
"Interpolated Z" ),
str );
751 const QString
str = QLocale().toString( closestPoint.
m(),
'g', 10 );
752 derivedAttributes.insert( tr(
"Interpolated M" ),
str );
756void QgsMapToolIdentify::formatCoordinate(
const QgsPointXY &canvasPoint, QString &x, QString &y )
const
759 mCoordinatePrecision, x, y );
766 QMap< QString, QString > derivedAttributes;
795 derivedAttributes.insert( tr(
"Parts" ),
str );
798 str = QLocale().toString( vId.
part + 1 );
799 derivedAttributes.insert( tr(
"Part number" ),
str );
804 ? displayDistanceUnits() :
layer->
crs().mapUnits();
808 if ( geometryType == Qgis::GeometryType::Line )
817 str = formatDistance( dist );
818 derivedAttributes.insert( tr(
"Length (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
827 derivedAttributes.insert( tr(
"Length (Cartesian — 2D)" ),
str );
831 return total + qgsgeometry_cast< const QgsLineString * >( part )->length3D();
834 str = formatDistance( totalLength3d, cartesianDistanceUnits );
835 derivedAttributes.insert( tr(
"Length (Cartesian — 3D)" ),
str );
839 derivedAttributes.insert( tr(
"Length (Cartesian)" ),
str );
843 derivedAttributes.insert( tr(
"Vertices" ),
str );
847 closestVertexAttributes( *geom, vId,
layer, derivedAttributes );
848 closestPointAttributes( *geom, layerPoint, derivedAttributes );
851 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom ) )
857 formatCoordinate( pnt, x, y );
858 derivedAttributes.insert( tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), x );
859 derivedAttributes.insert( tr(
"firstY" ), y );
860 pnt =
mCanvas->mapSettings().layerToMapCoordinates(
layer,
QgsPointXY( curve->endPoint().x(), curve->endPoint().y() ) );
861 formatCoordinate( pnt, x, y );
862 derivedAttributes.insert( tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), x );
863 derivedAttributes.insert( tr(
"lastY" ), y );
866 else if ( geometryType == Qgis::GeometryType::Polygon )
873 str = formatArea( area );
874 derivedAttributes.insert( tr(
"Area (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
878 derivedAttributes.insert( tr(
"Area (Cartesian)" ),
str );
884 str = formatDistance( perimeter );
885 derivedAttributes.insert( tr(
"Perimeter (Ellipsoidal — %1)" ).arg( ellipsoid ),
str );
889 derivedAttributes.insert( tr(
"Perimeter (Cartesian)" ),
str );
892 derivedAttributes.insert( tr(
"Vertices" ),
str );
898 closestPointAttributes( *feature.
geometry().
constGet(), layerPoint, derivedAttributes );
901 else if ( geometryType == Qgis::GeometryType::Point )
909 formatCoordinate( pnt, x, y );
910 derivedAttributes.insert( tr(
"X" ), x );
911 derivedAttributes.insert( tr(
"Y" ), y );
916 derivedAttributes.insert( tr(
"Z" ),
str );
921 derivedAttributes.insert( tr(
"M" ),
str );
932 closestVertexAttributes( *geom, vId,
layer, derivedAttributes );
942 return derivedAttributes;
957 std::unique_ptr< QgsRasterDataProvider > dprovider(
layer->
dataProvider()->clone() );
961 int capabilities = dprovider->capabilities();
970 dprovider->temporalCapabilities()->setRequestedTemporalRange( identifyContext.
temporalRange() );
981 QgsDebugMsg( QStringLiteral(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
984 QgsDebugMsg( QStringLiteral(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
989 QMap< QString, QString > attributes, derivedAttributes;
997 format = Qgis::RasterIdentifyFormat::Feature;
999 format = Qgis::RasterIdentifyFormat::Value;
1001 format = Qgis::RasterIdentifyFormat::Html;
1003 format = Qgis::RasterIdentifyFormat::Text;
1009 if ( dprovider->crs() !=
mCanvas->mapSettings().destinationCrs() )
1018 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
1019 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
1020 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
1021 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
1025 identifyResult = dprovider->identify( point, format, r, 1, 1 );
1041 int width =
static_cast< int >( std::round( viewExtent.
width() / mapUnitsPerPixel ) );
1042 int height =
static_cast< int >( std::round( viewExtent.
height() / mapUnitsPerPixel ) );
1044 QgsDebugMsg( QStringLiteral(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
1045 QgsDebugMsg( QStringLiteral(
"width = %1 height = %2" ).arg( width ).arg( height ) );
1046 QgsDebugMsg( QStringLiteral(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
1048 identifyResult = dprovider->identify( point, format, viewExtent, width, height );
1051#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
1057 if ( identifyResult.
isValid() )
1059 QMap<int, QVariant> values = identifyResult.
results();
1061 if ( format == Qgis::RasterIdentifyFormat::Value )
1063 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1065 QString valueString;
1068 valueString = tr(
"no data" );
1072 QVariant value( it.value() );
1076 if (
static_cast<QMetaType::Type
>( value.type() ) == QMetaType::Float )
1085 attributes.insert( dprovider->generateBandName( it.key() ), valueString );
1091 const double doubleValue { it.value().toDouble( &ok ) };
1094 const QVariantList row = rat->row( doubleValue );
1095 if ( ! row.isEmpty() )
1097 for (
int colIdx = 0; colIdx < std::min( rat->fields().count( ), row.count() ); ++colIdx )
1108 switch ( ratField.type )
1110 case QVariant::Type::Char:
1111 case QVariant::Type::Int:
1112 case QVariant::Type::UInt:
1113 case QVariant::Type::LongLong:
1114 case QVariant::Type::ULongLong:
1115 ratValue = QLocale().toString( row.at( colIdx ).toLongLong() );
1117 case QVariant::Type::Double:
1118 ratValue = QLocale().toString( row.at( colIdx ).toDouble( ) );
1121 ratValue = row.at( colIdx ).toString();
1123 attributes.insert( ratField.name, ratValue );
1132 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1134 else if ( format == Qgis::RasterIdentifyFormat::Feature )
1136 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1138 QVariant value = it.value();
1139 if ( value.type() == QVariant::Bool && !value.toBool() )
1145 if ( value.type() == QVariant::String )
1151 attributes.insert( tr(
"Error" ), value.toString() );
1153 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1163 for (
const QgsFeature &feature : storeFeatures )
1169 QString sublayer = featureStore.params().value( QStringLiteral(
"sublayer" ) ).toString();
1170 QString featureType = featureStore.params().value( QStringLiteral(
"featureType" ) ).toString();
1172 featureType.remove( QStringLiteral(
"_feature" ) );
1174 if ( sublayer.compare(
layer->
name(), Qt::CaseInsensitive ) != 0 )
1178 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
1180 labels << featureType;
1183 QMap< QString, QString > derAttributes = derivedAttributes;
1184#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
1190 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>(
layer ), labels.join( QLatin1String(
" / " ) ), featureStore.fields(), feature, derAttributes );
1192 identifyResult.
mParams.insert( QStringLiteral(
"getFeatureInfoUrl" ), featureStore.params().value( QStringLiteral(
"getFeatureInfoUrl" ) ) );
1193 results->append( identifyResult );
1200 QgsDebugMsg( QStringLiteral(
"%1 HTML or text values" ).arg( values.size() ) );
1201 for (
auto it = values.constBegin(); it != values.constEnd(); ++it )
1203 QString value = it.value().toString();
1205 attributes.insert( QString(), value );
1208 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1216 attributes.insert( tr(
"Error" ), value );
1217 QString label = tr(
"Identify error" );
1218 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>(
layer ), label, attributes, derivedAttributes ) );
1234QString QgsMapToolIdentify::formatDistance(
double distance )
const
1236 return formatDistance( distance, displayDistanceUnits() );
1239QString QgsMapToolIdentify::formatArea(
double area )
const
1241 return formatArea( area, displayAreaUnits() );
1244QString QgsMapToolIdentify::formatDistance(
double distance,
Qgis::DistanceUnit unit )
const
1247 bool baseUnit = settings.
value( QStringLiteral(
"qgis/measure/keepbaseunit" ),
true ).toBool();
1252QString QgsMapToolIdentify::formatArea(
double area,
Qgis::AreaUnit unit )
const
1255 bool baseUnit = settings.
value( QStringLiteral(
"qgis/measure/keepbaseunit" ),
true ).toBool();
1262 QList<IdentifyResult> results;
1273 for (
const QVariantMap &pt : identified )
1275 QMap<QString, QString> ptStr;
1276 QString classification;
1277 for (
auto attrIt = pt.constBegin(); attrIt != pt.constEnd(); ++attrIt )
1279 if ( attrIt.key().compare( QLatin1String(
"Z" ), Qt::CaseInsensitive ) == 0
1283 ptStr[ tr(
"Z (original)" ) ] = attrIt.value().toString();
1284 ptStr[ tr(
"Z (adjusted)" ) ] = QString::number( attrIt.value().toDouble() * elevationProps->
zScale() + elevationProps->
zOffset() );
1286 else if ( attrIt.key().compare( QLatin1String(
"Classification" ), Qt::CaseInsensitive ) == 0 )
1289 ptStr[ attrIt.key() ] = QStringLiteral(
"%1 (%2)" ).arg( attrIt.value().toString(), classification );
1293 ptStr[attrIt.key()] = attrIt.value().toString();
1296 QgsMapToolIdentify::IdentifyResult res(
layer, classification.isEmpty() ? QString::number(
id ) : QStringLiteral(
"%1 (%2)" ).arg(
id ).arg( classification ), ptStr, QMap<QString, QString>() );
1297 results.append( res );
1307 if ( identified.empty() )
1312 case Qgis::LayerType::Vector:
1317 QHash< QgsFeatureId, QVariant > featureDistances;
1318 QHash< QgsFeatureId, QVariant > featureElevations;
1321 for (
const QVariantMap &map : identified )
1323 if ( !map.contains( QStringLiteral(
"id" ) ) )
1325 QMap< QString, QString > attributes;
1326 if ( map.value( QStringLiteral(
"distance" ) ).isValid() )
1327 attributes.insert( tr(
"Distance along curve" ), QString::number( map.value( QStringLiteral(
"distance" ) ).toDouble() ) );
1328 if ( map.value( QStringLiteral(
"elevation" ) ).isValid() )
1329 attributes.insert( tr(
"Elevation" ), QString::number( map.value( QStringLiteral(
"elevation" ) ).toDouble() ) );
1335 const QgsFeatureId id = map.value( QStringLiteral(
"id" ) ).toLongLong();
1336 filterIds.insert(
id );
1338 featureDistances.insert(
id, map.value( QStringLiteral(
"distance" ) ) );
1339 featureElevations.insert(
id, map.value( QStringLiteral(
"elevation" ) ) );
1351 identifyVectorLayer( &results, vl, features,
nullptr, QMap< QString, QString >(), [
this, vl, &featureDistances, &featureElevations](
const QgsFeature & feature )->QMap< QString, QString >
1353 QMap< QString, QString > attributes = featureDerivedAttributes( feature, vl,
QgsPointXY() );
1355 if ( featureDistances.value( feature.
id() ).isValid() )
1356 attributes.insert( tr(
"Distance along curve" ), QString::number( featureDistances.value( feature.
id() ).toDouble() ) );
1357 if ( featureElevations.value( feature.
id() ).isValid() )
1358 attributes.insert( tr(
"Elevation" ), QString::number( featureElevations.value( feature.
id() ).toDouble() ) );
1365 case Qgis::LayerType::Raster:
1366 case Qgis::LayerType::Mesh:
1368 for (
const QVariantMap &map : identified )
1370 QMap< QString, QString > attributes;
1371 if ( map.value( QStringLiteral(
"distance" ) ).isValid() )
1372 attributes.insert( tr(
"Distance along curve" ), QString::number( map.value( QStringLiteral(
"distance" ) ).toDouble() ) );
1373 if ( map.value( QStringLiteral(
"elevation" ) ).isValid() )
1374 attributes.insert( tr(
"Elevation" ), QString::number( map.value( QStringLiteral(
"elevation" ) ).toDouble() ) );
1382 case Qgis::LayerType::PointCloud:
1389 case Qgis::LayerType::Plugin:
1390 case Qgis::LayerType::VectorTile:
1391 case Qgis::LayerType::Annotation:
1392 case Qgis::LayerType::Group:
DistanceUnit
Units of distance.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
RasterIdentifyFormat
Raster identify formats.
WkbType
The WKB type describes the number of dimensions a geometry has.
Abstract base class for all geometries.
bool is3D() const SIP_HOLDGIL
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.
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.
Qgis::WkbType wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
const_part_iterator const_parts_begin() const
Returns STL-style iterator pointing to the const first part of the geometry.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
Q_GADGET 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.
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)
@ 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 & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
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.
Container of fields for a vector layer.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
int numGeometries() const SIP_HOLDGIL
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) SIP_HOLDGIL
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.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Qgis::WkbType wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
double area() const
Returns the planar, 2-dimensional area of the geometry.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool isGeosEqual(const QgsGeometry &) const
Compares the geometry with another geometry using GEOS.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
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 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 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.
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
QString toString(int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision.
Point geometry type, with support for z-dimension and m-values.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
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)
Print double value with all necessary significant digits.
static Capability 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.
@ IdentifyValue
Numerical values.
@ Identify
At least one identify format supported.
@ IdentifyFeature
WMS GML -> feature.
Represents a raster layer.
A rectangle specified with double values.
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
bool contains(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle contains other 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.
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.
int endColumn() const
Returns index of the last column in the range.
int endRow() const
Returns index of the last row in the range.
int startRow() const
Returns index of the first row in the range.
int startColumn() const
Returns index of the first column in the range.
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)
Returns true if the specified variant should be considered a NULL value.
@ FeatureSymbology
Provider is able retrieve embedded symbology associated with individual features. Since QGIS 3....
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.
static QgsFields makeQgisFields(const QSet< QString > &flds)
Returns QgsFields instance based on the set of field names.
static bool isMultiType(Qgis::WkbType type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
static bool hasZ(Qgis::WkbType type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
static Qgis::WkbType singleType(Qgis::WkbType type) SIP_HOLDGIL
Returns the single type for a WKB type.
static bool hasM(Qgis::WkbType type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
static Qgis::WkbType flatType(Qgis::WkbType type) SIP_HOLDGIL
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)
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.
Qgis::VertexType type
Vertex type.
bool isValid() const SIP_HOLDGIL
Returns true if the vertex id is valid.