Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix #7125
  • Loading branch information
jef-n committed Feb 9, 2013
1 parent d4fcc6d commit 19f0666
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -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;
Expand Down
65 changes: 18 additions & 47 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -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();
Expand All @@ -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 );
Expand Down Expand Up @@ -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 ) ) )
{
Expand All @@ -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 );
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 );

Expand All @@ -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 )
{
Expand All @@ -277,4 +246,6 @@ void QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )
getFeatureAttribute( fet, feature, idx );
}
}

return true;
}
5 changes: 1 addition & 4 deletions src/providers/ogr/qgsogrfeatureiterator.h
Expand Up @@ -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;
};

Expand Down

0 comments on commit 19f0666

Please sign in to comment.