Skip to content
Permalink
Browse files

[needs-docs] Don't restrict project ellipsoid choice when

canvas OTF reprojection is disabled

These two settings aren't necessarily related - you may want
to disable OTF canvas reprojection while still wanting accurate
distance/area measurements using an ellipsoid.

This change should make distance/area calculation in QGIS more
reliable and predictable for users. Calculations are now
based entirely on the ellipsoid choice in project properties, so
it only takes checking a single setting to verify how
measurements are calculated.
  • Loading branch information
nyalldawson committed Jan 14, 2017
1 parent 7d2cd37 commit 24c990f15f5b87b8af865f3fec6681e63ca522f7
@@ -7513,7 +7513,7 @@ void QgisApp::selectByForm()
QgsDistanceArea myDa;

myDa.setSourceCrs( vlayer->crs().srsid() );
myDa.setEllipsoidalMode( mMapCanvas->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );

QgsAttributeEditorContext context;
@@ -699,7 +699,7 @@ QgsAttributeDialog* QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeat
QgsDistanceArea myDa;

myDa.setSourceCrs( l->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );

QgsAttributeEditorContext context;
@@ -200,7 +200,7 @@ void QgsAttributeActionPropertiesDialog::init( const QSet<QString>& actionScopes

QgsDistanceArea myDa;
myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );

mFieldExpression->setLayer( mLayer );
@@ -126,7 +126,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
myDa = new QgsDistanceArea();

myDa->setSourceCrs( mLayer->crs() );
myDa->setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa->setEllipsoidalMode( true );
myDa->setEllipsoid( QgsProject::instance()->ellipsoid() );

mEditorContext.setDistanceArea( *myDa );
@@ -587,7 +587,7 @@ void QgsAttributeTableDialog::filterExpressionBuilder()

QgsDistanceArea myDa;
myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
dlg.setGeomCalculator( myDa );

@@ -948,7 +948,7 @@ void QgsAttributeTableDialog::setFilterExpression( const QString& filterString,
QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );

