diff --git a/src/app/qgsmaptoolidentify.cpp b/src/app/qgsmaptoolidentify.cpp index b8506fb505ab..47e25cc6acba 100644 --- a/src/app/qgsmaptoolidentify.cpp +++ b/src/app/qgsmaptoolidentify.cpp @@ -205,7 +205,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int return false; } - QMap< QString, QString > attributes, derivedAttributes; + QMap< QString, QString > derivedAttributes; QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( x, y ); @@ -259,6 +259,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int calc.setEllipsoid( ellipsoid ); calc.setSourceCrs( layer->crs().srsid() ); } + QgsFeatureList::iterator f_it = featureList.begin(); bool filter = false; @@ -280,8 +281,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int featureCount++; - QMap derivedAttributes; - // Calculate derived attributes and insert: // measure distance or area depending on geometry type if ( layer->geometryType() == QGis::Line ) @@ -295,33 +294,39 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int f_it->geometry()->wkbType() == QGis::WKBLineString25D ) { // Add the start and end points in as derived attributes - str = QLocale::system().toString( f_it->geometry()->asPolyline().first().x(), 'g', 10 ); + QgsPoint pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPolyline().first() ); + 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( f_it->geometry()->asPolyline().first().y(), 'g', 10 ); + str = QLocale::system().toString( pnt.y(), 'g', 10 ); derivedAttributes.insert( tr( "firstY" ), str ); - str = QLocale::system().toString( f_it->geometry()->asPolyline().last().x(), 'g', 10 ); + pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPolyline().last() ); + 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( f_it->geometry()->asPolyline().last().y(), 'g', 10 ); + str = QLocale::system().toString( pnt.y(), 'g', 10 ); derivedAttributes.insert( tr( "lastY" ), str ); } } else if ( layer->geometryType() == QGis::Polygon ) { double area = calc.measure( f_it->geometry() ); + double perimeter = calc.measurePerimeter( f_it->geometry() ); QGis::UnitType myDisplayUnits; convertMeasurement( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params QString str = calc.textUnit( area, 3, myDisplayUnits, true ); derivedAttributes.insert( tr( "Area" ), str ); + convertMeasurement( calc, perimeter, myDisplayUnits, false ); // area and myDisplayUnits are out params + str = calc.textUnit( perimeter, 3, myDisplayUnits, false ); + derivedAttributes.insert( tr( "Perimeter" ), str ); } else if ( layer->geometryType() == QGis::Point && ( f_it->geometry()->wkbType() == QGis::WKBPoint || f_it->geometry()->wkbType() == QGis::WKBPoint25D ) ) { // Include the x and y coordinates of the point as a derived attribute - QString str; - str = QLocale::system().toString( f_it->geometry()->asPoint().x(), 'g', 10 ); + QgsPoint pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPoint() ); + QString str = QLocale::system().toString( pnt.x(), 'g', 10 ); derivedAttributes.insert( "X", str ); - str = QLocale::system().toString( f_it->geometry()->asPoint().y(), 'g', 10 ); + str = QLocale::system().toString( pnt.y(), 'g', 10 ); derivedAttributes.insert( "Y", str ); }