Skip to content

Commit

Permalink
Remove support for disabling OTF reprojection
Browse files Browse the repository at this point in the history
Because
- OTF reprojection is mature and stable
- Should be no cost when not required - transforms are shortcut
when not required
- Reduces code complexity
- Canvas OTF support was being incorrectly used as a flag for
whether measurements should be made in ellipsoidal mode. Instead
the project's ellipsoid setting should be checked for this.
- Should simplify behavior for new users
  • Loading branch information
nyalldawson committed Feb 28, 2017
1 parent 809d30f commit 20c07a5
Show file tree
Hide file tree
Showing 68 changed files with 398 additions and 873 deletions.
15 changes: 15 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1257,6 +1257,12 @@ QgsLayerTreeNode {#qgis_api_break_3_0_QgsLayerTreeNode}
- readXml() does not resolve layers from the layer IDs anymore. Call resolveReferences() or use readXml() override with QgsProject as the second argument.


QgsLayerTreeMapCanvasBridge {#qgis_api_break_3_0_QgsLayerTreeMapCanvasBridge}
-----------------

- setAutoEnableCrsTransform() and autoEnableCrsTransform() were removed. CRS transformation is now always enabled.


QgsLayerTreeModel {#qgis_api_break_3_0_QgsLayerTreeMode}
-----------------

Expand Down Expand Up @@ -1315,6 +1321,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
- setProgress() signal has been removed. It was not emitted since 2.0.
- enableOverviewMode() and updateOverview() have been removed. Map canvas does not keep pointer to overview canvas anymore. Use QgsLayerTreeMapCanvasBridge::setOverviewCanvas() to set up updates of overview canvas together with main canvas.
- the duplicate mapToolSet signal with a single QgsMapTool argument has been removed. Use the signal with arguments for new and old map tool instead.
- setCrsTransformEnabled(), hasCrsTransformEnabled(), hasCrsTransformEnabledChanged() were removed. CRS transformation is now always enabled.

QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
----------------
Expand Down Expand Up @@ -1354,6 +1361,7 @@ QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}

- layerSet() and setLayerSet() have been replaced by layers() and setLayers() which work with list of layers instead of layer IDs
- destinationSrsChanged() was renamed to destinationCrsChanged()
- hasCrsTransformEnabled() was removed. CRS transformation is now always enabled.


QgsMapRenderer {#qgis_api_break_3_0_QgsMapRenderer}
Expand Down Expand Up @@ -1421,6 +1429,7 @@ QgsMapSettings {#qgis_api_break_3_0_QgsMapSettings}
be returned instead of a null pointer if no transformation is required.
- destinationCrs() now returns a copy instead of a reference to the CRS. This has no effect on PyQGIS code, but c++
plugins calling this method will need to be updated.
- setCrsTransformEnabled() and hasCrsTransformEnabled() were removed. CRS transformation is now always enabled.


QgsMarkerSymbolLayer {#qgis_api_break_3_0_QgsMarkerSymbolLayer}
Expand Down Expand Up @@ -1896,6 +1905,12 @@ QgsTolerance {#qgis_api_break_3_0_QgsTolerance}
- The MapUnits UnitType was removed. Use LayerUnits or ProjectUnits instead.


QgsTracer {#qgis_api_break_3_0_QgsTracer}
---------

- hasCrsTransformEnabled() and setCrsTransformEnabled() were removed. CRS transformation is now always enabled when required.


QgsTreeWidgetItem {#qgis_api_break_3_0_QgsTreeWidgetItem}
-----------------

Expand Down
5 changes: 0 additions & 5 deletions python/core/qgsmapsettings.sip
Expand Up @@ -83,11 +83,6 @@ class QgsMapSettings
*/
void setCustomRenderFlags( const QString& customRenderFlags );

//! sets whether to use projections for this layer set
void setCrsTransformEnabled( bool enabled );
//! returns true if projections are enabled for this layer set
bool hasCrsTransformEnabled() const;

//! sets destination coordinate reference system
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
//! returns CRS of destination coordinate reference system
Expand Down
5 changes: 0 additions & 5 deletions python/core/qgstracer.sip
Expand Up @@ -20,11 +20,6 @@ class QgsTracer : QObject
//! Set layers used for tracing
void setLayers( const QList<QgsVectorLayer*>& layers );

//! Return true if reprojection to destination CRS is enabled
bool hasCrsTransformEnabled() const;
//! Set whether to do reprojection to destination CRS
void setCrsTransformEnabled( bool enabled );

//! Get CRS used for tracing
QgsCoordinateReferenceSystem destinationCrs() const;
//! Set CRS used for tracing
Expand Down
5 changes: 0 additions & 5 deletions python/gui/layertree/qgslayertreemapcanvasbridge.sip
Expand Up @@ -45,11 +45,6 @@ class QgsLayerTreeMapCanvasBridge : QObject
void setAutoSetupOnFirstLayer( bool enabled );
bool autoSetupOnFirstLayer() const;

//! if enabled, will automatically turn on on-the-fly reprojection of layers if a layer
//! with different source CRS is added
void setAutoEnableCrsTransform( bool enabled );
bool autoEnableCrsTransform() const;

public slots:
void setHasCustomLayerOrder( bool state );
void setCustomLayerOrder( const QStringList& order );
Expand Down
11 changes: 0 additions & 11 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -36,10 +36,6 @@ class QgsMapCanvas : QGraphicsView
//! @note added in 2.4
const QgsMapSettings& mapSettings() const /KeepReference/;

//! sets whether to use projections for this layer set
//! @note added in 2.4
void setCrsTransformEnabled( bool enabled );

//! sets destination coordinate reference system
//! @note added in 2.4
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
Expand Down Expand Up @@ -360,9 +356,6 @@ class QgsMapCanvas : QGraphicsView
//! State of render suppression flag
bool renderFlag();

//! A simple helper method to find out if on the fly projections are enabled or not
bool hasCrsTransformEnabled();

//! stop rendering (if there is any right now)
//! @note added in 2.4
void stopRendering();
Expand Down Expand Up @@ -454,10 +447,6 @@ class QgsMapCanvas : QGraphicsView
//! Emitted when zoom next status changed
void zoomNextStatusChanged( bool );

//! Emitted when on-the-fly projection has been turned on/off
//! @note added in 2.4
void hasCrsTransformEnabledChanged( bool flag );

//! Emitted when map CRS has changed
//! @note added in 2.4
void destinationCrsChanged();
Expand Down
3 changes: 0 additions & 3 deletions python/gui/qgsmapoverviewcanvas.sip
Expand Up @@ -32,9 +32,6 @@ class QgsMapOverviewCanvas : QWidget
//! used for overview canvas to reflect changed extent in main map canvas
void drawExtentRect();

// ### QGIS 3: rename so it does not look like getter, make protected
void hasCrsTransformEnabled( bool flag );

// ### QGIS 3: make protected
//! Should be called when the canvas destination CRS is changed
void destinationCrsChanged();
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/qgis/FieldsCalculator.py
Expand Up @@ -100,8 +100,7 @@ def processAlgorithm(self, feedback):

da = QgsDistanceArea()
da.setSourceCrs(layer.crs())
da.setEllipsoidalMode(
iface.mapCanvas().mapSettings().hasCrsTransformEnabled())
da.setEllipsoidalMode(True)
da.setEllipsoid(QgsProject.instance().readEntry(
'Measure', '/Ellipsoid', GEO_NONE)[0])
exp.setGeomCalculator(da)
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Expand Up @@ -104,8 +104,7 @@ def processAlgorithm(self, feedback):

da = QgsDistanceArea()
da.setSourceCrs(layer.crs())
da.setEllipsoidalMode(
iface.mapCanvas().mapSettings().hasCrsTransformEnabled())
da.setEllipsoidalMode(True)
da.setEllipsoid(QgsProject.instance().readEntry(
'Measure', '/Ellipsoid', GEO_NONE)[0])

Expand Down
Expand Up @@ -209,7 +209,7 @@ def processAlgorithm(self, feedback):

director.addStrategy(strategy)
builder = QgsGraphBuilder(iface.mapCanvas().mapSettings().destinationCrs(),
iface.mapCanvas().hasCrsTransformEnabled(),
True,
tolerance)

feedback.pushInfo(self.tr('Loading start points...'))
Expand Down
Expand Up @@ -192,7 +192,7 @@ def processAlgorithm(self, feedback):

director.addStrategy(strategy)
builder = QgsGraphBuilder(iface.mapCanvas().mapSettings().destinationCrs(),
iface.mapCanvas().hasCrsTransformEnabled(),
True,
tolerance)
feedback.pushInfo(self.tr('Building graph...'))
snappedPoints = director.makeGraph(builder, [startPoint])
Expand Down
Expand Up @@ -203,7 +203,7 @@ def processAlgorithm(self, feedback):

director.addStrategy(strategy)
builder = QgsGraphBuilder(iface.mapCanvas().mapSettings().destinationCrs(),
iface.mapCanvas().hasCrsTransformEnabled(),
True,
tolerance)

feedback.pushInfo(self.tr('Loading start points...'))
Expand Down
Expand Up @@ -203,7 +203,7 @@ def processAlgorithm(self, feedback):

director.addStrategy(strategy)
builder = QgsGraphBuilder(iface.mapCanvas().mapSettings().destinationCrs(),
iface.mapCanvas().hasCrsTransformEnabled(),
True,
tolerance)

feedback.pushInfo(self.tr('Loading end points...'))
Expand Down
Expand Up @@ -204,7 +204,7 @@ def processAlgorithm(self, feedback):

director.addStrategy(strategy)
builder = QgsGraphBuilder(iface.mapCanvas().mapSettings().destinationCrs(),
iface.mapCanvas().hasCrsTransformEnabled(),
True,
tolerance)
feedback.pushInfo(self.tr('Building graph...'))
snappedPoints = director.makeGraph(builder, [startPoint, endPoint])
Expand Down
17 changes: 7 additions & 10 deletions src/app/openstreetmap/qgsosmdownloaddialog.cpp
Expand Up @@ -101,17 +101,14 @@ void QgsOSMDownloadDialog::onExtentCanvas()
{
QgsRectangle r( QgisApp::instance()->mapCanvas()->extent() );

if ( QgisApp::instance()->mapCanvas()->hasCrsTransformEnabled() )
{
QgsCoordinateReferenceSystem dst = QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID );
QgsCoordinateReferenceSystem dst = QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID );

QgsCoordinateTransform ct( QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs(), dst );
r = ct.transformBoundingBox( r );
if ( !r.isFinite() )
{
QMessageBox::information( this, tr( "OpenStreetMap download" ), tr( "Could not transform canvas extent." ) );
return;
}
QgsCoordinateTransform ct( QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs(), dst );
r = ct.transformBoundingBox( r );
if ( !r.isFinite() )
{
QMessageBox::information( this, tr( "OpenStreetMap download" ), tr( "Could not transform canvas extent." ) );
return;
}

setRect( r );
Expand Down
82 changes: 15 additions & 67 deletions src/app/qgisapp.cpp
Expand Up @@ -2810,8 +2810,6 @@ void QgisApp::setupConnections()
this, &QgisApp::mapCanvas_keyPressed );

// connect renderer
connect( mMapCanvas, &QgsMapCanvas::hasCrsTransformEnabledChanged,
this, &QgisApp::hasCrsTransformEnabled );
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged,
this, &QgisApp::destinationCrsChanged );

Expand Down Expand Up @@ -3202,9 +3200,6 @@ void QgisApp::initLayerTreeView()
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument& ) ), mLayerTreeCanvasBridge, SLOT( writeProject( QDomDocument& ) ) );
connect( QgsProject::instance(), SIGNAL( readProject( QDomDocument ) ), mLayerTreeCanvasBridge, SLOT( readProject( QDomDocument ) ) );

bool otfTransformAutoEnable = QSettings().value( QStringLiteral( "/Projections/otfTransformAutoEnable" ), true ).toBool();
mLayerTreeCanvasBridge->setAutoEnableCrsTransform( otfTransformAutoEnable );

mMapLayerOrder = new QgsCustomLayerOrderWidget( mLayerTreeCanvasBridge, this );
mMapLayerOrder->setObjectName( QStringLiteral( "theMapLayerOrder" ) );

Expand Down Expand Up @@ -4607,9 +4602,6 @@ void QgisApp::fileNew( bool promptToSaveFlag, bool forceBlank )
mMapCanvas->setMapUnits( srs.mapUnits() );
}

// enable OTF CRS transformation if necessary
mMapCanvas->setCrsTransformEnabled( settings.value( QStringLiteral( "/Projections/otfTransformEnabled" ), 0 ).toBool() );

updateCrsStatusBar();

/** New Empty Project Created
Expand Down Expand Up @@ -5357,11 +5349,6 @@ void QgisApp::openProject( QAction *action )
QString debugme = action->data().toString();
if ( saveDirty() )
addProject( debugme );

//set the projections enabled icon in the status bar
int myProjectionEnabledFlag =
QgsProject::instance()->readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 );
mMapCanvas->setCrsTransformEnabled( myProjectionEnabledFlag );
}

void QgisApp::runScript( const QString &filePath )
Expand Down Expand Up @@ -7582,15 +7569,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
return;

pasteVectorLayer->beginEditCommand( tr( "Features pasted" ) );
QgsFeatureList features;
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->fields() );
}
else
{
features = clipboard()->copyOf( pasteVectorLayer->fields() );
}
QgsFeatureList features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->fields() );
int nTotalFeatures = features.count();

QHash<int, int> remap;
Expand Down Expand Up @@ -8822,23 +8801,17 @@ void QgisApp::legendLayerZoomNative()
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixelX() ) );
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );

if ( mMapCanvas->hasCrsTransformEnabled() )
{
// get length of central canvas pixel width in source raster crs
QgsRectangle e = mMapCanvas->extent();
QSize s = mMapCanvas->mapSettings().outputSize();
QgsPoint p1( e.center().x(), e.center().y() );
QgsPoint p2( e.center().x() + e.width() / s.width(), e.center().y() + e.height() / s.height() );
QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), layer->crs() );
p1 = ct.transform( p1 );
p2 = ct.transform( p2 );
double width = sqrt( p1.sqrDist( p2 ) ); // width (actually the diagonal) of reprojected pixel
mMapCanvas->zoomByFactor( sqrt( layer->rasterUnitsPerPixelX() * layer->rasterUnitsPerPixelX() + layer->rasterUnitsPerPixelY() * layer->rasterUnitsPerPixelY() ) / width );
}
else
{
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixelX() / mMapCanvas->mapUnitsPerPixel() ) );
}
// get length of central canvas pixel width in source raster crs
QgsRectangle e = mMapCanvas->extent();
QSize s = mMapCanvas->mapSettings().outputSize();
QgsPoint p1( e.center().x(), e.center().y() );
QgsPoint p2( e.center().x() + e.width() / s.width(), e.center().y() + e.height() / s.height() );
QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), layer->crs() );
p1 = ct.transform( p1 );
p2 = ct.transform( p2 );
double width = sqrt( p1.sqrDist( p2 ) ); // width (actually the diagonal) of reprojected pixel
mMapCanvas->zoomByFactor( sqrt( layer->rasterUnitsPerPixelX() * layer->rasterUnitsPerPixelX() + layer->rasterUnitsPerPixelY() * layer->rasterUnitsPerPixelY() ) / width );

mMapCanvas->refresh();
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
}
Expand Down Expand Up @@ -9189,9 +9162,6 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
qobject_cast<QgsMeasureTool*>( mMapTools.mMeasureArea )->updateSettings();
qobject_cast<QgsMapToolMeasureAngle*>( mMapTools.mMeasureAngle )->updateSettings();

bool otfTransformAutoEnable = mySettings.value( QStringLiteral( "/Projections/otfTransformAutoEnable" ), true ).toBool();
mLayerTreeCanvasBridge->setAutoEnableCrsTransform( otfTransformAutoEnable );

mMapCanvas->setSegmentationTolerance( mySettings.value( QStringLiteral( "/qgis/segmentationTolerance" ), "0.01745" ).toDouble() );
mMapCanvas->setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType( mySettings.value( QStringLiteral( "/qgis/segmentationToleranceType" ), "0" ).toInt() ) );

Expand Down Expand Up @@ -10311,33 +10281,16 @@ void QgisApp::updateCrsStatusBar()
{
mOnTheFlyProjectionStatusButton->setText( mMapCanvas->mapSettings().destinationCrs().authid() );

if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{
mOnTheFlyProjectionStatusButton->setToolTip(
tr( "Current CRS: %1 (OTF enabled)" ).arg( mMapCanvas->mapSettings().destinationCrs().description() ) );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mIconProjectionEnabled.svg" ) ) );
}
else
{
mOnTheFlyProjectionStatusButton->setText( tr( "%1 (OTF off)" ).arg( mOnTheFlyProjectionStatusButton->text() ) );
mOnTheFlyProjectionStatusButton->setToolTip(
tr( "Current CRS: %1 (OTF disabled)" ).arg( mMapCanvas->mapSettings().destinationCrs().description() ) );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mIconProjectionDisabled.svg" ) ) );
}
mOnTheFlyProjectionStatusButton->setToolTip(
tr( "Current CRS: %1" ).arg( mMapCanvas->mapSettings().destinationCrs().description() ) );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mIconProjectionEnabled.svg" ) ) );
}

void QgisApp::destinationCrsChanged()
{
updateCrsStatusBar();
}

void QgisApp::hasCrsTransformEnabled( bool flag )
{
// save this information to project
QgsProject::instance()->writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), ( flag ? 1 : 0 ) );
updateCrsStatusBar();
}

// slot to update the progress bar in the status bar
void QgisApp::showProgress( int progress, int totalSteps )
{
Expand Down Expand Up @@ -11605,16 +11558,11 @@ void QgisApp::readProject( const QDomDocument &doc )
projectChanged( doc );

// force update of canvas, without automatic changes to extent and OTF projections
bool autoEnableCrsTransform = mLayerTreeCanvasBridge->autoEnableCrsTransform();
bool autoSetupOnFirstLayer = mLayerTreeCanvasBridge->autoSetupOnFirstLayer();
mLayerTreeCanvasBridge->setAutoEnableCrsTransform( false );
mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( false );

mLayerTreeCanvasBridge->setCanvasLayers();

if ( autoEnableCrsTransform )
mLayerTreeCanvasBridge->setAutoEnableCrsTransform( true );

if ( autoSetupOnFirstLayer )
mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( true );
}
Expand Down
1 change: 0 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -1194,7 +1194,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void displayMessage( const QString& title, const QString& message, QgsMessageBar::MessageLevel level );
void removeMapToolMessage();
void updateMouseCoordinatePrecision();
void hasCrsTransformEnabled( bool flag );
void destinationCrsChanged();
// void debugHook();
//! Add a Layer Definition file
Expand Down
5 changes: 1 addition & 4 deletions src/app/qgsmaptoollabel.cpp
Expand Up @@ -105,10 +105,7 @@ void QgsMapToolLabel::createRubberBands()
if ( mCanvas )
{
const QgsMapSettings& s = mCanvas->mapSettings();
if ( s.hasCrsTransformEnabled() )
{
fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint );
}
fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint );
}

QgsGeometry pointGeom = QgsGeometry::fromPoint( fixPoint );
Expand Down

0 comments on commit 20c07a5

Please sign in to comment.