Last active
December 12, 2015 08:49
-
-
Save jef-n/4747002 to your computer and use it in GitHub Desktop.
possible fix for #7125
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/app/qgsmaptoolshowhidelabels.cpp b/src/app/qgsmaptoolshowhidelabels.cpp | |
index 220460c..713488a 100644 | |
--- a/src/app/qgsmaptoolshowhidelabels.cpp | |
+++ b/src/app/qgsmaptoolshowhidelabels.cpp | |
@@ -212,7 +212,7 @@ bool QgsMapToolShowHideLabels::selectedFeatures( QgsVectorLayer* vlayer, | |
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest() | |
.setFilterRect( selectGeomTrans.boundingBox() ) | |
- .setFlags( QgsFeatureRequest::ExactIntersect ) | |
+ .setFlags( QgsFeatureRequest::NoGeometry | QgsFeatureRequest::ExactIntersect ) | |
.setSubsetOfAttributes( QgsAttributeList() ) ); | |
QgsFeature f; | |
diff --git a/src/providers/ogr/qgsogrfeatureiterator.cpp b/src/providers/ogr/qgsogrfeatureiterator.cpp | |
index a4a549d..69e79cb 100644 | |
--- a/src/providers/ogr/qgsogrfeatureiterator.cpp | |
+++ b/src/providers/ogr/qgsogrfeatureiterator.cpp | |
@@ -38,9 +38,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur | |
P->mActiveIterator->close(); | |
P->mActiveIterator = this; | |
- // set the selection rectangle pointer to 0 | |
- mSelectionRectangle = 0; | |
- | |
mFeatureFetched = false; | |
ensureRelevantFields(); | |
@@ -53,17 +50,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur | |
QByteArray ba = wktExtent.toAscii(); | |
const char *wktText = ba; | |
- if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect ) | |
- { | |
- // store the selection rectangle for use in filtering features during | |
- // an identify and display attributes | |
- if ( mSelectionRectangle ) | |
- OGR_G_DestroyGeometry( mSelectionRectangle ); | |
- | |
- OGR_G_CreateFromWkt(( char ** )&wktText, NULL, &mSelectionRectangle ); | |
- wktText = ba; | |
- } | |
- | |
OGR_G_CreateFromWkt(( char ** )&wktText, NULL, &filter ); | |
QgsDebugMsg( "Setting spatial filter using " + wktExtent ); | |
OGR_L_SetSpatialFilter( P->ogrLayer, filter ); | |
@@ -120,13 +106,13 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature ) | |
} | |
readFeature( fet, feature ); | |
+ | |
feature.setValid( true ); | |
close(); // the feature has been read: we have finished here | |
return true; | |
} | |
OGRFeatureH fet; | |
- QgsRectangle selectionRect; | |
while (( fet = OGR_L_GetNextFeature( P->ogrLayer ) ) ) | |
{ | |
@@ -137,26 +123,8 @@ bool QgsOgrFeatureIterator::nextFeature( QgsFeature& feature ) | |
continue; | |
} | |
- readFeature( fet, feature ); | |
- | |
- if ( mRequest.flags() & QgsFeatureRequest::ExactIntersect ) | |
- { | |
- //precise test for intersection with search rectangle | |
- //first make QgsRectangle from OGRPolygon | |
- OGREnvelope env; | |
- memset( &env, 0, sizeof( env ) ); | |
- if ( mSelectionRectangle ) | |
- OGR_G_GetEnvelope( mSelectionRectangle, &env ); | |
- if ( env.MinX != 0 || env.MinY != 0 || env.MaxX != 0 || env.MaxY != 0 ) //if envelope is invalid, skip the precise intersection test | |
- { | |
- selectionRect.set( env.MinX, env.MinY, env.MaxX, env.MaxY ); | |
- if ( !feature.geometry() || !feature.geometry()->intersects( selectionRect ) ) | |
- { | |
- OGR_F_Destroy( fet ); | |
- continue; | |
- } | |
- } | |
- } | |
+ if ( !readFeature( fet, feature ) ) | |
+ continue; | |
// we have a feature, end this cycle | |
feature.setValid( true ); | |
@@ -188,12 +156,6 @@ bool QgsOgrFeatureIterator::close() | |
if ( mClosed ) | |
return false; | |
- if ( mSelectionRectangle ) | |
- { | |
- OGR_G_DestroyGeometry( mSelectionRectangle ); | |
- mSelectionRectangle = 0; | |
- } | |
- | |
// tell provider that this iterator is not active anymore | |
P->mActiveIterator = 0; | |
@@ -234,15 +196,15 @@ void QgsOgrFeatureIterator::getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature | |
} | |
- | |
-void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature ) | |
+bool QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature ) | |
{ | |
feature.setFeatureId( OGR_F_GetFID( fet ) ); | |
feature.initAttributes( P->fields().count() ); | |
feature.setFields( &P->mAttributeFields ); // allow name-based attribute lookups | |
- // fetch geometry | |
- if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) ) | |
+ bool fetchGeom = !( mRequest.flags() & QgsFeatureRequest::NoGeometry ); | |
+ bool useIntersect = mRequest.flags() & QgsFeatureRequest::ExactIntersect; | |
+ if ( fetchGeom || useIntersect ) | |
{ | |
OGRGeometryH geom = OGR_F_GetGeometryRef( fet ); | |
@@ -254,12 +216,19 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature ) | |
feature.setGeometryAndOwnership( wkb, OGR_G_WkbSize( geom ) ); | |
} | |
- else | |
+ | |
+ if ( useIntersect && ( !feature.geometry() || !feature.geometry()->intersects( mRequest.filterRect() ) ) ) | |
{ | |
- feature.setGeometry( 0 ); | |
+ OGR_F_Destroy( fet ); | |
+ return false; | |
} | |
} | |
+ if ( !fetchGeom ) | |
+ { | |
+ feature.setGeometry( 0 ); | |
+ } | |
+ | |
// fetch attributes | |
if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) | |
{ | |
@@ -277,4 +246,6 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature ) | |
getFeatureAttribute( fet, feature, idx ); | |
} | |
} | |
+ | |
+ return true; | |
} | |
diff --git a/src/providers/ogr/qgsogrfeatureiterator.h b/src/providers/ogr/qgsogrfeatureiterator.h | |
index 44e81d0..97d4d7d 100644 | |
--- a/src/providers/ogr/qgsogrfeatureiterator.h | |
+++ b/src/providers/ogr/qgsogrfeatureiterator.h | |
@@ -42,14 +42,11 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIterator | |
void ensureRelevantFields(); | |
- void readFeature( OGRFeatureH fet, QgsFeature& feature ); | |
+ bool readFeature( OGRFeatureH fet, QgsFeature& feature ); | |
//! Get an attribute associated with a feature | |
void getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature & f, int attindex ); | |
- //! Selection rectangle | |
- OGRGeometryH mSelectionRectangle; | |
- | |
bool mFeatureFetched; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment