Skip to content

Commit

Permalink
Merge branch 'identify_improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Nov 27, 2012
2 parents a757935 + 4cfdba4 commit dbd849f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/app/qgsmaptoolidentify.cpp
Expand Up @@ -205,7 +205,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
return false; return false;
} }


QMap< QString, QString > attributes, derivedAttributes; QMap< QString, QString > derivedAttributes;


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


Expand Down Expand Up @@ -259,6 +259,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
calc.setEllipsoid( ellipsoid ); calc.setEllipsoid( ellipsoid );
calc.setSourceCrs( layer->crs().srsid() ); calc.setSourceCrs( layer->crs().srsid() );
} }

QgsFeatureList::iterator f_it = featureList.begin(); QgsFeatureList::iterator f_it = featureList.begin();


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


featureCount++; featureCount++;


QMap<QString, QString> derivedAttributes;

// Calculate derived attributes and insert: // Calculate derived attributes and insert:
// measure distance or area depending on geometry type // measure distance or area depending on geometry type
if ( layer->geometryType() == QGis::Line ) if ( layer->geometryType() == QGis::Line )
Expand All @@ -295,33 +294,39 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
f_it->geometry()->wkbType() == QGis::WKBLineString25D ) f_it->geometry()->wkbType() == QGis::WKBLineString25D )
{ {
// Add the start and end points in as derived attributes // 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 ); 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 ); 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 ); 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 ); derivedAttributes.insert( tr( "lastY" ), str );
} }
} }
else if ( layer->geometryType() == QGis::Polygon ) else if ( layer->geometryType() == QGis::Polygon )
{ {
double area = calc.measure( f_it->geometry() ); double area = calc.measure( f_it->geometry() );
double perimeter = calc.measurePerimeter( f_it->geometry() );
QGis::UnitType myDisplayUnits; QGis::UnitType myDisplayUnits;
convertMeasurement( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params convertMeasurement( calc, area, myDisplayUnits, true ); // area and myDisplayUnits are out params
QString str = calc.textUnit( area, 3, myDisplayUnits, true ); QString str = calc.textUnit( area, 3, myDisplayUnits, true );
derivedAttributes.insert( tr( "Area" ), str ); 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 && else if ( layer->geometryType() == QGis::Point &&
( f_it->geometry()->wkbType() == QGis::WKBPoint || ( f_it->geometry()->wkbType() == QGis::WKBPoint ||
f_it->geometry()->wkbType() == QGis::WKBPoint25D ) ) f_it->geometry()->wkbType() == QGis::WKBPoint25D ) )
{ {
// Include the x and y coordinates of the point as a derived attribute // Include the x and y coordinates of the point as a derived attribute
QString str; QgsPoint pnt = mCanvas->mapRenderer()->layerToMapCoordinates( layer, f_it->geometry()->asPoint() );
str = QLocale::system().toString( f_it->geometry()->asPoint().x(), 'g', 10 ); QString str = QLocale::system().toString( pnt.x(), 'g', 10 );
derivedAttributes.insert( "X", str ); 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 ); derivedAttributes.insert( "Y", str );
} }


Expand Down

0 comments on commit dbd849f

Please sign in to comment.