// parse search string and build parsed tree
@@ -177,7 +177,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mSizeFieldExpressionWidget->setLayer( mLayer );
QgsDistanceArea myDa;
myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( mMapCanvas->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
mSizeFieldExpressionWidget->setGeomCalculator( myDa );

@@ -869,7 +869,7 @@ QString QgsDiagramProperties::showExpressionBuilder( const QString& initialExpre

QgsDistanceArea myDa;
myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( mMapCanvas->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
dlg.setGeomCalculator( myDa );

@@ -57,7 +57,7 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );

context.setDistanceArea( myDa );
@@ -56,7 +56,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl, QWidget* parent )

QgsDistanceArea myDa;
myDa.setSourceCrs( vl->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
builder->setGeomCalculator( myDa );

@@ -156,7 +156,7 @@ void QgsFieldCalculator::accept()
QgsDistanceArea myDa;

myDa.setSourceCrs( mVectorLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( true );
myDa.setEllipsoid( QgsProject::instance()->ellipsoid() );

QString calcString = builder->expressionText();
@@ -94,7 +94,7 @@ void QgsLabelingGui::setLayer( QgsMapLayer* mapLayer )
mFieldExpressionWidget->setLayer( mLayer );
QgsDistanceArea da;
da.setSourceCrs( mLayer->crs().srsid() );
da.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
da.setEllipsoidalMode( true );
da.setEllipsoid( QgsProject::instance()->ellipsoid() );
mFieldExpressionWidget->setGeomCalculator( da );

@@ -184,6 +184,5 @@ void QgsMapToolMeasureAngle::configureDistanceArea()
QString ellipsoidId = QgsProject::instance()->ellipsoid();
mDa.setSourceCrs( mCanvas->mapSettings().destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
// Only use ellipsoidal calculation when project wide transformation is enabled.
mDa.setEllipsoidalMode( mCanvas->mapSettings().hasCrsTransformEnabled() );
mDa.setEllipsoidalMode( true );
}
@@ -80,15 +80,7 @@ void QgsMeasureDialog::updateSettings()
mAreaUnits = QgsProject::instance()->areaUnits();
mDa.setSourceCrs( mTool->canvas()->mapSettings().destinationCrs().srsid() );
mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
// Only use ellipsoidal calculation when project wide transformation is enabled.
if ( mTool->canvas()->mapSettings().hasCrsTransformEnabled() )
{
mDa.setEllipsoidalMode( true );
}
else
{
mDa.setEllipsoidalMode( false );
}
mDa.setEllipsoidalMode( true );

QgsDebugMsg( "****************" );
QgsDebugMsg( QString( "Ellipsoid ID : %1" ).arg( mDa.ellipsoid() ) );
@@ -301,33 +293,21 @@ void QgsMeasureDialog::updateUi()
else
{
QgsUnitTypes::AreaUnit resultUnit = QgsUnitTypes::AreaUnknownUnit;
if ( ! mTool->canvas()->hasCrsTransformEnabled() )
if ( mDa.willUseEllipsoid() )
{
resultUnit = QgsUnitTypes::distanceToAreaUnit( mTool->canvas()->mapSettings().destinationCrs().mapUnits() );
toolTip += "<br> * " + tr( "Project CRS transformation is turned off." ) + ' ';
toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mTool->canvas()->mapSettings().destinationCrs().description() );
toolTip += "<br> * " + tr( "Ellipsoidal calculation is not possible with CRS transformation disabled." );
setWindowTitle( tr( "Measure (OTF off)" ) );
resultUnit = QgsUnitTypes::AreaSquareMeters;
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is selected." ) + ' ';
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the area is calculated in %2." ).arg( mDa.ellipsoid(),
QgsUnitTypes::toString( resultUnit ) );
}
else
{
if ( mDa.willUseEllipsoid() )
{
resultUnit = QgsUnitTypes::AreaSquareMeters;
toolTip += "<br> * " + tr( "Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + ' ';
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the area is calculated in %2." ).arg( mDa.ellipsoid(),
QgsUnitTypes::toString( resultUnit ) );
}
else
{
resultUnit = QgsUnitTypes::distanceToAreaUnit( mTool->canvas()->mapSettings().destinationCrs().mapUnits() );
toolTip += "<br> * " + tr( "Project CRS transformation is turned on but ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mTool->canvas()->mapSettings().destinationCrs().description() );
}
setWindowTitle( tr( "Measure (OTF on)" ) );
resultUnit = QgsUnitTypes::distanceToAreaUnit( mTool->canvas()->mapSettings().destinationCrs().mapUnits() );
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mTool->canvas()->mapSettings().destinationCrs().description() );
}
setWindowTitle( tr( "Measure (OTF on)" ) );

if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Geographic &&
QgsUnitTypes::unitType( mAreaUnits ) == QgsUnitTypes::Standard )
@@ -375,33 +355,21 @@ void QgsMeasureDialog::updateUi()
else
{
QgsUnitTypes::DistanceUnit resultUnit = QgsUnitTypes::DistanceUnknownUnit;
if ( ! mTool->canvas()->hasCrsTransformEnabled() )
if ( mDa.willUseEllipsoid() )
{
resultUnit = mTool->canvas()->mapSettings().destinationCrs().mapUnits();
toolTip += "<br> * " + tr( "Project CRS transformation is turned off." ) + ' ';
toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mTool->canvas()->mapSettings().destinationCrs().description() );
toolTip += "<br> * " + tr( "Ellipsoidal calculation is not possible with CRS transformation disabled." );
setWindowTitle( tr( "Measure (OTF off)" ) );
resultUnit = QgsUnitTypes::DistanceMeters;
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is selected." ) + ' ';
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the distance is calculated in %2." ).arg( mDa.ellipsoid(),
QgsUnitTypes::toString( resultUnit ) );
}
else
{
if ( mDa.willUseEllipsoid() )
{
resultUnit = QgsUnitTypes::DistanceMeters;
toolTip += "<br> * " + tr( "Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + ' ';
toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the distance is calculated in %2." ).arg( mDa.ellipsoid(),
QgsUnitTypes::toString( resultUnit ) );
}
else
{
resultUnit = mTool->canvas()->mapSettings().destinationCrs().mapUnits();
toolTip += "<br> * " + tr( "Project CRS transformation is turned on but ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mTool->canvas()->mapSettings().destinationCrs().description() );
}
setWindowTitle( tr( "Measure (OTF on)" ) );
resultUnit = mTool->canvas()->mapSettings().destinationCrs().mapUnits();
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mTool->canvas()->mapSettings().destinationCrs().description() );
}
setWindowTitle( tr( "Measure (OTF on)" ) );

if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Geographic &&
QgsUnitTypes::unitType( mDistanceUnits ) == QgsUnitTypes::Standard )
@@ -1967,31 +1967,25 @@ void QgsProjectProperties::updateEllipsoidUI( int newIndex )
leSemiMinor->setEnabled( false );
leSemiMajor->setText( QLatin1String( "" ) );
leSemiMinor->setText( QLatin1String( "" ) );
if ( cbxProjectionEnabled->isChecked() )

