Skip to content

Commit

Permalink
[ArcGIS REST] fix caching logic for extent filtered requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 23, 2017
1 parent d236942 commit f32791e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/providers/arcgisrest/qgsafsshareddata.cpp
Expand Up @@ -32,7 +32,7 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
if ( it != mCache.constEnd() ) if ( it != mCache.constEnd() )
{ {
f = it.value(); f = it.value();
return filterRect.isNull() || f.geometry().intersects( filterRect ); return filterRect.isNull() || ( f.hasGeometry() && f.geometry().intersects( filterRect ) );
} }


// Determine attributes to fetch // Determine attributes to fetch
Expand Down Expand Up @@ -86,9 +86,7 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
{ {
QVariantMap featureData = featuresData[i].toMap(); QVariantMap featureData = featuresData[i].toMap();
QgsFeature feature; QgsFeature feature;

int objectId = startId + i;
// Set FID
feature.setId( startId + i );


// Set attributes // Set attributes
if ( !fetchAttribIdx.isEmpty() ) if ( !fetchAttribIdx.isEmpty() )
Expand All @@ -99,10 +97,17 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
foreach ( int idx, fetchAttribIdx ) foreach ( int idx, fetchAttribIdx )
{ {
attributes[idx] = attributesData[mFields.at( idx ).name()]; attributes[idx] = attributesData[mFields.at( idx ).name()];
if ( mFields.at( idx ).name() == QStringLiteral( "OBJECTID" ) )
{
objectId = attributesData[mFields.at( idx ).name()].toInt();
}
} }
feature.setAttributes( attributes ); feature.setAttributes( attributes );
} }


// Set FID
feature.setId( startId + objectIds.indexOf( objectId ) );

// Set geometry // Set geometry
if ( fetchGeometry ) if ( fetchGeometry )
{ {
Expand All @@ -115,7 +120,14 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
feature.setValid( true ); feature.setValid( true );
mCache.insert( feature.id(), feature ); mCache.insert( feature.id(), feature );
} }
f = mCache[id];
Q_ASSERT( f.isValid() ); // If added to cache, return feature
return filterRect.isNull() || ( f.hasGeometry() && f.geometry().intersects( filterRect ) ); it = mCache.constFind( id );
if ( it != mCache.constEnd() )
{
f = it.value();
return filterRect.isNull() || ( f.hasGeometry() && f.geometry().intersects( filterRect ) );
}

return false;
} }

0 comments on commit f32791e

Please sign in to comment.