From 8a339a71e00814cf64e6b8da66f6951effdca7bc Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 22 Nov 2012 12:02:06 +0200 Subject: [PATCH 1/2] add perimeter to derived attributes for polygonal geometries --- src/app/qgsmaptoolidentify.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/qgsmaptoolidentify.cpp b/src/app/qgsmaptoolidentify.cpp index b8506fb505ab..b40194b46a16 100644 --- a/src/app/qgsmaptoolidentify.cpp +++ b/src/app/qgsmaptoolidentify.cpp @@ -308,10 +308,14 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int 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 || From 4cfdba4c26b50e90659fd5f06df470663e80ea19 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 22 Nov 2012 12:32:26 +0200 Subject: [PATCH 2/2] put back to derived attrs clicked coordinates --- src/app/qgsmaptoolidentify.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/qgsmaptoolidentify.cpp b/src/app/qgsmaptoolidentify.cpp index b40194b46a16..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,13 +294,15 @@ 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 ); } } @@ -322,10 +323,10 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int 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 ); }