Skip to content
Permalink
Browse files

[tracing] fix the case when OTF reprojection is disabled

  • Loading branch information
wonder-sk committed Jan 20, 2016
1 parent 60816af commit 9fda6aaf53d814ab30783ae0fff3773abb1e572b
@@ -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
@@ -437,6 +437,7 @@ void extractLinework( const QgsGeometry* g, QgsMultiPolyline& mpl )

QgsTracer::QgsTracer()
: mGraph( 0 )
, mReprojectionEnabled( false )
, mMaxFeatureCount( 0 )
{
}
@@ -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
{
@@ -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 )
@@ -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
@@ -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)
@@ -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() );

@@ -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 );

0 comments on commit 9fda6aa

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