Skip to content

Commit

Permalink
Fix closest vertex z/m doesn't show in identify tool for multiline
Browse files Browse the repository at this point in the history
geometries, remove duplicate closest M value attribute
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent ff900c0 commit 6b4b9fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
49 changes: 19 additions & 30 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 )
Expand Down
5 changes: 0 additions & 5 deletions src/gui/qgsmaptoolidentify.h
Expand Up @@ -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;
Expand Down

0 comments on commit 6b4b9fe

Please sign in to comment.