Skip to content

Commit dda51c6

Browse files
committedJan 21, 2013
wfs provider: copy geometry and attributes only if necessary
1 parent bde20b4 commit dda51c6

File tree

3 files changed

+21
-106
lines changed

3 files changed

+21
-106
lines changed
 

‎src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QgsWFSFeatureIterator::QgsWFSFeatureIterator( QgsWFSProvider* provider, const Qg
4040

4141
QgsWFSFeatureIterator::~QgsWFSFeatureIterator()
4242
{
43-
43+
close();
4444
}
4545

4646
bool QgsWFSFeatureIterator::nextFeature( QgsFeature& f )
@@ -61,7 +61,17 @@ bool QgsWFSFeatureIterator::nextFeature( QgsFeature& f )
6161
return false;
6262
}
6363
QgsFeature* fet = it.value();
64-
mProvider->copyFeature( fet, f, !( mRequest.flags() & QgsFeatureRequest::NoGeometry ), mRequest.subsetOfAttributes() );
64+
65+
QgsAttributeList attributes;
66+
if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
67+
{
68+
attributes = mRequest.subsetOfAttributes();
69+
}
70+
else
71+
{
72+
attributes = mProvider->attributeIndexes();
73+
}
74+
mProvider->copyFeature( fet, f, !( mRequest.flags() & QgsFeatureRequest::NoGeometry ), attributes );
6575
++mFeatureIterator;
6676
return true;
6777
}

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,28 @@ void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetch
159159

160160
//copy the geometry
161161
QgsGeometry* geometry = f->geometry();
162-
if ( geometry )
162+
if ( geometry && fetchGeometry )
163163
{
164164
unsigned char *geom = geometry->asWkb();
165165
int geomSize = geometry->wkbSize();
166166
unsigned char* copiedGeom = new unsigned char[geomSize];
167167
memcpy( copiedGeom, geom, geomSize );
168168
feature.setGeometryAndOwnership( copiedGeom, geomSize );
169169
}
170+
else
171+
{
172+
feature.setGeometry( 0 );
173+
}
170174

171175
//and the attributes
172176
const QgsAttributes& attributes = f->attributes();
173177
feature.setAttributes( attributes );
178+
179+
int i = 0;
174180
for ( QgsAttributeList::const_iterator it = fetchAttributes.begin(); it != fetchAttributes.end(); ++it )
175181
{
176-
feature.setAttribute( *it, attributes[*it] );
182+
feature.setAttribute( i, attributes[*it] );
183+
++i;
177184
}
178185

179186
//id and valid
@@ -351,96 +358,6 @@ QgsFeatureIterator QgsWFSProvider::getFeatures( const QgsFeatureRequest& request
351358
return QgsFeatureIterator( new QgsWFSFeatureIterator( this, request ) );
352359
}
353360

