Skip to content

Commit

Permalink
Correct vertex count when using identify tool on curved lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 22, 2015
1 parent 06553db commit 2963408
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -37,6 +37,7 @@
#include "qgsrendererv2.h"
#include "qgsgeometryutils.h"
#include "qgsgeometrycollectionv2.h"
#include "qgscurvev2.h"

#include <QSettings>
#include <QMouseEvent>
Expand Down Expand Up @@ -346,27 +347,28 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur

if ( geometryType == QGis::Line )
{
const QgsPolyline &pline = feature->constGeometry()->asPolyline();
double dist = calc.measureLength( feature->constGeometry() );
QGis::UnitType myDisplayUnits;
convertMeasurement( calc, dist, myDisplayUnits, false );
QString str = calc.textUnit( dist, 3, myDisplayUnits, false ); // dist and myDisplayUnits are out params
derivedAttributes.insert( tr( "Length" ), str );
str = QLocale::system().toString( pline.size() );
derivedAttributes.insert( tr( "Vertices" ), str );

//add details of closest vertex to identify point
closestVertexAttributes( *feature->constGeometry()->geometry(), vId, layer, derivedAttributes );

if ( QgsWKBTypes::flatType( wkbType ) == QgsWKBTypes::LineString )
const QgsCurveV2* curve = dynamic_cast< const QgsCurveV2* >( feature->constGeometry()->geometry() );
if ( curve )
{
str = QLocale::system().toString( curve->nCoordinates() );
derivedAttributes.insert( tr( "Vertices" ), str );

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

// Add the start and end points in as derived attributes
QgsPoint pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, pline.first() );
QgsPoint pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPoint( curve->startPoint().x(), curve->startPoint().y() ) );
str = QLocale::system().toString( pnt.x(), 'g', 10 );
derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
str = QLocale::system().toString( pnt.y(), 'g', 10 );
derivedAttributes.insert( tr( "firstY" ), str );
pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, pline.last() );
pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPoint( curve->endPoint().x(), curve->endPoint().y() ) );
str = QLocale::system().toString( pnt.x(), 'g', 10 );
derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
str = QLocale::system().toString( pnt.y(), 'g', 10 );
Expand Down

0 comments on commit 2963408

Please sign in to comment.