Skip to content

Commit 4bcbc1e

Browse files
committedAug 8, 2016
[WFS provider] Succesfully analyze DescribeFeatureType response with <complexType> as inline element of <element> (#15395)
1 parent 23c83b1 commit 4bcbc1e

File tree

2 files changed

+110
-13
lines changed

2 files changed

+110
-13
lines changed
 

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,17 +1161,23 @@ bool QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc,
11611161
// collect the correspond type.
11621162
QDomElement elementElement = schemaElement.firstChildElement( "element" );
11631163
QString elementTypeString;
1164+
QDomElement complexTypeElement;
11641165
while ( !elementElement.isNull() )
11651166
{
11661167
QString name = elementElement.attribute( "name" );
11671168
if ( name == unprefixedTypename )
11681169
{
11691170
elementTypeString = elementElement.attribute( "type" );
1171+
if ( elementTypeString.isEmpty() )
1172+
{
1173+
// e.g http://afnemers.ruimtelijkeplannen.nl/afnemers2012/services?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAME=app:Bouwvlak
1174+
complexTypeElement = elementElement.firstChildElement( "complexType" );
1175+
}
11701176
break;
11711177
}
11721178
elementElement = elementElement.nextSiblingElement( "element" );
11731179
}
1174-
if ( elementTypeString.isEmpty() )
1180+
if ( elementTypeString.isEmpty() && complexTypeElement.isNull() )
11751181
{
11761182
// "http://demo.deegree.org/inspire-workspace/services/wfs?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAME=ad:Address"
11771183
QDomElement iter = schemaElement.firstChildElement();
@@ -1206,21 +1212,24 @@ bool QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc,
12061212
elementTypeString = elementTypeString.section( ':', 1 );
12071213
}
12081214

1209-
//the <complexType> element corresponding to the feature type
1210-
QDomElement complexTypeElement = schemaElement.firstChildElement( "complexType" );
1211-
while ( !complexTypeElement.isNull() )
1215+
if ( complexTypeElement.isNull() )
12121216
{
1213-
QString name = complexTypeElement.attribute( "name" );
1214-
if ( name == elementTypeString )
1217+
//the <complexType> element corresponding to the feature type
1218+
complexTypeElement = schemaElement.firstChildElement( "complexType" );
1219+
while ( !complexTypeElement.isNull() )
12151220
{
1216-
break;
1221+
QString name = complexTypeElement.attribute( "name" );
1222+
if ( name == elementTypeString )
1223+
{
1224+
break;
1225+
}
1226+
complexTypeElement = complexTypeElement.nextSiblingElement( "complexType" );
1227+
}
1228+
if ( complexTypeElement.isNull() )
1229+
{
1230+
errorMsg = tr( "Cannot find ComplexType element '%1'" ).arg( elementTypeString );
1231+
return false;
12171232
}
1218-
complexTypeElement = complexTypeElement.nextSiblingElement( "complexType" );
1219-
}
1220-
if ( complexTypeElement.isNull() )
1221-
{
1222-
errorMsg = tr( "Cannot find ComplexType element '%1'" ).arg( elementTypeString );
1223-
return false;
12241233
}
12251234

12261235
//we have the relevant <complexType> element. Now find out the geometry and the thematic attributes

‎tests/src/python/test_provider_wfs.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,94 @@ def testMapServerWFS1_1_EPSG_4326(self):
21022102
</gml:featureMember>
21032103
</wfs:FeatureCollection>
21042104
2105+
""".encode('UTF-8'))
2106+
2107+
vl = QgsVectorLayer(u"url='http://" + endpoint + u"' typename='my:typename' version='1.1.0'", u'test', u'WFS')
2108+
assert vl.isValid()
2109+
2110+
got_f = [f for f in vl.getFeatures()]
2111+
got = got_f[0].geometry().geometry()
2112+
self.assertEqual((got.x(), got.y()), (2.0, 49.0))
2113+
2114+
def testDescribeFeatureTypeWithInlineType(self):
2115+
"""Test a DescribeFeatureType response with a inline ComplexType (#15395)."""
2116+
2117+
endpoint = self.__class__.basetestpath + '/fake_qgis_http_endpoint_testDescribeFeatureTypeWithInlineType'
2118+
2119+
with open(sanitize(endpoint, '?SERVICE=WFS?REQUEST=GetCapabilities?VERSION=1.1.0'), 'wb') as f:
2120+
f.write("""
2121+
<wfs:WFS_Capabilities version="1.1.0" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://schemas.opengis.net/gml">
2122+
<FeatureTypeList>
2123+
<FeatureType>
2124+
<Name>my:typename</Name>
2125+
<Title>Title</Title>
2126+
<Abstract>Abstract</Abstract>
2127+
<DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
2128+
<ows:WGS84BoundingBox>
2129+
<ows:LowerCorner>2 49</ows:LowerCorner>
2130+
<ows:UpperCorner>2 49</ows:UpperCorner>
2131+
</ows:WGS84BoundingBox>
2132+
</FeatureType>
2133+
</FeatureTypeList>
2134+
</wfs:WFS_Capabilities>""".encode('UTF-8'))
2135+
2136+
with open(sanitize(endpoint, '?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.1.0&TYPENAME=my:typename'), 'wb') as f:
2137+
f.write("""
2138+
<schema
2139+
targetNamespace="http://my"
2140+
xmlns:my="http://my"
2141+
xmlns:ogc="http://www.opengis.net/ogc"
2142+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2143+
xmlns="http://www.w3.org/2001/XMLSchema"
2144+
xmlns:gml="http://www.opengis.net/gml"
2145+
elementFormDefault="qualified" version="0.1" >
2146+
<import namespace="http://www.opengis.net/gml"
2147+
schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd" />
2148+
<element name="typename"
2149+
substitutionGroup="gml:_Feature">
2150+
<complexType>
2151+
<complexContent>
2152+
<extension base="gml:AbstractFeatureType">
2153+
<sequence>
2154+
<element name="geometryProperty" type="gml:GeometryPropertyType" minOccurs="0" maxOccurs="1"/>
2155+
</sequence>
2156+
</extension>
2157+
</complexContent>
2158+
</complexType>
2159+
</element>
2160+
</schema>
2161+
""".encode('UTF-8'))
2162+
2163+
with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::4326"""), 'wb') as f:
2164+
f.write("""
2165+
<wfs:FeatureCollection
2166+
xmlns:my="http://my"
2167+
xmlns:gml="http://www.opengis.net/gml"
2168+
xmlns:wfs="http://www.opengis.net/wfs"
2169+
xmlns:ogc="http://www.opengis.net/ogc">
2170+
<gml:boundedBy>
2171+
<gml:Envelope srsName="EPSG:4326">
2172+
<gml:lowerCorner>49.000000 2.000000</gml:lowerCorner>
2173+
<gml:upperCorner>49.000000 2.000000</gml:upperCorner>
2174+
</gml:Envelope>
2175+
</gml:boundedBy>
2176+
<gml:featureMember>
2177+
<my:typename gml:id="typename.1">
2178+
<gml:boundedBy>
2179+
<gml:Envelope srsName="EPSG:4326">
2180+
<gml:lowerCorner>49.000000 2.000000</gml:lowerCorner>
2181+
<gml:upperCorner>49.000000 2.000000</gml:upperCorner>
2182+
</gml:Envelope>
2183+
</gml:boundedBy>
2184+
<my:geometryProperty>
2185+
<gml:Point srsName="EPSG:4326">
2186+
<gml:pos>49.000000 2.000000</gml:pos>
2187+
</gml:Point>
2188+
</my:geometryProperty>
2189+
</my:typename>
2190+
</gml:featureMember>
2191+
</wfs:FeatureCollection>
2192+
21052193
""".encode('UTF-8'))
21062194

21072195
vl = QgsVectorLayer(u"url='http://" + endpoint + u"' typename='my:typename' version='1.1.0'", u'test', u'WFS')

0 commit comments

Comments
 (0)
Please sign in to comment.