354-
void QgsWFSProvider::select( QgsAttributeList fetchAttributes,
355-
QgsRectangle rect,
356-
bool fetchGeometry,
357-
bool useIntersect )
358-
{
359-
360-
if ( geometryType() == QGis::WKBNoGeometry )
361-
{
362-
fetchGeometry = false;
363-
}
364-
365-
mUseIntersect = useIntersect;
366-
mAttributesToFetch = fetchAttributes;
367-
mFetchGeom = fetchGeometry;
368-
369-
if ( rect.isEmpty() )
370-
{ //select all features
371-
mSpatialFilter = mExtent;
372-
mSelectedFeatures = mFeatures.keys();
373-
}
374-
else
375-
{ //select features intersecting caller's extent
376-
QString dsURI = dataSourceUri();
377-
//first time through, initialize GetRenderedOnly args
378-
//ctor cannot initialize because layer object not available then
379-
if ( ! mInitGro )
380-
{ //did user check "Cache Features" in WFS layer source selection?
381-
if ( dsURI.contains( "BBOX" ) )
382-
{ //no: initialize incremental getFeature
383-
if ( initGetRenderedOnly( rect ) )
384-
{
385-
mGetRenderedOnly = true;
386-
}
387-
else
388-
{ //initialization failed;
389-
QgsDebugMsg( QString( "GetRenderedOnly initialization failed; incorrect operation may occur\n%1" )
390-
.arg( dataSourceUri() ) );
391-
QMessageBox( QMessageBox::Warning, "Non-Cached layer initialization failed!",
392-
QString( "Incorrect operation may occur:\n%1" ).arg( dataSourceUri() ) );
393-
}
394-
}
395-
mInitGro = true;
396-
}
397-
398-
if ( mGetRenderedOnly )
399-
{ //"Cache Features" was not selected for this layer
400-
//has rendered extent expanded beyond last-retrieved WFS extent?
401-
//NB: "intersect" instead of "contains" tolerates rounding errors;
402-
// avoids unnecessary second fetch on zoom-in/zoom-out sequences
403-
QgsRectangle olap( rect );
404-
olap = olap.intersect( &mGetExtent );
405-
if ( doubleNear( rect.width(), olap.width() ) && doubleNear( rect.height(), olap.height() ) )
406-
{ //difference between canvas and layer extents is within rounding error: do not re-fetch
407-
QgsDebugMsg( QString( "Layer %1 GetRenderedOnly: no fetch required" ).arg( mLayer->name() ) );
408-
}
409-
else
410-
{ //combined old and new extents might speed up local panning & zooming
411-
mGetExtent.combineExtentWith( &rect );
412-
//but see if the combination is useless or too big
413-
double pArea = mGetExtent.width() * mGetExtent.height();
414-
double cArea = rect.width() * rect.height();
415-
if ( olap.isEmpty() || pArea > ( cArea * 4.0 ) )
416-
{ //new canvas extent does not overlap or combining old and new extents would
417-
//fetch > 4 times the area to be rendered; get only what will be rendered
418-
mGetExtent = rect;
419-
}
420-
QgsDebugMsg( QString( "Layer %1 GetRenderedOnly: fetching extent %2" )
421-
.arg( mLayer->name(), mGetExtent.asWktCoordinates() ) );
422-
dsURI = dsURI.replace( QRegExp( "BBOX=[^&]*" ),
423-
QString( "BBOX=%1,%2,%3,%4" )
424-
.arg( mGetExtent.xMinimum(), 0, 'f' )
425-
.arg( mGetExtent.yMinimum(), 0, 'f' )
426-
.arg( mGetExtent.xMaximum(), 0, 'f' )
427-
.arg( mGetExtent.yMaximum(), 0, 'f' ) );
428-
//TODO: BBOX may not be combined with FILTER. WFS spec v. 1.1.0, sec. 14.7.3 ff.
429-
// if a FILTER is present, the BBOX must be merged into it, capabilities permitting.
430-
// Else one criterion must be abandoned and the user warned. [WBC 111221]
431-
setDataSourceUri( dsURI );
432-
reloadData();
433-
mLayer->updateExtents();
434-
}
435-
}
436-
437-
mSpatialFilter = rect;
438-
mSelectedFeatures = mSpatialIndex->intersects( mSpatialFilter );
439-
}
440-
441-
mFeatureIterator = mSelectedFeatures.begin();
442-
}
443-
444361
int QgsWFSProvider::getFeature( const QString& uri )
445362
{
446363
if ( mRequestEncoding == QgsWFSProvider::GET )

‎src/providers/wfs/qgswfsprovider.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ class QgsWFSProvider: public QgsVectorDataProvider
4949

5050
QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() );
5151

52-
/** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
53-
* @param fetchAttributes list of attributes which should be fetched
54-
* @param rect spatial filter
55-
* @param fetchGeometry true if the feature geometry should be fetched
56-
* @param useIntersect true if an accurate intersection test should be used,
57-
* false if a test based on bounding box is sufficient
58-
*/
59-
virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(),
60-
QgsRectangle rect = QgsRectangle(),
61-
bool fetchGeometry = true,
62-
bool useIntersect = false );
63-
6452
/**
6553
* Gets the feature at the given feature ID.
6654
* @param featureId of the feature to be returned

0 commit comments

Comments
 (0)
Please sign in to comment.