Skip to content

Commit

Permalink
[tracing] fix the case when OTF reprojection is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 20, 2016
1 parent 60816af commit 9fda6aa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions python/core/qgstracer.sip
Expand Up @@ -20,6 +20,11 @@ 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
14 changes: 12 additions & 2 deletions src/core/qgstracer.cpp
Expand Up @@ -437,6 +437,7 @@ void extractLinework( const QgsGeometry* g, QgsMultiPolyline& mpl )

QgsTracer::QgsTracer()
: mGraph( 0 )
, mReprojectionEnabled( false )
, mMaxFeatureCount( 0 )
{
}
Expand Down Expand Up @@ -465,15 +466,15 @@ bool QgsTracer::initGraph()
QgsFeatureRequest request;
request.setSubsetOfAttributes( QgsAttributeList() );
if ( !mExtent.isEmpty() )
request.setFilterRect( ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) );
request.setFilterRect( mReprojectionEnabled ? ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) : mExtent );

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

if ( !ct.isShortCircuited() )
if ( mReprojectionEnabled && !ct.isShortCircuited() )
{
try
{
Expand Down Expand Up @@ -565,6 +566,15 @@ void QgsTracer::setLayers( const QList<QgsVectorLayer*>& layers )
invalidateGraph();
}

void QgsTracer::setCrsTransformEnabled( bool enabled )
{
if ( mReprojectionEnabled == enabled )
return;

mReprojectionEnabled = enabled;
invalidateGraph();
}

void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
{
if ( mCRS == crs )
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgstracer.h
Expand Up @@ -47,6 +47,11 @@ class CORE_EXPORT QgsTracer : public QObject
//! Set layers used for tracing
void setLayers( const QList<QgsVectorLayer*>& layers );

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

//! Get CRS used for tracing
QgsCoordinateReferenceSystem destinationCrs() const { return mCRS; }
//! Set CRS used for tracing
Expand Down Expand Up @@ -113,6 +118,8 @@ class CORE_EXPORT QgsTracer : public QObject
QgsTracerGraph* mGraph;
//! Input layers for the graph building
QList<QgsVectorLayer*> mLayers;
//! Whether to reproject layer features to specified destination CRS
bool mReprojectionEnabled;
//! Destination CRS in which graph is built and tracing done
QgsCoordinateReferenceSystem mCRS;
//! Extent for graph building (empty extent means no limit)
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmapcanvastracer.cpp
Expand Up @@ -84,6 +84,7 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte

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

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgstracer.cpp
Expand Up @@ -312,6 +312,7 @@ void TestQgsTracer::testReprojection()
QgsTracer tracer;
tracer.setLayers( QList<QgsVectorLayer*>() << vl );
tracer.setDestinationCrs( dstCrs );
tracer.setCrsTransformEnabled( true );
tracer.init();

QgsPolyline points1 = tracer.findShortestPath( p1, p2 );
Expand Down

0 comments on commit 9fda6aa

Please sign in to comment.