Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WFS: emit hint when an axis order issue is likely (fixes #44054)
  • Loading branch information
rouault authored and nyalldawson committed Sep 14, 2021
1 parent 0e2e98b commit 91cdf3a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/providers/wfs/qgsbackgroundcachedshareddata.cpp
Expand Up @@ -770,16 +770,17 @@ void QgsBackgroundCachedSharedData::endOfDownload( bool success, int featureCoun
QgsDebugMsg( QStringLiteral( "Capability extent is probably wrong. Starting a new request with one feature limit to get at least one feature" ) );
mTryFetchingOneFeature = true;
mComputedExtent = getExtentFromSingleFeatureRequest();
if ( !mComputedExtent.isNull() )
if ( !mComputedExtent.isNull() &&
!detectPotentialServerAxisOrderIssueFromSingleFeatureExtent() )
{
// Grow the extent by ~ 50 km (completely arbitrary number if you wonder!)
// so that it is sufficiently zoomed out
if ( mSourceCrs.mapUnits() == QgsUnitTypes::DistanceMeters )
mComputedExtent.grow( 50. * 1000. );
else if ( mSourceCrs.mapUnits() == QgsUnitTypes::DistanceDegrees )
mComputedExtent.grow( 50. / 110 );
QgsMessageLog::logMessage( QObject::tr( "Layer extent reported by the server is not correct. "
"You may need to zoom on layer and then zoom out to see all features" ), mComponentTranslated );
pushError( QObject::tr( "Layer extent reported by the server is not correct. "
"You may need to zoom on layer and then zoom out to see all features" ) );
}
mMutex.unlock();
if ( !mComputedExtent.isNull() )
Expand Down
11 changes: 7 additions & 4 deletions src/providers/wfs/qgsbackgroundcachedshareddata.h
Expand Up @@ -180,7 +180,7 @@ class QgsBackgroundCachedSharedData
virtual QString layerName() const = 0;

//! Called when an error must be raised to the provider
virtual void pushError( const QString &errorMsg ) = 0;
virtual void pushError( const QString &errorMsg ) const = 0;

protected:

Expand All @@ -207,6 +207,9 @@ class QgsBackgroundCachedSharedData
//! Bounding box for the layer as returned by GetCapabilities
QgsRectangle mCapabilityExtent;

//! Extent computed from downloaded features
QgsRectangle mComputedExtent;

//! Flag is a /items request returns a numberMatched property
bool mHasNumberMatched = false;

Expand All @@ -218,6 +221,9 @@ class QgsBackgroundCachedSharedData
//! Should be called in the destructor of the implementation of this class !
void cleanup();

//! Returns true if it is likely that the server doesn't properly honor axis order.
virtual bool detectPotentialServerAxisOrderIssueFromSingleFeatureExtent() const { return false; }

private:

//! Cache directory manager
Expand Down Expand Up @@ -247,9 +253,6 @@ class QgsBackgroundCachedSharedData
*/
int mGenCounter = 0;

//! Extent computed from downloaded features
QgsRectangle mComputedExtent;

//! Spatial index of requested cached regions
QgsSpatialIndex mCachedRegions;

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgsoapifprovider.cpp
Expand Up @@ -587,7 +587,7 @@ bool QgsOapifSharedData::computeServerFilter( QString &errorMsg )
return true;
}

void QgsOapifSharedData::pushError( const QString &errorMsg )
void QgsOapifSharedData::pushError( const QString &errorMsg ) const
{
QgsMessageLog::logMessage( errorMsg, tr( "OAPIF" ) );
emit raiseError( errorMsg );
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wfs/qgsoapifprovider.h
Expand Up @@ -142,7 +142,7 @@ class QgsOapifSharedData final: public QObject, public QgsBackgroundCachedShared
signals:

//! Raise error
void raiseError( const QString &errorMsg );
void raiseError( const QString &errorMsg ) const;

//! Extent has been updated
void extentUpdated();
Expand Down Expand Up @@ -186,7 +186,7 @@ class QgsOapifSharedData final: public QObject, public QgsBackgroundCachedShared
QString &untranslatedPart );

//! Log error to QgsMessageLog and raise it to the provider
void pushError( const QString &errorMsg ) override;
void pushError( const QString &errorMsg ) const override;

void emitExtentUpdated() override { emit extentUpdated(); }

Expand Down
17 changes: 16 additions & 1 deletion src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -182,7 +182,7 @@ bool QgsWFSSharedData::computeFilter( QString &errorMsg )
return true;
}

void QgsWFSSharedData::pushError( const QString &errorMsg )
void QgsWFSSharedData::pushError( const QString &errorMsg ) const
{
QgsMessageLog::logMessage( errorMsg, tr( "WFS" ) );
emit raiseError( errorMsg );
Expand Down Expand Up @@ -237,6 +237,21 @@ int QgsWFSSharedData::getFeatureCountFromServer() const
return request.getFeatureCount( mWFSVersion, mWFSFilter, mCaps );
}

bool QgsWFSSharedData::detectPotentialServerAxisOrderIssueFromSingleFeatureExtent() const
{
Q_ASSERT( !mComputedExtent.isNull() );
if ( mWFSVersion.startsWith( QLatin1String( "1.1" ) ) &&
!mURI.ignoreAxisOrientation() &&
!mURI.invertAxisOrientation() &&
mSourceCrs.hasAxisInverted() &&
mCapabilityExtent.contains( mComputedExtent ) )
{
pushError( QObject::tr( "It is likely that there is an issue with coordinate axis order of geometries when interacting with the server. You may want to enable the Ignore axis orientation and/or Invert axis orientation settings of the WFS connection." ) );
return true;
}
return false;
}

// -------------------------


Expand Down
7 changes: 5 additions & 2 deletions src/providers/wfs/qgswfsshareddata.h
Expand Up @@ -49,7 +49,7 @@ class QgsWFSSharedData : public QObject, public QgsBackgroundCachedSharedData
signals:

//! Raise error
void raiseError( const QString &errorMsg );
void raiseError( const QString &errorMsg ) const;

//! Extent has been updated
void extentUpdated();
Expand Down Expand Up @@ -100,6 +100,9 @@ class QgsWFSSharedData : public QObject, public QgsBackgroundCachedSharedData
//! Create GML parser
QgsGmlStreamingParser *createParser() const;

//! Returns true if it is likely that the server doesn't properly honor axis order.
bool detectPotentialServerAxisOrderIssueFromSingleFeatureExtent() const override;

private:

//! WFS filter
Expand All @@ -109,7 +112,7 @@ class QgsWFSSharedData : public QObject, public QgsBackgroundCachedSharedData
QString mSortBy;

//! Log error to QgsMessageLog and raise it to the provider
void pushError( const QString &errorMsg ) override;
void pushError( const QString &errorMsg ) const override;

void emitExtentUpdated() override { emit extentUpdated(); }

Expand Down

0 comments on commit 91cdf3a

Please sign in to comment.