Compare commits

...

2 Commits

Author SHA1 Message Date
Alessandro Pasotti
5f2679c7d0 Push error in case the geometry has Z but the layer has not 2025-07-01 14:43:06 +02:00
Alessandro Pasotti
a933ae8152 Fix comment 2025-07-01 14:26:17 +02:00
4 changed files with 17 additions and 4 deletions

View File

@ -572,8 +572,21 @@ void QgsBackgroundCachedFeatureIterator::featureReceivedSynchronous( const QVect
mWriterStream.reset( new QDataStream( &mWriterByteArray, QIODevice::WriteOnly ) ); mWriterStream.reset( new QDataStream( &mWriterByteArray, QIODevice::WriteOnly ) );
} }
const auto constList = list; const auto constList = list;
const Qgis::WkbType expectedType { mShared->mWKBType };
bool errorRaised = false;
for ( const QgsFeatureUniqueIdPair &pair : constList ) for ( const QgsFeatureUniqueIdPair &pair : constList )
{ {
if ( !errorRaised && expectedType != pair.first.geometry().wkbType() )
{
if ( QgsWkbTypes::hasZ( pair.first.geometry().wkbType() ) && !QgsWkbTypes::hasZ( expectedType ) )
{
mShared->pushError( QStringLiteral( "Received feature geometry has Z values but the layer type (%1) does not. Please check the WFS connection setting 'Force initial GetFeature'." ).arg( QgsWkbTypes::displayString( expectedType ) ) );
}
else
{
mShared->pushError( QStringLiteral( "Received feature with geometry type %1, expected %2" ).arg( QgsWkbTypes::displayString( pair.first.geometry().wkbType() ), QgsWkbTypes::displayString( expectedType ) ) );
}
}
*mWriterStream << pair.first; *mWriterStream << pair.first;
} }
if ( !mWriterFile && mWriterByteArray.size() > mWriteTransferThreshold ) if ( !mWriterFile && mWriterByteArray.size() > mWriteTransferThreshold )

View File

@ -188,6 +188,9 @@ class QgsBackgroundCachedSharedData
//! Called when an error must be raised to the provider //! Called when an error must be raised to the provider
virtual void pushError( const QString &errorMsg ) const = 0; virtual void pushError( const QString &errorMsg ) const = 0;
//! Geometry type of the features in this layer (used by WFS only)
Qgis::WkbType mWKBType = Qgis::WkbType::Unknown;
protected: protected:
//////////// Input members. Implementations should define them to meaningful values //////////// Input members. Implementations should define them to meaningful values

View File

@ -245,7 +245,7 @@ QList<QgsProviderSublayerDetails> QgsWfsProviderMetadata::querySublayers( const
details.setWkbType( provider.wkbType() ); details.setWkbType( provider.wkbType() );
res << details; res << details;
// Always issue a GetFeature because the guessed type can't be trusted, // If set: always issue a GetFeature because the guessed type can't be trusted,
// for example when dealing with Z geometries identified as 2D. // for example when dealing with Z geometries identified as 2D.
const bool forceInitialGetFeature = dsUri.hasParam( QgsWFSConstants::URI_PARAM_FORCE_INITIAL_GET_FEATURE ) const bool forceInitialGetFeature = dsUri.hasParam( QgsWFSConstants::URI_PARAM_FORCE_INITIAL_GET_FEATURE )
&& dsUri.param( QgsWFSConstants::URI_PARAM_FORCE_INITIAL_GET_FEATURE ).toUpper() == QStringLiteral( "TRUE" ); && dsUri.param( QgsWFSConstants::URI_PARAM_FORCE_INITIAL_GET_FEATURE ).toUpper() == QStringLiteral( "TRUE" );

View File

@ -141,9 +141,6 @@ class QgsWFSSharedData : public QObject, public QgsBackgroundCachedSharedData
*/ */
bool mServerPrefersCoordinatesForTransactions_1_1 = false; bool mServerPrefersCoordinatesForTransactions_1_1 = false;
//! Geometry type of the features in this layer
Qgis::WkbType mWKBType = Qgis::WkbType::Unknown;
//! Geometry type filter to ensure geometries returned by the layer are of type mWKBType. //! Geometry type filter to ensure geometries returned by the layer are of type mWKBType.
QString mWFSGeometryTypeFilter; QString mWFSGeometryTypeFilter;