Skip to content

Commit

Permalink
[WFS provider] Add a new test for a layer of geometry type Unknown, w…
Browse files Browse the repository at this point in the history
…hose GetFeature COUNT=1 request without BBOX returns a null geometry, but with a BBOX returns a non-null geometry
  • Loading branch information
rouault authored and nyalldawson committed Nov 18, 2022
1 parent dc85a1f commit c264204
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion tests/src/python/test_provider_wfs.py
Expand Up @@ -5332,6 +5332,21 @@ def testLayerWithGeometryFieldButNoGeom(self):
</xsd:schema>
""".encode('UTF-8'))

with open(sanitize(endpoint,
"""?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&COUNT=1&SRSNAME=urn:ogc:def:crs:EPSG::4326"""),
'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:my="http://my">
<wfs:member>
<my:typename gml:id="typename.0">
<my:intfield>1</my:intfield>
</my:typename>
</wfs:member>
</wfs:FeatureCollection>""".encode('UTF-8'))

with open(sanitize(endpoint,
"""?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&COUNT=1&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=-90,-180,90,180,urn:ogc:def:crs:EPSG::4326"""),
'wb') as f:
Expand All @@ -5342,6 +5357,54 @@ def testLayerWithGeometryFieldButNoGeom(self):
xmlns:my="http://my">
</wfs:FeatureCollection>""".encode('UTF-8'))

vl = QgsVectorLayer(
"url='http://" + endpoint + "' typename='my:typename' version='2.0.0'",
'test', 'WFS')
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.NoGeometry)

def testLayerWithGeometryFieldButInitialFeatureHasNoGeom(self):
""" https://github.com/qgis/QGIS/pull/50237 """

endpoint = self.__class__.basetestpath + '/fake_qgis_http_endpoint_layer_with_geometry_field_but_initial_filter_has_no_geom'

with open(sanitize(endpoint, '?SERVICE=WFS?REQUEST=GetCapabilities?VERSION=2.0.0'), 'wb') as f:
f.write("""
<wfs:WFS_Capabilities version="2.0.0" xmlns="http://www.opengis.net/wfs/2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://schemas.opengis.net/gml/3.2" xmlns:fes="http://www.opengis.net/fes/2.0">
<FeatureTypeList>
<FeatureType>
<Name>my:typename</Name>
<Title>Title</Title>
<Abstract>Abstract</Abstract>
<DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
<WGS84BoundingBox>
<LowerCorner>-71.123 66.33</LowerCorner>
<UpperCorner>-65.32 78.3</UpperCorner>
</WGS84BoundingBox>
</FeatureType>
</FeatureTypeList>
</wfs:WFS_Capabilities>""".encode('UTF-8'))

with open(sanitize(endpoint,
'?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">
<xsd:import namespace="http://www.opengis.net/gml"/>
<xsd:complexType name="typenameType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="intfield" nillable="true" type="xsd:int"/>
<xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:GeometryPropertyType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="typename" substitutionGroup="gml:_Feature" type="my:typenameType"/>
</xsd:schema>
""".encode('UTF-8'))

with open(sanitize(endpoint,
"""?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&COUNT=1&SRSNAME=urn:ogc:def:crs:EPSG::4326"""),
'wb') as f:
Expand All @@ -5357,11 +5420,27 @@ def testLayerWithGeometryFieldButNoGeom(self):
</wfs:member>
</wfs:FeatureCollection>""".encode('UTF-8'))

with open(sanitize(endpoint,
"""?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&COUNT=1&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=-90,-180,90,180,urn:ogc:def:crs:EPSG::4326"""),
'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:my="http://my">
<wfs:member>
<my:typename gml:id="typename.0">
<my:intfield>2</my:intfield>
<my:geometry><gml:Point srsName="urn:ogc:def:crs:EPSG::4326" gml:id="typename.geom.0"><gml:pos>78.3 -65.32</gml:pos></gml:Point></my:geometry>
</my:typename>
</wfs:member>
</wfs:FeatureCollection>""".encode('UTF-8'))

vl = QgsVectorLayer(
"url='http://" + endpoint + "' typename='my:typename' version='2.0.0'",
'test', 'WFS')
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.NoGeometry)
self.assertEqual(vl.wkbType(), QgsWkbTypes.Point)

def testLayerWithFieldsInGMLNamespace(self):
""" https://github.com/qgis/QGIS/issues/42660 """
Expand Down

0 comments on commit c264204

Please sign in to comment.