Skip to content

Commit

Permalink
Merge pull request #41169 from elpaso/bugfix-gh41087-wfs-20-typnames-…
Browse files Browse the repository at this point in the history
…esri-bug

Bugfix wfs 2.0 typenames esri bug
  • Loading branch information
elpaso committed Jan 27, 2021
2 parents ead85b1 + 57ebcaf commit ff36aa0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 46 deletions.
14 changes: 13 additions & 1 deletion src/core/providers/ogr/qgsgeopackageproviderconnection.cpp
Expand Up @@ -238,35 +238,43 @@ void QgsGeoPackageProviderConnection::deleteSpatialIndex( const QString &schema,

QList<QgsGeoPackageProviderConnection::TableProperty> QgsGeoPackageProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
{
// List of GPKG quoted system and dummy tables names to be excluded from the tables listing

// List of GPKG quoted system and dummy tables names to be excluded from the tables listing
static const QStringList excludedTableNames { { QStringLiteral( "\"ogr_empty_table\"" ) } };

checkCapability( Capability::Tables );

if ( ! schema.isEmpty() )
{
QgsMessageLog::logMessage( QStringLiteral( "Schema is not supported by GPKG, ignoring" ), QStringLiteral( "OGR" ), Qgis::Info );
}

QList<QgsGeoPackageProviderConnection::TableProperty> tableInfo;
QString errCause;
QList<QVariantList> results;

try
{
const QString sql { QStringLiteral( "SELECT c.table_name, data_type, description, c.srs_id, g.geometry_type_name, g.column_name "
"FROM gpkg_contents c LEFT JOIN gpkg_geometry_columns g ON (c.table_name = g.table_name) "
"WHERE c.table_name NOT IN (%1)" ).arg( excludedTableNames.join( ',' ) ) };
results = executeSql( sql );

for ( const auto &row : qgis::as_const( results ) )
{

if ( row.size() != 6 )
{
throw QgsProviderConnectionException( QObject::tr( "Error listing tables from %1: wrong number of columns returned by query" ).arg( uri() ) );
}

QgsGeoPackageProviderConnection::TableProperty property;
property.setTableName( row.at( 0 ).toString() );
property.setPrimaryKeyColumns( { QStringLiteral( "fid" ) } );
property.setGeometryColumnCount( 0 );
static const QStringList aspatialTypes = { QStringLiteral( "attributes" ), QStringLiteral( "aspatial" ) };
const QString dataType = row.at( 1 ).toString();

// Table type
if ( dataType == QLatin1String( "tiles" ) || dataType == QLatin1String( "2d-gridded-coverage" ) )
{
Expand All @@ -278,6 +286,7 @@ QList<QgsGeoPackageProviderConnection::TableProperty> QgsGeoPackageProviderConne
property.setGeometryColumn( row.at( 5 ).toString() );
property.setGeometryColumnCount( 1 );
}

if ( aspatialTypes.contains( dataType ) )
{
property.setFlag( QgsGeoPackageProviderConnection::Aspatial );
Expand All @@ -287,13 +296,16 @@ QList<QgsGeoPackageProviderConnection::TableProperty> QgsGeoPackageProviderConne
{
bool ok;
int srid = row.at( 3 ).toInt( &ok );

if ( !ok )
{
throw QgsProviderConnectionException( QObject::tr( "Error fetching srs_id table information: %1" ).arg( row.at( 3 ).toString() ) );
}

QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromEpsgId( srid );
property.addGeometryColumnType( QgsWkbTypes::parseType( row.at( 4 ).toString() ), crs );
}

property.setComment( row.at( 4 ).toString() );
tableInfo.push_back( property );
}
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wfs/qgswfsdescribefeaturetype.cpp
Expand Up @@ -40,6 +40,8 @@ bool QgsWFSDescribeFeatureType::requestFeatureType( const QString &WFSVersion,
}
}

// Always add singular form for broken servers
// See: https://github.com/qgis/QGIS/issues/41087
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeName );
if ( !namespaceValue.isEmpty() )
{
Expand Down
7 changes: 6 additions & 1 deletion src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -129,8 +129,13 @@ QUrl QgsWFSFeatureDownloaderImpl::buildURL( qint64 startIndex, int maxFeatures,
}
}
if ( mShared->mWFSVersion.startsWith( QLatin1String( "2.0" ) ) )
{
query.addQueryItem( QStringLiteral( "TYPENAMES" ), typenames );
query.addQueryItem( QStringLiteral( "TYPENAME" ), typenames );
}
else
{
query.addQueryItem( QStringLiteral( "TYPENAME" ), typenames );
}

if ( forHits )
{
Expand Down
18 changes: 14 additions & 4 deletions src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -257,14 +257,22 @@ int QgsWFSFeatureHitsRequest::getFeatureCount( const QString &WFSVersion,
{
query.addQueryItem( QStringLiteral( "TYPENAMES" ), typeName );
}
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeName );
else
{
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeName );
}

QString namespaceValue( caps.getNamespaceParameterValue( WFSVersion, typeName ) );
if ( !namespaceValue.isEmpty() )
{
if ( WFSVersion.startsWith( QLatin1String( "2.0" ) ) )
{
query.addQueryItem( QStringLiteral( "NAMESPACES" ), namespaceValue );
query.addQueryItem( QStringLiteral( "NAMESPACE" ), namespaceValue );
}
else
{
query.addQueryItem( QStringLiteral( "NAMESPACE" ), namespaceValue );
}
}

if ( !filter.isEmpty() )
Expand Down Expand Up @@ -327,14 +335,16 @@ QgsRectangle QgsWFSSingleFeatureRequest::getExtent()
query.addQueryItem( QStringLiteral( "VERSION" ), mShared->mWFSVersion );
if ( mShared->mWFSVersion .startsWith( QLatin1String( "2.0" ) ) )
query.addQueryItem( QStringLiteral( "TYPENAMES" ), mUri.typeName() );
query.addQueryItem( QStringLiteral( "TYPENAME" ), mUri.typeName() );
else
query.addQueryItem( QStringLiteral( "TYPENAME" ), mUri.typeName() );

QString namespaceValue( mShared->mCaps.getNamespaceParameterValue( mShared->mWFSVersion, mUri.typeName() ) );
if ( !namespaceValue.isEmpty() )
{
if ( mShared->mWFSVersion.startsWith( QLatin1String( "2.0" ) ) )
query.addQueryItem( QStringLiteral( "NAMESPACES" ), namespaceValue );
query.addQueryItem( QStringLiteral( "NAMESPACE" ), namespaceValue );
else
query.addQueryItem( QStringLiteral( "NAMESPACE" ), namespaceValue );
}

if ( mShared->mWFSVersion .startsWith( QLatin1String( "2.0" ) ) )
Expand Down

0 comments on commit ff36aa0

Please sign in to comment.