@@ -38,9 +38,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
38
38
P->mActiveIterator ->close ();
39
39
P->mActiveIterator = this ;
40
40
41
- // set the selection rectangle pointer to 0
42
- mSelectionRectangle = 0 ;
43
-
44
41
mFeatureFetched = false ;
45
42
46
43
ensureRelevantFields ();
@@ -53,17 +50,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
53
50
QByteArray ba = wktExtent.toAscii ();
54
51
const char *wktText = ba;
55
52
56
- if ( mRequest .flags () & QgsFeatureRequest::ExactIntersect )
57
- {
58
- // store the selection rectangle for use in filtering features during
59
- // an identify and display attributes
60
- if ( mSelectionRectangle )
61
- OGR_G_DestroyGeometry ( mSelectionRectangle );
62
-
63
- OGR_G_CreateFromWkt (( char ** )&wktText, NULL , &mSelectionRectangle );
64
- wktText = ba;
65
- }
66
-
67
53
OGR_G_CreateFromWkt (( char ** )&wktText, NULL , &filter );
68
54
QgsDebugMsg ( " Setting spatial filter using " + wktExtent );
69
55
OGR_L_SetSpatialFilter ( P->ogrLayer , filter );
@@ -120,13 +106,13 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature )
120
106
}
121
107
122
108
readFeature ( fet, feature );
109
+
123
110
feature.setValid ( true );
124
111
close (); // the feature has been read: we have finished here
125
112
return true ;
126
113
}
127
114
128
115
OGRFeatureH fet;
129
- QgsRectangle selectionRect;
130
116
131
117
while (( fet = OGR_L_GetNextFeature ( P->ogrLayer ) ) )
132
118
{
@@ -137,26 +123,8 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature )
137
123
continue ;
138
124
}
139
125
140
- readFeature ( fet, feature );
141
-
142
- if ( mRequest .flags () & QgsFeatureRequest::ExactIntersect )
143
- {
144
- // precise test for intersection with search rectangle
145
- // first make QgsRectangle from OGRPolygon
146
- OGREnvelope env;
147
- memset ( &env, 0 , sizeof ( env ) );
148
- if ( mSelectionRectangle )
149
- OGR_G_GetEnvelope ( mSelectionRectangle , &env );
150
- if ( env.MinX != 0 || env.MinY != 0 || env.MaxX != 0 || env.MaxY != 0 ) // if envelope is invalid, skip the precise intersection test
151
- {
152
- selectionRect.set ( env.MinX , env.MinY , env.MaxX , env.MaxY );
153
- if ( !feature.geometry () || !feature.geometry ()->intersects ( selectionRect ) )
154
- {
155
- OGR_F_Destroy ( fet );
156
- continue ;
157
- }
158
- }
159
- }
126
+ if ( !readFeature ( fet, feature ) )
127
+ continue ;
160
128
161
129
// we have a feature, end this cycle
162
130
feature.setValid ( true );
@@ -188,12 +156,6 @@ bool QgsOgrFeatureIterator::close()
188
156
if ( mClosed )
189
157
return false ;
190
158
191
- if ( mSelectionRectangle )
192
- {
193
- OGR_G_DestroyGeometry ( mSelectionRectangle );
194
- mSelectionRectangle = 0 ;
195
- }
196
-
197
159
// tell provider that this iterator is not active anymore
198
160
P->mActiveIterator = 0 ;
199
161
@@ -234,15 +196,15 @@ void QgsOgrFeatureIterator::getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature
234
196
}
235
197
236
198
237
-
238
- void QgsOgrFeatureIterator::readFeature ( OGRFeatureH fet, QgsFeature& feature )
199
+ bool QgsOgrFeatureIterator::readFeature ( OGRFeatureH fet, QgsFeature& feature )
239
200
{
240
201
feature.setFeatureId ( OGR_F_GetFID ( fet ) );
241
202
feature.initAttributes ( P->fields ().count () );
242
203
feature.setFields ( &P->mAttributeFields ); // allow name-based attribute lookups
243
204
244
- // fetch geometry
245
- if ( !( mRequest .flags () & QgsFeatureRequest::NoGeometry ) )
205
+ bool fetchGeom = !( mRequest .flags () & QgsFeatureRequest::NoGeometry );
206
+ bool useIntersect = mRequest .flags () & QgsFeatureRequest::ExactIntersect;
207
+ if ( fetchGeom || useIntersect )
246
208
{
247
209
OGRGeometryH geom = OGR_F_GetGeometryRef ( fet );
248
210
@@ -254,12 +216,19 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
254
216
255
217
feature.setGeometryAndOwnership ( wkb, OGR_G_WkbSize ( geom ) );
256
218
}
257
- else
219
+
220
+ if ( useIntersect && ( !feature.geometry () || !feature.geometry ()->intersects ( mRequest .filterRect () ) ) )
258
221
{
259
- feature.setGeometry ( 0 );
222
+ OGR_F_Destroy ( fet );
223
+ return false ;
260
224
}
261
225
}
262
226
227
+ if ( !fetchGeom )
228
+ {
229
+ feature.setGeometry ( 0 );
230
+ }
231
+
263
232
// fetch attributes
264
233
if ( mRequest .flags () & QgsFeatureRequest::SubsetOfAttributes )
265
234
{
@@ -277,4 +246,6 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
277
246
getFeatureAttribute ( fet, feature, idx );
278
247
}
279
248
}
249
+
250
+ return true ;
280
251
}
0 commit comments