Skip to content

Commit cfbb5d7

Browse files
authoredNov 23, 2017
[ArcGIS REST] backport for crasher and mutex
1 parent 10b34b9 commit cfbb5d7

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed
 

‎src/providers/arcgisrest/qgsafsprovider.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ QgsFeatureIterator QgsAfsProvider::getFeatures( const QgsFeatureRequest& request
157157

158158
bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fetchGeometry, const QList<int>& /*fetchAttributes*/, const QgsRectangle filterRect )
159159
{
160+
QMutexLocker locker( &mMutex );
161+
160162
// If cached, return cached feature
161163
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mCache.find( id );
162164
if ( it != mCache.end() )
@@ -214,9 +216,8 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
214216
{
215217
QVariantMap featureData = featuresData[i].toMap();
216218
QgsFeature feature;
219+
int featureId = startId + i;
217220

218-
// Set FID
219-
feature.setFeatureId( startId + i );
220221

221222
// Set attributes
222223
if ( !fetchAttribIdx.isEmpty() )
@@ -227,10 +228,17 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
227228
foreach ( int idx, fetchAttribIdx )
228229
{
229230
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+
}
230235
}
231236
feature.setAttributes( attributes );
232237
}
233238

239+
// Set FID
240+
feature.setFeatureId( featureId );
241+
234242
// Set geometry
235243
if ( fetchGeometry )
236244
{
@@ -243,9 +251,16 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
243251
feature.setValid( true );
244252
mCache.insert( feature.id(), feature );
245253
}
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;
249264
}
250265

251266
void QgsAfsProvider::setDataSourceUri( const QString &uri )

‎src/providers/arcgisrest/qgsafsprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef QGSAFSPROVIDER_H
1919
#define QGSAFSPROVIDER_H
2020

21+
#include <QMutex>
22+
2123
#include "qgsvectordataprovider.h"
2224
#include "qgsdatasourceuri.h"
2325
#include "qgscoordinatereferencesystem.h"
@@ -69,6 +71,7 @@ class QgsAfsProvider : public QgsVectorDataProvider
6971
void reloadData() override { mCache.clear(); }
7072

7173
private:
74+
QMutex mMutex;
7275
bool mValid;
7376
QgsDataSourceURI mDataSource;
7477
QgsRectangle mExtent;

0 commit comments

Comments
 (0)
Please sign in to comment.