Skip to content
Permalink
Browse files

Fix closest vertex z/m doesn't show in identify tool for multiline

geometries, remove duplicate closest M value attribute
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent ff900c0 commit 6b4b9fe9e3200e011e9e90226c2e6e40dbc98d6d
Showing with 19 additions and 35 deletions.
  1. +19 −30 src/gui/qgsmaptoolidentify.cpp
  2. +0 −5 src/gui/qgsmaptoolidentify.h
@@ -326,18 +326,6 @@ void QgsMapToolIdentify::closestVertexAttributes( const QgsAbstractGeometry &geo
}
}

void QgsMapToolIdentify::closestPointAttributes( const QgsAbstractGeometry &geometry, QgsMapLayer *layer, const QgsPointXY &layerPoint, QMap< QString, QString > &derivedAttributes )
{
Q_UNUSED( layer );
// measure
if ( QgsWkbTypes::hasM( geometry.wkbType() ) )
{
QgsPoint closestPoint = QgsGeometryUtils::closestPoint( geometry, QgsPoint( layerPoint.x(), layerPoint.y() ) );
QString str = QLocale::system().toString( closestPoint.m(), 'g', 10 );
derivedAttributes.insert( QStringLiteral( "Closest point M" ), str );
}
}

QString QgsMapToolIdentify::formatCoordinate( const QgsPointXY &canvasPoint ) const
{
return QgsCoordinateUtils::formatCoordinateForProject( canvasPoint, mCanvas->mapSettings().destinationCrs(),
@@ -396,27 +384,28 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
QString str = formatDistance( dist );
derivedAttributes.insert( tr( "Length" ), str );

const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( feature->geometry().constGet() );
if ( curve )
const QgsAbstractGeometry *geom = feature->geometry().constGet();
if ( geom )
{
str = QLocale::system().toString( curve->nCoordinates() );
str = QLocale::system().toString( geom->nCoordinates() );
derivedAttributes.insert( tr( "Vertices" ), str );

//add details of closest vertex to identify point
closestVertexAttributes( *curve, vId, layer, derivedAttributes );
closestPointAttributes( *curve, layer, layerPoint, derivedAttributes );

// Add the start and end points in as derived attributes
QgsPointXY pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->startPoint().x(), curve->startPoint().y() ) );
str = formatXCoordinate( pnt );
derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
str = formatYCoordinate( pnt );
derivedAttributes.insert( tr( "firstY" ), str );
pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->endPoint().x(), curve->endPoint().y() ) );
str = formatXCoordinate( pnt );
derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
str = formatYCoordinate( pnt );
derivedAttributes.insert( tr( "lastY" ), str );
closestVertexAttributes( *geom, vId, layer, derivedAttributes );

if ( const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom ) )
{
// Add the start and end points in as derived attributes
QgsPointXY pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->startPoint().x(), curve->startPoint().y() ) );
str = formatXCoordinate( pnt );
derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
str = formatYCoordinate( pnt );
derivedAttributes.insert( tr( "firstY" ), str );
pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPointXY( curve->endPoint().x(), curve->endPoint().y() ) );
str = formatXCoordinate( pnt );
derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
str = formatYCoordinate( pnt );
derivedAttributes.insert( tr( "lastY" ), str );
}
}
}
else if ( geometryType == QgsWkbTypes::PolygonGeometry )
@@ -195,11 +195,6 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
*/
void closestVertexAttributes( const QgsAbstractGeometry &geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString > &derivedAttributes );

/**
* Adds details of the closest point to derived attributes
*/
void closestPointAttributes( const QgsAbstractGeometry &geometry, QgsMapLayer *layer, const QgsPointXY &layerPoint, QMap< QString, QString > &derivedAttributes );

QString formatCoordinate( const QgsPointXY &canvasPoint ) const;
QString formatXCoordinate( const QgsPointXY &canvasPoint ) const;
QString formatYCoordinate( const QgsPointXY &canvasPoint ) const;

0 comments on commit 6b4b9fe

Please sign in to comment.
You can’t perform that action at this time.