Skip to content
Permalink
Browse files

Respect transform contexts when tracing

  • Loading branch information
nyalldawson committed Jan 4, 2018
1 parent 13ad760 commit 8f15cdf680d7b10b50780900fd689e23682c8003
@@ -2133,6 +2133,12 @@ loadDefaultStyle argument.
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.


QgsRasterLayerSaveAsDialog {#qgis_api_break_3_0_QgsRasterLayerSaveAsDialog}
--------------------------

- The currentExtent and currentCrs arguments have been dropped from the constructor. Use setMapCanvas() instead.


QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
------------------

@@ -2524,6 +2530,8 @@ QgsTracer {#qgis_api_break_3_0_QgsTracer}
---------

- hasCrsTransformEnabled() and setCrsTransformEnabled() were removed. CRS transformation is now always enabled when required.
- setDestinationCrs() now requires a QgsCoordinateTransformContext argument.


QgsTransaction {#qgis_api_break_3_0_QgsTransaction}
--------------
@@ -43,11 +43,16 @@ Set layers used for tracing

QgsCoordinateReferenceSystem destinationCrs() const;
%Docstring
Get CRS used for tracing
Returns the CRS used for tracing.

.. seealso:: :py:func:`setDestinationCrs()`
%End
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );

void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
%Docstring
Set CRS used for tracing
Sets the ``crs`` and transform ``context`` used for tracing.

.. seealso:: :py:func:`destinationCrs()`
%End

QgsRectangle extent() const;
@@ -898,6 +898,13 @@ Emitted when zoom next status changed
Emitted when map CRS has changed

.. versionadded:: 2.4
%End

void transformContextChanged();
%Docstring
Emitted when the canvas transform context is changed.

.. versionadded:: 3.0
%End

void currentLayerChanged( QgsMapLayer *layer );
@@ -473,37 +473,20 @@ bool QgsTracer::initGraph()

t1.start();
int featuresCounted = 0;
Q_FOREACH ( QgsVectorLayer *vl, mLayers )
for ( QgsVectorLayer *vl : qgis::as_const( mLayers ) )
{
Q_NOWARN_DEPRECATED_PUSH
QgsCoordinateTransform ct( vl->crs(), mCRS );
Q_NOWARN_DEPRECATED_POP

QgsFeatureRequest request;
request.setSubsetOfAttributes( QgsAttributeList() );
request.setDestinationCrs( mCRS, mTransformContext );
if ( !mExtent.isEmpty() )
request.setFilterRect( ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) );
request.setFilterRect( mExtent );

QgsFeatureIterator fi = vl->getFeatures( request );
while ( fi.nextFeature( f ) )
{
if ( !f.hasGeometry() )
continue;

if ( !ct.isShortCircuited() )
{
try
{
QgsGeometry transformedGeom = f.geometry();
transformedGeom.transform( ct );
f.setGeometry( transformedGeom );
}
catch ( QgsCsException & )
{
continue; // ignore if the transform failed
}
}

extractLinework( f.geometry(), mpl );

++featuresCounted;
@@ -596,12 +579,10 @@ void QgsTracer::setLayers( const QList<QgsVectorLayer *> &layers )
invalidateGraph();
}

void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context )
{
if ( mCRS == crs )
return;

mCRS = crs;
mTransformContext = context;
invalidateGraph();
}

@@ -53,10 +53,17 @@ class CORE_EXPORT QgsTracer : public QObject
//! Set layers used for tracing
void setLayers( const QList<QgsVectorLayer *> &layers );

//! Get CRS used for tracing
/**
* Returns the CRS used for tracing.
* \see setDestinationCrs()
*/
QgsCoordinateReferenceSystem destinationCrs() const { return mCRS; }
//! Set CRS used for tracing
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );

/**
* Sets the \a crs and transform \a context used for tracing.
* \see destinationCrs()
*/
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );

//! Get extent to which graph's features will be limited (empty extent means no limit)
QgsRectangle extent() const { return mExtent; }
@@ -161,6 +168,8 @@ class CORE_EXPORT QgsTracer : public QObject
QList<QgsVectorLayer *> mLayers;
//! Destination CRS in which graph is built and tracing done
QgsCoordinateReferenceSystem mCRS;
//! Coordinate transform context
QgsCoordinateTransformContext mTransformContext;
//! Extent for graph building (empty extent means no limit)
QgsRectangle mExtent;

@@ -144,6 +144,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
this, [ = ]
{
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
emit transformContextChanged();
refresh();
} );

@@ -801,6 +801,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
*/
void destinationCrsChanged();

/**
* Emitted when the canvas transform context is changed.
* \since QGIS 3.0
*/
void transformContextChanged();

/**
* Emitted when the current layer is changed
* \since QGIS 2.8
@@ -39,6 +39,7 @@ QgsMapCanvasTracer::QgsMapCanvasTracer( QgsMapCanvas *canvas, QgsMessageBar *mes

// when things change we just invalidate the graph - and set up new parameters again only when necessary
connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
connect( canvas, &QgsMapCanvas::transformContextChanged, this, &QgsMapCanvasTracer::invalidateGraph );
connect( canvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasTracer::invalidateGraph );
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapCanvasTracer::onCurrentLayerChanged );
@@ -96,7 +97,7 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte

void QgsMapCanvasTracer::configure()
{
setDestinationCrs( mCanvas->mapSettings().destinationCrs() );
setDestinationCrs( mCanvas->mapSettings().destinationCrs(), mCanvas->mapSettings().transformContext() );
setExtent( mCanvas->extent() );

QList<QgsVectorLayer *> layers;
@@ -313,7 +313,8 @@ void TestQgsTracer::testReprojection()

QgsTracer tracer;
tracer.setLayers( QList<QgsVectorLayer *>() << vl );
tracer.setDestinationCrs( dstCrs );
QgsCoordinateTransformContext context;
tracer.setDestinationCrs( dstCrs, context );
tracer.init();

QgsPolylineXY points1 = tracer.findShortestPath( p1, p2 );

0 comments on commit 8f15cdf

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