Skip to content

Commit 19f0666

Browse files
committed
fix #7125
1 parent d4fcc6d commit 19f0666

File tree

3 files changed

+20
-52
lines changed

3 files changed

+20
-52
lines changed

src/app/qgsmaptoolshowhidelabels.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ bool QgsMapToolShowHideLabels::selectedFeatures( QgsVectorLayer* vlayer,
212212

213213
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest()
214214
.setFilterRect( selectGeomTrans.boundingBox() )
215-
.setFlags( QgsFeatureRequest::ExactIntersect )
215+
.setFlags( QgsFeatureRequest::NoGeometry | QgsFeatureRequest::ExactIntersect )
216216
.setSubsetOfAttributes( QgsAttributeList() ) );
217217

218218
QgsFeature f;

src/providers/ogr/qgsogrfeatureiterator.cpp

+18-47
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
3838
P->mActiveIterator->close();
3939
P->mActiveIterator = this;
4040

41-
// set the selection rectangle pointer to 0
42-
mSelectionRectangle = 0;
43-
4441
mFeatureFetched = false;
4542

4643
ensureRelevantFields();
@@ -53,17 +50,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
5350
QByteArray ba = wktExtent.toAscii();
5451
const char *wktText = ba;
5552

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-
6753
OGR_G_CreateFromWkt(( char ** )&wktText, NULL, &filter );
6854
QgsDebugMsg( "Setting spatial filter using " + wktExtent );
6955
OGR_L_SetSpatialFilter( P->ogrLayer, filter );
@@ -120,13 +106,13 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature )
120106
}
121107

122108
readFeature( fet, feature );
109+
123110
feature.setValid( true );
124111
close(); // the feature has been read: we have finished here
125112
return true;
126113
}
127114

128115
OGRFeatureH fet;
129-
QgsRectangle selectionRect;
130116

131117
while (( fet = OGR_L_GetNextFeature( P->ogrLayer ) ) )
132118
{
@@ -137,26 +123,8 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature )
137123
continue;
138124
}
139125

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;
160128

161129
// we have a feature, end this cycle
162130
feature.setValid( true );
@@ -188,12 +156,6 @@ bool QgsOgrFeatureIterator::close()
188156
if ( mClosed )
189157
return false;
190158

191-
if ( mSelectionRectangle )
192-
{
193-
OGR_G_DestroyGeometry( mSelectionRectangle );
194-
mSelectionRectangle = 0;
195-
}
196-
197159
// tell provider that this iterator is not active anymore
198160
P->mActiveIterator = 0;
199161

@@ -234,15 +196,15 @@ void QgsOgrFeatureIterator::getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature
234196
}
235197

236198

237-
238-
void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
199+
bool QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
239200
{
240201
feature.setFeatureId( OGR_F_GetFID( fet ) );
241202
feature.initAttributes( P->fields().count() );
242203
feature.setFields( &P->mAttributeFields ); // allow name-based attribute lookups
243204

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 )
246208
{
247209
OGRGeometryH geom = OGR_F_GetGeometryRef( fet );
248210

@@ -254,12 +216,19 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
254216

255217
feature.setGeometryAndOwnership( wkb, OGR_G_WkbSize( geom ) );
256218
}
257-
else
219+
220+
if ( useIntersect && ( !feature.geometry() || !feature.geometry()->intersects( mRequest.filterRect() ) ) )
258221
{
259-
feature.setGeometry( 0 );
222+
OGR_F_Destroy( fet );
223+
return false;
260224
}
261225
}
262226

227+
if ( !fetchGeom )
228+
{
229+
feature.setGeometry( 0 );
230+
}
231+
263232
// fetch attributes
264233
if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
265234
{
@@ -277,4 +246,6 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
277246
getFeatureAttribute( fet, feature, idx );
278247
}
279248
}
249+
250+
return true;
280251
}

src/providers/ogr/qgsogrfeatureiterator.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIterator
4242

4343
void ensureRelevantFields();
4444

45-
void readFeature( OGRFeatureH fet, QgsFeature& feature );
45+
bool readFeature( OGRFeatureH fet, QgsFeature& feature );
4646

4747
//! Get an attribute associated with a feature
4848
void getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature & f, int attindex );
4949

50-
//! Selection rectangle
51-
OGRGeometryH mSelectionRectangle;
52-
5350
bool mFeatureFetched;
5451
};
5552

0 commit comments

Comments
 (0)