Skip to content

Commit

Permalink
Use TYPENAMES for WFS 2 getFeature
Browse files Browse the repository at this point in the history
Leave both forms for describeFeatureType, fix tests
  • Loading branch information
elpaso committed Jan 25, 2021
1 parent ce1e74e commit 9a75145
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/providers/wfs/qgswfsdescribefeaturetype.cpp
Expand Up @@ -39,13 +39,13 @@ bool QgsWFSDescribeFeatureType::requestFeatureType( const QString &WFSVersion,
query.addQueryItem( QStringLiteral( "NAMESPACES" ), namespaceValue );
}
}
else

// Always add singular form for broken servers (ESRI)
// See: https://github.com/qgis/QGIS/issues/41087
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeName );
if ( !namespaceValue.isEmpty() )
{
query.addQueryItem( QStringLiteral( "TYPENAME" ), typeName );
if ( !namespaceValue.isEmpty() )
{
query.addQueryItem( QStringLiteral( "NAMESPACE" ), namespaceValue );
}
query.addQueryItem( QStringLiteral( "NAMESPACE" ), namespaceValue );
}

url.setQuery( query );
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
38 changes: 20 additions & 18 deletions tests/src/python/test_provider_wfs.py
Expand Up @@ -124,7 +124,7 @@ def setUpClass(cls):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -463,9 +463,6 @@ def testWkbType(self):
"""N/A for WFS provider"""
pass


class TestPyQgsWFSProvider():

def testInconsistentUri(self):
"""Test a URI with a typename that doesn't match a type of the capabilities"""

Expand Down Expand Up @@ -1129,7 +1126,7 @@ def testWFS20Paging(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -1267,7 +1264,7 @@ def testWFS20PagingPageSizeOverride(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -1761,7 +1758,7 @@ def testWFS20TruncatedResponse(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -2069,7 +2066,7 @@ def testJoins(self):
'wb') as f:
f.write(schema.encode('UTF-8'))

with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename,my:othertypename&TYPENAME=my:typename,my:othertypename&SRSNAME=urn:ogc:def:crs:EPSG::4326&FILTER=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">
with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename,my:othertypename&SRSNAME=urn:ogc:def:crs:EPSG::4326&FILTER=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">
<fes:And>
<fes:PropertyIsEqualTo>
<fes:ValueReference>my:typename/id</fes:ValueReference>
Expand Down Expand Up @@ -2195,7 +2192,7 @@ def testJoins(self):
self.assertEqual(fields[0].name(), 'id')

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write(schema.encode('UTF-8'))

Expand Down Expand Up @@ -2414,7 +2411,7 @@ def testFunctionValidation(self):
'wb') as f:
f.write(schema.encode('UTF-8'))
with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write(schema.encode('UTF-8'))

Expand Down Expand Up @@ -2501,7 +2498,7 @@ def testSelectDistinct(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -2626,7 +2623,7 @@ def testWrongCapabilityExtent(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -2745,7 +2742,7 @@ def testGeomedia(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -3020,6 +3017,11 @@ def testDescribeFeatureTypeWithInlineType(self):
""".encode('UTF-8'))

shutil.copyfile(sanitize(endpoint,
"""?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::4326"""),
sanitize(endpoint,
"""?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=1&SRSNAME=urn:ogc:def:crs:EPSG::4326"""))

vl = QgsVectorLayer("url='http://" + endpoint + "' typename='my:typename' version='1.1.0'", 'test', 'WFS')
self.assertTrue(vl.isValid())

Expand Down Expand Up @@ -3063,7 +3065,7 @@ def testWFS20TransactionsDisabled(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -3143,7 +3145,7 @@ def testWFS20TransactionsEnabled(self):
</wfs:WFS_Capabilities>""".format(endpoint=endpoint).encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -3615,7 +3617,7 @@ def testWfs20SamServer(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(
sanitize(endpoint, '?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=EC422'),
sanitize(endpoint, '?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=EC422&TYPENAME=EC422'),
'wb') as f:
f.write("""<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
Expand Down Expand Up @@ -3830,7 +3832,7 @@ def testDescribeFeatureTypeWithSingleInclude(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write(("""
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down Expand Up @@ -4419,7 +4421,7 @@ def testRetryLogicOnExceptionLackOfPrimaryKey(self):
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename'),
'?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAMES=my:typename&TYPENAME=my:typename'),
'wb') as f:
f.write("""
<xsd:schema xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://my">
Expand Down
Binary file not shown.

0 comments on commit 9a75145

Please sign in to comment.