Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix wfs 2.0 typenames esri bug #41169

Merged
merged 3 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/core/providers/ogr/qgsgeopackageproviderconnection.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ bool QgsWFSDescribeFeatureType::requestFeatureType( const QString &WFSVersion,
}
}

// Always add singular form for broken servers (ESRI)
elpaso marked this conversation as resolved.
Show resolved Hide resolved
// 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading