@@ -157,6 +157,8 @@ QgsFeatureIterator QgsAfsProvider::getFeatures( const QgsFeatureRequest& request
157
157
158
158
bool QgsAfsProvider::getFeature ( const QgsFeatureId &id, QgsFeature &f, bool fetchGeometry, const QList<int >& /* fetchAttributes*/ , const QgsRectangle filterRect )
159
159
{
160
+ QMutexLocker locker ( &mMutex );
161
+
160
162
// If cached, return cached feature
161
163
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mCache .find ( id );
162
164
if ( it != mCache .end () )
@@ -214,9 +216,8 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
214
216
{
215
217
QVariantMap featureData = featuresData[i].toMap ();
216
218
QgsFeature feature;
219
+ int featureId = startId + i;
217
220
218
- // Set FID
219
- feature.setFeatureId ( startId + i );
220
221
221
222
// Set attributes
222
223
if ( !fetchAttribIdx.isEmpty () )
@@ -227,10 +228,17 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
227
228
foreach ( int idx, fetchAttribIdx )
228
229
{
229
230
attributes[idx] = attributesData[mFields .at ( idx ).name ()];
231
+ if ( mFields .at ( idx ).name () == QStringLiteral ( " OBJECTID" ) )
232
+ {
233
+ featureId = startId + objectIds.indexOf ( attributesData[mFields .at ( idx ).name ()].toInt () );
234
+ }
230
235
}
231
236
feature.setAttributes ( attributes );
232
237
}
233
238
239
+ // Set FID
240
+ feature.setFeatureId ( featureId );
241
+
234
242
// Set geometry
235
243
if ( fetchGeometry )
236
244
{
@@ -243,9 +251,16 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
243
251
feature.setValid ( true );
244
252
mCache .insert ( feature.id (), feature );
245
253
}
246
- f = mCache [id];
247
- Q_ASSERT ( f.isValid () );
248
- return filterRect.isNull () || ( f.geometry () && f.geometry ()->intersects ( filterRect ) );
254
+
255
+ // If added to cached, return feature
256
+ QMap<QgsFeatureId, QgsFeature>::const_iterator it = mCache .find ( id );
257
+ if ( it != mCache .end () )
258
+ {
259
+ f = it.value ();
260
+ return filterRect.isNull () || ( f.geometry () && f.geometry ()->intersects ( filterRect ) );
261
+ }
262
+
263
+ return false ;
249
264
}
250
265
251
266
void QgsAfsProvider::setDataSourceUri ( const QString &uri )
0 commit comments