cmbEllipsoid->setEnabled( true );
cmbEllipsoid->setToolTip( QLatin1String( "" ) );
if ( mEllipsoidList.at( mEllipsoidIndex ).acronym.startsWith( QLatin1String( "PARAMETER:" ) ) )
{
cmbEllipsoid->setEnabled( true );
cmbEllipsoid->setToolTip( QLatin1String( "" ) );
if ( mEllipsoidList.at( mEllipsoidIndex ).acronym.startsWith( QLatin1String( "PARAMETER:" ) ) )
{
leSemiMajor->setEnabled( true );
leSemiMinor->setEnabled( true );
}
else
{
leSemiMajor->setToolTip( tr( "Select %1 from pull-down menu to adjust radii" ).arg( tr( "Parameters:" ) ) );
leSemiMinor->setToolTip( tr( "Select %1 from pull-down menu to adjust radii" ).arg( tr( "Parameters:" ) ) );
}
if ( mEllipsoidList[ mEllipsoidIndex ].acronym != GEO_NONE )
{
leSemiMajor->setText( QLocale::system().toString( myMajor, 'f', 3 ) );
leSemiMinor->setText( QLocale::system().toString( myMinor, 'f', 3 ) );
}
leSemiMajor->setEnabled( true );
leSemiMinor->setEnabled( true );
}
else
{
cmbEllipsoid->setEnabled( false );
cmbEllipsoid->setToolTip( tr( "Can only use ellipsoidal calculations when CRS transformation is enabled" ) );
leSemiMajor->setToolTip( tr( "Select %1 from pull-down menu to adjust radii" ).arg( tr( "Parameters:" ) ) );
leSemiMinor->setToolTip( tr( "Select %1 from pull-down menu to adjust radii" ).arg( tr( "Parameters:" ) ) );
}
if ( mEllipsoidList[ mEllipsoidIndex ].acronym != GEO_NONE )
{
leSemiMajor->setText( QLocale::system().toString( myMajor, 'f', 3 ) );
leSemiMinor->setText( QLocale::system().toString( myMinor, 'f', 3 ) );
}

cmbEllipsoid->setCurrentIndex( mEllipsoidIndex ); // Not always necessary
}

@@ -419,7 +419,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
if ( mComposerMap && mShowOnlyVisibleFeatures )
{
selectionRect = *mComposerMap->currentMapExtent();
if ( layer && mComposition->mapSettings().hasCrsTransformEnabled() )
if ( layer )
{
//transform back to layer CRS
QgsCoordinateTransform coordTransform( layer->crs(), mComposition->mapSettings().destinationCrs() );
@@ -546,7 +546,7 @@ void QgsComposerHtml::setExpressionContext( const QgsFeature &feature, QgsVector
}
if ( mComposition )
{
mDistanceArea->setEllipsoidalMode( mComposition->mapSettings().hasCrsTransformEnabled() );
mDistanceArea->setEllipsoidalMode( true );
mDistanceArea->setEllipsoid( mComposition->project()->ellipsoid() );
}

@@ -264,7 +264,7 @@ void QgsComposerLabel::refreshExpressionContext()
//set to composition's mapsettings' crs
mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
}
mDistanceArea->setEllipsoidalMode( mComposition->mapSettings().hasCrsTransformEnabled() );
mDistanceArea->setEllipsoidalMode( true );
mDistanceArea->setEllipsoid( mComposition->project()->ellipsoid() );
contentChanged();

@@ -302,7 +302,7 @@ double QgsComposerScaleBar::mapWidth() const
else
{
QgsDistanceArea da;
da.setEllipsoidalMode( mComposition->mapSettings().hasCrsTransformEnabled() );
da.setEllipsoidalMode( true );
da.setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
da.setEllipsoid( mComposition->project()->ellipsoid() );

@@ -353,7 +353,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
// init distance/area calculator
QString ellipsoid = QgsProject::instance()->ellipsoid();
QgsDistanceArea calc;
calc.setEllipsoidalMode( mCanvas->hasCrsTransformEnabled() );
calc.setEllipsoidalMode( true );
calc.setEllipsoid( ellipsoid );
calc.setSourceCrs( layer->crs().srsid() );

0 comments on commit 24c990f

Please sign in to comment.
You can’t perform that action at this time.