@@ -205,7 +205,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
205
205
return false ;
206
206
}
207
207
208
- QMap< QString, QString > attributes, derivedAttributes;
208
+ QMap< QString, QString > derivedAttributes;
209
209
210
210
QgsPoint point = mCanvas ->getCoordinateTransform ()->toMapCoordinates ( x, y );
211
211
@@ -259,6 +259,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
259
259
calc.setEllipsoid ( ellipsoid );
260
260
calc.setSourceCrs ( layer->crs ().srsid () );
261
261
}
262
+
262
263
QgsFeatureList::iterator f_it = featureList.begin ();
263
264
264
265
bool filter = false ;
@@ -280,8 +281,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
280
281
281
282
featureCount++;
282
283
283
- QMap<QString, QString> derivedAttributes;
284
-
285
284
// Calculate derived attributes and insert:
286
285
// measure distance or area depending on geometry type
287
286
if ( layer->geometryType () == QGis::Line )
@@ -295,33 +294,39 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
295
294
f_it->geometry ()->wkbType () == QGis::WKBLineString25D )
296
295
{
297
296
// 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 );
299
299
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 );
301
301
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 );
303
304
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 );
305
306
derivedAttributes.insert ( tr ( " lastY" ), str );
306
307
}
307
308
}
308
309
else if ( layer->geometryType () == QGis::Polygon )
309
310
{
310
311
double area = calc.measure ( f_it->geometry () );
312
+ double perimeter = calc.measurePerimeter ( f_it->geometry () );
311
313
QGis::UnitType myDisplayUnits;
312
314
convertMeasurement ( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params
313
315
QString str = calc.textUnit ( area, 3 , myDisplayUnits, true );
314
316
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 );
315
320
}
316
321
else if ( layer->geometryType () == QGis::Point &&
317
322
( f_it->geometry ()->wkbType () == QGis::WKBPoint ||
318
323
f_it->geometry ()->wkbType () == QGis::WKBPoint25D ) )
319
324
{
320
325
// 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 );
323
328
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 );
325
330
derivedAttributes.insert ( " Y" , str );
326
331
}
327
332
0 commit comments