Skip to content

Commit

Permalink
[ArcGIS REST] backport for crasher and mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 23, 2017
1 parent 10b34b9 commit cfbb5d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/providers/arcgisrest/qgsafsprovider.cpp
Expand Up @@ -157,6 +157,8 @@ QgsFeatureIterator QgsAfsProvider::getFeatures( const QgsFeatureRequest& request

bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fetchGeometry, const QList<int>& /*fetchAttributes*/, const QgsRectangle filterRect )
{
QMutexLocker locker( &mMutex );

// If cached, return cached feature
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mCache.find( id );
if ( it != mCache.end() )
Expand Down Expand Up @@ -214,9 +216,8 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
{
QVariantMap featureData = featuresData[i].toMap();
QgsFeature feature;
int featureId = startId + i;

// Set FID
feature.setFeatureId( startId + i );

// Set attributes
if ( !fetchAttribIdx.isEmpty() )
Expand All @@ -227,10 +228,17 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
foreach ( int idx, fetchAttribIdx )
{
attributes[idx] = attributesData[mFields.at( idx ).name()];
if ( mFields.at( idx ).name() == QStringLiteral( "OBJECTID" ) )
{
featureId = startId + objectIds.indexOf( attributesData[mFields.at( idx ).name()].toInt() );
}
}
feature.setAttributes( attributes );
}

// Set FID
feature.setFeatureId( featureId );

// Set geometry
if ( fetchGeometry )
{
Expand All @@ -243,9 +251,16 @@ bool QgsAfsProvider::getFeature( const QgsFeatureId &id, QgsFeature &f, bool fet
feature.setValid( true );
mCache.insert( feature.id(), feature );
}
f = mCache[id];
Q_ASSERT( f.isValid() );
return filterRect.isNull() || ( f.geometry() && f.geometry()->intersects( filterRect ) );

// If added to cached, return feature
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mCache.find( id );
if ( it != mCache.end() )
{
f = it.value();
return filterRect.isNull() || ( f.geometry() && f.geometry()->intersects( filterRect ) );
}

return false;
}

void QgsAfsProvider::setDataSourceUri( const QString &uri )
Expand Down
3 changes: 3 additions & 0 deletions src/providers/arcgisrest/qgsafsprovider.h
Expand Up @@ -18,6 +18,8 @@
#ifndef QGSAFSPROVIDER_H
#define QGSAFSPROVIDER_H

#include <QMutex>

#include "qgsvectordataprovider.h"
#include "qgsdatasourceuri.h"
#include "qgscoordinatereferencesystem.h"
Expand Down Expand Up @@ -69,6 +71,7 @@ class QgsAfsProvider : public QgsVectorDataProvider
void reloadData() override { mCache.clear(); }

private:
QMutex mMutex;
bool mValid;
QgsDataSourceURI mDataSource;
QgsRectangle mExtent;
Expand Down

0 comments on commit cfbb5d7

Please sign in to comment.