Skip to content

Commit dbd849f

Browse files
committedNov 27, 2012
Merge branch 'identify_improvements'
2 parents a757935 + 4cfdba4 commit dbd849f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed
 

‎src/app/qgsmaptoolidentify.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
205205
return false;
206206
}
207207

208-
QMap< QString, QString > attributes, derivedAttributes;
208+
QMap< QString, QString > derivedAttributes;
209209

210210
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( x, y );
211211

@@ -259,6 +259,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
259259
calc.setEllipsoid( ellipsoid );
260260
calc.setSourceCrs( layer->crs().srsid() );
261261
}
262+
262263
QgsFeatureList::iterator f_it = featureList.begin();
263264

264265
bool filter = false;
@@ -280,8 +281,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
280281

281282
featureCount++;
282283

283-
QMap<QString, QString> derivedAttributes;
284-
285284
// Calculate derived attributes and insert:
286285
// measure distance or area depending on geometry type
287286
if ( layer->geometryType() == QGis::Line )
@@ -295,33 +294,39 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
295294
f_it->geometry()->wkbType() == QGis::WKBLineString25D )
296295
{
297296
// Add the start and end points in as derived attributes
298-
str = QLocale::system().toString( f_it->geometry()->asPolyline().first().x(), 'g', 10 );
297+
QgsPoint pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPolyline().first() );
298+
str = QLocale::system().toString( pnt.x(), 'g', 10 );
299299
derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
300-
str = QLocale::system().toString( f_it->geometry()->asPolyline().first().y(), 'g', 10 );
300+
str = QLocale::system().toString( pnt.y(), 'g', 10 );
301301
derivedAttributes.insert( tr( "firstY" ), str );
302-
str = QLocale::system().toString( f_it->geometry()->asPolyline().last().x(), 'g', 10 );
302+
pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPolyline().last() );
303+
str = QLocale::system().toString( pnt.x(), 'g', 10 );
303304
derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
304-
str = QLocale::system().toString( f_it->geometry()->asPolyline().last().y(), 'g', 10 );
305+
str = QLocale::system().toString( pnt.y(), 'g', 10 );
305306
derivedAttributes.insert( tr( "lastY" ), str );
306307
}
307308
}
308309
else if ( layer->geometryType() == QGis::Polygon )
309310
{
310311
double area = calc.measure( f_it->geometry() );
312+
double perimeter = calc.measurePerimeter( f_it->geometry() );
311313
QGis::UnitType myDisplayUnits;
312314
convertMeasurement( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params
313315
QString str = calc.textUnit( area, 3, myDisplayUnits, true );
314316
derivedAttributes.insert( tr( "Area" ), str );
317+
convertMeasurement( calc, perimeter, myDisplayUnits, false ); // area and myDisplayUnits are out params
318+
str = calc.textUnit( perimeter, 3, myDisplayUnits, false );
319+
derivedAttributes.insert( tr( "Perimeter" ), str );
315320
}
316321
else if ( layer->geometryType() == QGis::Point &&
317322
( f_it->geometry()->wkbType() == QGis::WKBPoint ||
318323
f_it->geometry()->wkbType() == QGis::WKBPoint25D ) )
319324
{
320325
// Include the x and y coordinates of the point as a derived attribute
321-
QString str;
322-
str = QLocale::system().toString( f_it->geometry()->asPoint().x(), 'g', 10 );
326+
QgsPoint pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPoint() );
327+
QString str = QLocale::system().toString( pnt.x(), 'g', 10 );
323328
derivedAttributes.insert( "X", str );
324-
str = QLocale::system().toString( f_it->geometry()->asPoint().y(), 'g', 10 );
329+
str = QLocale::system().toString( pnt.y(), 'g', 10 );
325330
derivedAttributes.insert( "Y", str );
326331
}
327332

0 commit comments

Comments
 (0)
Please sign in to comment.