Skip to content
Permalink
Browse files

Return an invalid iterator if a transform exception occurs

when projecting filter rects from destination crs
  • Loading branch information
nyalldawson committed Jun 8, 2017
1 parent 7d847bf commit e437812a689ebeca9a4a29fd3eaee4664b153450
@@ -120,6 +120,7 @@ end of iterating: free the resources / lock
the requested filterRect() transformed to the source's coordinate reference system.
Iterators should call this method and use the returned rectangle for filtering
features to ensure that any QgsFeatureRequest.destinationCrs() set on the request is respected.
Will throw a QgsCsException if the rect cannot be transformed from the destination CRS.
.. versionadded:: 3.0
:rtype: QgsRectangle
%End
@@ -21,6 +21,7 @@
#include "qgsspatialindex.h"
#include "qgsmessagelog.h"
#include "qgsproject.h"
#include "qgscsexception.h"

///@cond PRIVATE

@@ -31,7 +32,16 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource *sour
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

if ( !mSource->mSubsetString.isEmpty() )
{
@@ -15,6 +15,7 @@

#include "qgscachedfeatureiterator.h"
#include "qgsvectorlayercache.h"
#include "qgscsexception.h"

QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache, const QgsFeatureRequest &featureRequest )
: QgsAbstractFeatureIterator( featureRequest )
@@ -24,7 +25,16 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
{
mTransform = QgsCoordinateTransform( mVectorLayerCache->sourceCrs(), mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}
if ( !mFilterRect.isNull() )
{
// update request to be the unprojected filter rect
@@ -101,7 +111,16 @@ QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator( QgsVectorLayerCa
{
mTransform = QgsCoordinateTransform( mVectorLayerCache->sourceCrs(), mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}
if ( !mFilterRect.isNull() )
{
// update request to be the unprojected filter rect
@@ -124,15 +124,7 @@ QgsRectangle QgsAbstractFeatureIterator::filterRectToSourceCrs( const QgsCoordin
if ( mRequest.filterRect().isNull() )
return QgsRectangle();

try
{
return transform.transformBoundingBox( mRequest.filterRect(), QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
return mRequest.filterRect();
}
return transform.transformBoundingBox( mRequest.filterRect(), QgsCoordinateTransform::ReverseTransform );
}

void QgsAbstractFeatureIterator::ref()
@@ -131,6 +131,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
* the requested filterRect() transformed to the source's coordinate reference system.
* Iterators should call this method and use the returned rectangle for filtering
* features to ensure that any QgsFeatureRequest::destinationCrs() set on the request is respected.
* Will throw a QgsCsException if the rect cannot be transformed from the destination CRS.
* \since QGIS 3.0
*/
QgsRectangle filterRectToSourceCrs( const QgsCoordinateTransform &transform ) const;
@@ -25,6 +25,7 @@
#include "qgsdistancearea.h"
#include "qgsproject.h"
#include "qgsmessagelog.h"
#include "qgscsexception.h"

QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( const QgsVectorLayer *layer )
{
@@ -113,7 +114,16 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}
if ( !mFilterRect.isNull() )
{
// update request to be the unprojected filter rect
@@ -17,7 +17,7 @@
#include "qgsafsprovider.h"
#include "qgsmessagelog.h"
#include "geometry/qgsgeometry.h"

#include "qgscsexception.h"

QgsAfsFeatureSource::QgsAfsFeatureSource( const QgsAfsProvider *provider )
// FIXME: ugly const_cast...
@@ -45,7 +45,16 @@ QgsAfsFeatureIterator::QgsAfsFeatureIterator( QgsAfsFeatureSource *source, bool
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}
}

QgsAfsFeatureIterator::~QgsAfsFeatureIterator()
@@ -22,6 +22,7 @@
#include "qgssettings.h"
#include "qgslogger.h"
#include "qgsgeometry.h"
#include "qgscsexception.h"

#include <QObject>
#include <QTextStream>
@@ -37,7 +38,16 @@ QgsDb2FeatureIterator::QgsDb2FeatureIterator( QgsDb2FeatureSource *source, bool
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

BuildStatement( request );

@@ -43,7 +43,16 @@ QgsDelimitedTextFeatureIterator::QgsDelimitedTextFeatureIterator( QgsDelimitedTe
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

if ( !mFilterRect.isNull() && hasGeometry )
{
@@ -20,6 +20,7 @@
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgscsexception.h"

#include <limits>
#include <cstring>
@@ -32,7 +33,16 @@ QgsGPXFeatureIterator::QgsGPXFeatureIterator( QgsGPXFeatureSource *source, bool
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

rewind();
}
@@ -20,6 +20,7 @@
#include "qgsmssqlprovider.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgscsexception.h"

#include <QObject>
#include <QTextStream>
@@ -37,7 +38,16 @@ QgsMssqlFeatureIterator::QgsMssqlFeatureIterator( QgsMssqlFeatureSource *source,
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

BuildStatement( request );

@@ -80,7 +80,16 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

mFetchGeometry = ( !mFilterRect.isNull() ) || !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
QgsAttributeList attrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : mSource->mFields.allAttributesList();
@@ -22,6 +22,7 @@
#include "qgsmessagelog.h"
#include "qgsgeometry.h"
#include "qgssettings.h"
#include "qgscsexception.h"

#include <QObject>

@@ -42,7 +43,16 @@ QgsOracleFeatureIterator::QgsOracleFeatureIterator( QgsOracleFeatureSource *sour
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

QVariantList args;
mQry = QSqlQuery( *mConnection );
@@ -21,6 +21,7 @@
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include "qgscsexception.h"

#include <QElapsedTimer>
#include <QObject>
@@ -57,7 +58,16 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

mCursorName = mConn->uniqueCursorName();
QString whereClause;
@@ -47,7 +47,16 @@ QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeature
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

//beware - limitAtProvider needs to be set to false if the request cannot be completely handled
//by the provider (e.g., utilising QGIS expression filters)
@@ -19,6 +19,7 @@ email : hugo dot mercier at oslandia dot com
#include "qgsmessagelog.h"
#include "qgsgeometry.h"
#include "qgsvirtuallayerblob.h"
#include "qgscsexception.h"

#include <stdexcept>

@@ -46,7 +47,16 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

try
{
@@ -26,6 +26,7 @@
#include "qgswfsutils.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgscsexception.h"

#include <QDir>
#include <QProgressDialog>
@@ -793,7 +794,16 @@ QgsWFSFeatureIterator::QgsWFSFeatureIterator( QgsWFSFeatureSource *source,
{
mTransform = QgsCoordinateTransform( mSource->mCrs, mRequest.destinationCrs() );
}
mFilterRect = filterRectToSourceCrs( mTransform );
try
{
mFilterRect = filterRectToSourceCrs( mTransform );
}
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
return;
}

// Configurable for the purpose of unit tests
QString threshold( getenv( "QGIS_WFS_ITERATOR_TRANSFER_THRESHOLD" ) );

0 comments on commit e437812

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