@@ -369,8 +369,9 @@ def testWFS10(self):
369369 <Name>my:typename</Name>
370370 <Title>Title</Title>
371371 <Abstract>Abstract</Abstract>
372- <SRS>EPSG:4326</SRS>
373- <LatLongBoundingBox minx="-71.123" miny="66.33" maxx="-65.32" maxy="78.3"/>
372+ <SRS>EPSG:32631</SRS>
373+ <!-- in WFS 1.0, LatLongBoundingBox is in SRS units, not necessarily lat/long... -->
374+ <LatLongBoundingBox minx="400000" miny="5400000" maxx="450000" maxy="5500000"/>
374375 </FeatureType>
375376 </FeatureTypeList>
376377</WFS_Capabilities>""" .encode ('UTF-8' ))
@@ -402,11 +403,11 @@ def testWFS10(self):
402403 self .assertEqual (vl .wkbType (), QgsWKBTypes .Point )
403404 self .assertEqual (len (vl .fields ()), 5 )
404405 self .assertEqual (vl .featureCount (), 0 )
405- reference = QgsGeometry .fromRect (QgsRectangle (- 71.123 , 66.33 , - 65.32 , 78.3 ))
406+ reference = QgsGeometry .fromRect (QgsRectangle (400000.0 , 5400000.0 , 450000.0 , 5500000.0 ))
406407 vl_extent = QgsGeometry .fromRect (vl .extent ())
407408 assert QgsGeometry .compare (vl_extent .asPolygon ()[0 ], reference .asPolygon ()[0 ], 0.00001 ), 'Expected {}, got {}' .format (reference .exportToWkt (), vl_extent .exportToWkt ())
408409
409- with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:4326 ' ), 'wb' ) as f :
410+ with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:32631 ' ), 'wb' ) as f :
410411 f .write ("""
411412<wfs:FeatureCollection
412413 xmlns:wfs="http://www.opengis.net/wfs"
@@ -416,7 +417,7 @@ def testWFS10(self):
416417 <gml:featureMember>
417418 <my:typename fid="typename.0">
418419 <my:geometryProperty>
419- <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"><gml:coordinates decimal="." cs="," ts=" ">2,49 </gml:coordinates></gml:Point></my:geometryProperty>
420+ <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"><gml:coordinates decimal="." cs="," ts=" ">426858,5427937 </gml:coordinates></gml:Point></my:geometryProperty>
420421 <my:INTFIELD>1</my:INTFIELD>
421422 <my:GEOMETRY>2</my:GEOMETRY>
422423 <my:longfield>1234567890123</my:longfield>
@@ -448,7 +449,7 @@ def testWFS10(self):
448449
449450 got_f = [f for f in vl .getFeatures ()]
450451 got = got_f [0 ].geometry ().geometry ()
451- self .assertEqual ((got .x (), got .y ()), (2 .0 , 49 .0 ))
452+ self .assertEqual ((got .x (), got .y ()), (426858 .0 , 5427937 .0 ))
452453
453454 self .assertEqual (vl .featureCount (), 1 )
454455
@@ -459,6 +460,51 @@ def testWFS10(self):
459460
460461 assert not vl .dataProvider ().deleteFeatures ([0 ])
461462
463+ def testWFS10_latlongboundingbox_in_WGS84 (self ):
464+ """Test WFS 1.0 with non conformatn LatLongBoundingBox"""
465+
466+ endpoint = self .__class__ .basetestpath + '/fake_qgis_http_endpoint_WFS1.0_latlongboundingbox_in_WGS84'
467+
468+ with open (sanitize (endpoint , '?SERVICE=WFS?REQUEST=GetCapabilities?VERSION=1.0.0' ), 'wb' ) as f :
469+ f .write ("""
470+ <WFS_Capabilities version="1.0.0" xmlns="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
471+ <FeatureTypeList>
472+ <FeatureType>
473+ <Name>my:typename</Name>
474+ <Title>Title</Title>
475+ <Abstract>Abstract</Abstract>
476+ <SRS>EPSG:32631</SRS>
477+ <!-- in WFS 1.0, LatLongBoundingBox are supposed to be in SRS units, not necessarily lat/long...
478+ But some servers do not honour this, so let's try to be robust -->
479+ <LatLongBoundingBox minx="1.63972075372399" miny="48.7449841112119" maxx="2.30733562794991" maxy="49.6504711179582"/>
480+ </FeatureType>
481+ </FeatureTypeList>
482+ </WFS_Capabilities>""" .encode ('UTF-8' ))
483+
484+ with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename' ), 'wb' ) as f :
485+ f .write ("""
486+ <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">
487+ <xsd:import namespace="http://www.opengis.net/gml"/>
488+ <xsd:complexType name="typenameType">
489+ <xsd:complexContent>
490+ <xsd:extension base="gml:AbstractFeatureType">
491+ <xsd:sequence>
492+ <xsd:element maxOccurs="1" minOccurs="0" name="geometryProperty" nillable="true" type="gml:PointPropertyType"/>
493+ </xsd:sequence>
494+ </xsd:extension>
495+ </xsd:complexContent>
496+ </xsd:complexType>
497+ <xsd:element name="typename" substitutionGroup="gml:_Feature" type="my:typenameType"/>
498+ </xsd:schema>
499+ """ .encode ('UTF-8' ))
500+
501+ vl = QgsVectorLayer (u"url='http://" + endpoint + u"' typename='my:typename' version='1.0.0'" , u'test' , u'WFS' )
502+ assert vl .isValid ()
503+
504+ reference = QgsGeometry .fromRect (QgsRectangle (399999.9999999680439942 ,5399338.9090830031782389 ,449999.9999999987776391 ,5500658.0448500607162714 ))
505+ vl_extent = QgsGeometry .fromRect (vl .extent ())
506+ assert QgsGeometry .compare (vl_extent .asPolygon ()[0 ], reference .asPolygon ()[0 ], 0.00001 ), 'Expected {}, got {}' .format (reference .exportToWkt (), vl_extent .exportToWkt ())
507+
462508 def testWFST10 (self ):
463509 """Test WFS-T 1.0 (read-write)"""
464510
@@ -1959,14 +2005,19 @@ def testGeomedia(self):
19592005 assert vl .isValid ()
19602006 self .assertEqual (vl .wkbType (), QgsWKBTypes .MultiPolygon )
19612007
2008+ # Extent before downloading features
2009+ reference = QgsGeometry .fromRect (QgsRectangle (243900.3520259926444851 ,4427769.1559739429503679 ,1525592.3040170343592763 ,5607994.6020106188952923 ))
2010+ vl_extent = QgsGeometry .fromRect (vl .extent ())
2011+ assert QgsGeometry .compare (vl_extent .asPolygon ()[0 ], reference .asPolygon ()[0 ], 0.00001 ), 'Expected {}, got {}' .format (reference .exportToWkt (), vl_extent .exportToWkt ())
2012+
19622013 # Download all features
19632014 features = [f for f in vl .getFeatures ()]
19642015 self .assertEqual (len (features ), 2 )
19652016
19662017 reference = QgsGeometry .fromRect (QgsRectangle (500000 , 4500000 , 510000 , 4510000 ))
19672018 vl_extent = QgsGeometry .fromRect (vl .extent ())
1968- self .assertEqual (features [0 ]['intfield' ], 1 )
19692019 assert QgsGeometry .compare (vl_extent .asPolygon ()[0 ], reference .asPolygon ()[0 ], 0.00001 ), 'Expected {}, got {}' .format (reference .exportToWkt (), vl_extent .exportToWkt ())
2020+ self .assertEqual (features [0 ]['intfield' ], 1 )
19702021 self .assertEqual (features [1 ]['intfield' ], 2 )
19712022
19722023
0 commit comments