@@ -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
@@ -260,6 +260,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
260
260
calc.setEllipsoid ( ellipsoid );
261
261
calc.setSourceCrs ( layer->crs ().srsid () );
262
262
}
263
+
263
264
QgsFeatureList::iterator f_it = featureList.begin ();
264
265
265
266
bool filter = false ;
@@ -281,8 +282,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
281
282
282
283
featureCount++;
283
284
284
- QMap<QString, QString> derivedAttributes;
285
-
286
285
// Calculate derived attributes and insert:
287
286
// measure distance or area depending on geometry type
288
287
if ( layer->geometryType () == QGis::Line )
@@ -296,33 +295,39 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
296
295
f_it->geometry ()->wkbType () == QGis::WKBLineString25D )
297
296
{
298
297
// Add the start and end points in as derived attributes
299
- str = QLocale::system ().toString ( f_it->geometry ()->asPolyline ().first ().x (), ' g' , 10 );
298
+ QgsPoint pnt = mCanvas ->mapRenderer ()->layerToMapCoordinates ( layer, f_it->geometry ()->asPolyline ().first () );
299
+ str = QLocale::system ().toString ( pnt.x (), ' g' , 10 );
300
300
derivedAttributes.insert ( tr ( " firstX" , " attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
301
- str = QLocale::system ().toString ( f_it-> geometry ()-> asPolyline (). first () .y (), ' g' , 10 );
301
+ str = QLocale::system ().toString ( pnt .y (), ' g' , 10 );
302
302
derivedAttributes.insert ( tr ( " firstY" ), str );
303
- str = QLocale::system ().toString ( f_it->geometry ()->asPolyline ().last ().x (), ' g' , 10 );
303
+ pnt = mCanvas ->mapRenderer ()->layerToMapCoordinates ( layer, f_it->geometry ()->asPolyline ().last () );
304
+ str = QLocale::system ().toString ( pnt.x (), ' g' , 10 );
304
305
derivedAttributes.insert ( tr ( " lastX" , " attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
305
- str = QLocale::system ().toString ( f_it-> geometry ()-> asPolyline (). last () .y (), ' g' , 10 );
306
+ str = QLocale::system ().toString ( pnt .y (), ' g' , 10 );
306
307
derivedAttributes.insert ( tr ( " lastY" ), str );
307
308
}
308
309
}
309
310
else if ( layer->geometryType () == QGis::Polygon )
310
311
{
311
312
double area = calc.measure ( f_it->geometry () );
313
+ double perimeter = calc.measurePerimeter ( f_it->geometry () );
312
314
QGis::UnitType myDisplayUnits;
313
315
convertMeasurement ( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params
314
316
QString str = calc.textUnit ( area, 3 , myDisplayUnits, true );
315
317
derivedAttributes.insert ( tr ( " Area" ), str );
318
+ convertMeasurement ( calc, perimeter, myDisplayUnits, false ); // area and myDisplayUnits are out params
319
+ str = calc.textUnit ( perimeter, 3 , myDisplayUnits, false );
320
+ derivedAttributes.insert ( tr ( " Perimeter" ), str );
316
321
}
317
322
else if ( layer->geometryType () == QGis::Point &&
318
323
( f_it->geometry ()->wkbType () == QGis::WKBPoint ||
319
324
f_it->geometry ()->wkbType () == QGis::WKBPoint25D ) )
320
325
{
321
326
// Include the x and y coordinates of the point as a derived attribute
322
- QString str ;
323
- str = QLocale::system ().toString ( f_it-> geometry ()-> asPoint () .x (), ' g' , 10 );
327
+ QgsPoint pnt = mCanvas -> mapRenderer ()-> layerToMapCoordinates ( layer, f_it-> geometry ()-> asPoint () ) ;
328
+ QString str = QLocale::system ().toString ( pnt .x (), ' g' , 10 );
324
329
derivedAttributes.insert ( " X" , str );
325
- str = QLocale::system ().toString ( f_it-> geometry ()-> asPoint () .y (), ' g' , 10 );
330
+ str = QLocale::system ().toString ( pnt .y (), ' g' , 10 );
326
331
derivedAttributes.insert ( " Y" , str );
327
332
}
328
333
0 commit comments