mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Respect transform contexts when tracing
This commit is contained in:
parent
13ad7608e8
commit
8f15cdf680
@ -2133,6 +2133,12 @@ loadDefaultStyle argument.
|
|||||||
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.
|
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}
|
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.
|
- 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}
|
QgsTransaction {#qgis_api_break_3_0_QgsTransaction}
|
||||||
--------------
|
--------------
|
||||||
|
@ -43,11 +43,16 @@ Set layers used for tracing
|
|||||||
|
|
||||||
QgsCoordinateReferenceSystem destinationCrs() const;
|
QgsCoordinateReferenceSystem destinationCrs() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Get CRS used for tracing
|
Returns the CRS used for tracing.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`setDestinationCrs()`
|
||||||
%End
|
%End
|
||||||
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
|
|
||||||
|
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
|
||||||
%Docstring
|
%Docstring
|
||||||
Set CRS used for tracing
|
Sets the ``crs`` and transform ``context`` used for tracing.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`destinationCrs()`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsRectangle extent() const;
|
QgsRectangle extent() const;
|
||||||
|
@ -898,6 +898,13 @@ Emitted when zoom next status changed
|
|||||||
Emitted when map CRS has changed
|
Emitted when map CRS has changed
|
||||||
|
|
||||||
.. versionadded:: 2.4
|
.. versionadded:: 2.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
void transformContextChanged();
|
||||||
|
%Docstring
|
||||||
|
Emitted when the canvas transform context is changed.
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
%End
|
%End
|
||||||
|
|
||||||
void currentLayerChanged( QgsMapLayer *layer );
|
void currentLayerChanged( QgsMapLayer *layer );
|
||||||
|
@ -473,16 +473,13 @@ bool QgsTracer::initGraph()
|
|||||||
|
|
||||||
t1.start();
|
t1.start();
|
||||||
int featuresCounted = 0;
|
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;
|
QgsFeatureRequest request;
|
||||||
request.setSubsetOfAttributes( QgsAttributeList() );
|
request.setSubsetOfAttributes( QgsAttributeList() );
|
||||||
|
request.setDestinationCrs( mCRS, mTransformContext );
|
||||||
if ( !mExtent.isEmpty() )
|
if ( !mExtent.isEmpty() )
|
||||||
request.setFilterRect( ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) );
|
request.setFilterRect( mExtent );
|
||||||
|
|
||||||
QgsFeatureIterator fi = vl->getFeatures( request );
|
QgsFeatureIterator fi = vl->getFeatures( request );
|
||||||
while ( fi.nextFeature( f ) )
|
while ( fi.nextFeature( f ) )
|
||||||
@ -490,20 +487,6 @@ bool QgsTracer::initGraph()
|
|||||||
if ( !f.hasGeometry() )
|
if ( !f.hasGeometry() )
|
||||||
continue;
|
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 );
|
extractLinework( f.geometry(), mpl );
|
||||||
|
|
||||||
++featuresCounted;
|
++featuresCounted;
|
||||||
@ -596,12 +579,10 @@ void QgsTracer::setLayers( const QList<QgsVectorLayer *> &layers )
|
|||||||
invalidateGraph();
|
invalidateGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
|
void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context )
|
||||||
{
|
{
|
||||||
if ( mCRS == crs )
|
|
||||||
return;
|
|
||||||
|
|
||||||
mCRS = crs;
|
mCRS = crs;
|
||||||
|
mTransformContext = context;
|
||||||
invalidateGraph();
|
invalidateGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +53,17 @@ class CORE_EXPORT QgsTracer : public QObject
|
|||||||
//! Set layers used for tracing
|
//! Set layers used for tracing
|
||||||
void setLayers( const QList<QgsVectorLayer *> &layers );
|
void setLayers( const QList<QgsVectorLayer *> &layers );
|
||||||
|
|
||||||
//! Get CRS used for tracing
|
/**
|
||||||
|
* Returns the CRS used for tracing.
|
||||||
|
* \see setDestinationCrs()
|
||||||
|
*/
|
||||||
QgsCoordinateReferenceSystem destinationCrs() const { return mCRS; }
|
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)
|
//! Get extent to which graph's features will be limited (empty extent means no limit)
|
||||||
QgsRectangle extent() const { return mExtent; }
|
QgsRectangle extent() const { return mExtent; }
|
||||||
@ -161,6 +168,8 @@ class CORE_EXPORT QgsTracer : public QObject
|
|||||||
QList<QgsVectorLayer *> mLayers;
|
QList<QgsVectorLayer *> mLayers;
|
||||||
//! Destination CRS in which graph is built and tracing done
|
//! Destination CRS in which graph is built and tracing done
|
||||||
QgsCoordinateReferenceSystem mCRS;
|
QgsCoordinateReferenceSystem mCRS;
|
||||||
|
//! Coordinate transform context
|
||||||
|
QgsCoordinateTransformContext mTransformContext;
|
||||||
//! Extent for graph building (empty extent means no limit)
|
//! Extent for graph building (empty extent means no limit)
|
||||||
QgsRectangle mExtent;
|
QgsRectangle mExtent;
|
||||||
|
|
||||||
|
@ -144,6 +144,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
|
|||||||
this, [ = ]
|
this, [ = ]
|
||||||
{
|
{
|
||||||
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
|
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
|
||||||
|
emit transformContextChanged();
|
||||||
refresh();
|
refresh();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -801,6 +801,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
*/
|
*/
|
||||||
void destinationCrsChanged();
|
void destinationCrsChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the canvas transform context is changed.
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
void transformContextChanged();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the current layer is changed
|
* Emitted when the current layer is changed
|
||||||
* \since QGIS 2.8
|
* \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
|
// 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::destinationCrsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
|
||||||
|
connect( canvas, &QgsMapCanvas::transformContextChanged, this, &QgsMapCanvasTracer::invalidateGraph );
|
||||||
connect( canvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasTracer::invalidateGraph );
|
connect( canvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasTracer::invalidateGraph );
|
||||||
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
|
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
|
||||||
connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapCanvasTracer::onCurrentLayerChanged );
|
connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapCanvasTracer::onCurrentLayerChanged );
|
||||||
@ -96,7 +97,7 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte
|
|||||||
|
|
||||||
void QgsMapCanvasTracer::configure()
|
void QgsMapCanvasTracer::configure()
|
||||||
{
|
{
|
||||||
setDestinationCrs( mCanvas->mapSettings().destinationCrs() );
|
setDestinationCrs( mCanvas->mapSettings().destinationCrs(), mCanvas->mapSettings().transformContext() );
|
||||||
setExtent( mCanvas->extent() );
|
setExtent( mCanvas->extent() );
|
||||||
|
|
||||||
QList<QgsVectorLayer *> layers;
|
QList<QgsVectorLayer *> layers;
|
||||||
|
@ -313,7 +313,8 @@ void TestQgsTracer::testReprojection()
|
|||||||
|
|
||||||
QgsTracer tracer;
|
QgsTracer tracer;
|
||||||
tracer.setLayers( QList<QgsVectorLayer *>() << vl );
|
tracer.setLayers( QList<QgsVectorLayer *>() << vl );
|
||||||
tracer.setDestinationCrs( dstCrs );
|
QgsCoordinateTransformContext context;
|
||||||
|
tracer.setDestinationCrs( dstCrs, context );
|
||||||
tracer.init();
|
tracer.init();
|
||||||
|
|
||||||
QgsPolylineXY points1 = tracer.findShortestPath( p1, p2 );
|
QgsPolylineXY points1 = tracer.findShortestPath( p1, p2 );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user