@@ -488,6 +488,127 @@ def testWFS10(self):
488
488
values = [f ['INTFIELD' ] for f in vl .getFeatures (request )]
489
489
self .assertEqual (values , [100 ])
490
490
491
+ def testWFS10_outputformat_GML3 (self ):
492
+ """Test WFS 1.0 with OUTPUTFORMAT=GML3"""
493
+ # We also test attribute fields in upper-case, and a field named GEOMETRY
494
+
495
+ endpoint = self .__class__ .basetestpath + '/fake_qgis_http_endpoint_WFS1.0_gml3'
496
+
497
+ with open (sanitize (endpoint , '?SERVICE=WFS?REQUEST=GetCapabilities?VERSION=1.0.0' ), 'wb' ) as f :
498
+ f .write ("""
499
+ <WFS_Capabilities version="1.0.0" xmlns="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
500
+ <Capability>
501
+ <Request>
502
+ <GetFeature>
503
+ <ResultFormat>
504
+ <GML2/>
505
+ <GML3/>
506
+ </ResultFormat>
507
+ </GetFeature>
508
+ </Request>
509
+ </Capability>
510
+ <FeatureTypeList>
511
+ <FeatureType>
512
+ <Name>my:typename</Name>
513
+ <Title>Title</Title>
514
+ <Abstract>Abstract</Abstract>
515
+ <SRS>EPSG:32631</SRS>
516
+ <!-- in WFS 1.0, LatLongBoundingBox is in SRS units, not necessarily lat/long... -->
517
+ <LatLongBoundingBox minx="400000" miny="5400000" maxx="450000" maxy="5500000"/>
518
+ </FeatureType>
519
+ </FeatureTypeList>
520
+ </WFS_Capabilities>""" .encode ('UTF-8' ))
521
+
522
+ with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename' ), 'wb' ) as f :
523
+ f .write ("""
524
+ <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">
525
+ <xsd:import namespace="http://www.opengis.net/gml"/>
526
+ <xsd:complexType name="typenameType">
527
+ <xsd:complexContent>
528
+ <xsd:extension base="gml:AbstractFeatureType">
529
+ <xsd:sequence>
530
+ <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>
531
+ </xsd:sequence>
532
+ </xsd:extension>
533
+ </xsd:complexContent>
534
+ </xsd:complexType>
535
+ <xsd:element name="typename" substitutionGroup="gml:_Feature" type="my:typenameType"/>
536
+ </xsd:schema>
537
+ """ .encode ('UTF-8' ))
538
+
539
+ vl = QgsVectorLayer ("url='http://" + endpoint + "' typename='my:typename' version='1.0.0'" , 'test' , 'WFS' )
540
+ assert vl .isValid ()
541
+
542
+ with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:32631&OUTPUTFORMAT=GML3' ), 'wb' ) as f :
543
+ f .write ("""
544
+ <wfs:FeatureCollection
545
+ xmlns:wfs="http://www.opengis.net/wfs"
546
+ xmlns:gml="http://www.opengis.net/gml"
547
+ xmlns:my="http://my">
548
+ <gml:boundedBy><gml:null>unknown</gml:null></gml:boundedBy>
549
+ <gml:featureMember>
550
+ <my:typename fid="typename.0">
551
+ <my:geometry>
552
+ <gml:Point srsName="urn:ogc:def:crs:EPSG::32631"><gml:coordinates decimal="." cs="," ts=" ">426858,5427937</gml:coordinates></gml:Point>
553
+ </my:geometry>
554
+ </my:typename>
555
+ </gml:featureMember>
556
+ </wfs:FeatureCollection>""" .encode ('UTF-8' ))
557
+
558
+ got_f = [f for f in vl .getFeatures ()]
559
+ got = got_f [0 ].geometry ().geometry ()
560
+ self .assertEqual ((got .x (), got .y ()), (426858.0 , 5427937.0 ))
561
+
562
+ # Test with explicit OUTPUTFORMAT as parameter
563
+ vl = QgsVectorLayer ("url='http://" + endpoint + "' typename='my:typename' version='1.0.0' outputformat='GML2'" , 'test' , 'WFS' )
564
+ assert vl .isValid ()
565
+
566
+ with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:32631&OUTPUTFORMAT=GML2' ), 'wb' ) as f :
567
+ f .write ("""
568
+ <wfs:FeatureCollection
569
+ xmlns:wfs="http://www.opengis.net/wfs"
570
+ xmlns:gml="http://www.opengis.net/gml"
571
+ xmlns:my="http://my">
572
+ <gml:boundedBy><gml:null>unknown</gml:null></gml:boundedBy>
573
+ <gml:featureMember>
574
+ <my:typename fid="typename.0">
575
+ <my:geometry>
576
+ <gml:Point srsName="urn:ogc:def:crs:EPSG::32631"><gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates></gml:Point>
577
+ </my:geometry>
578
+ </my:typename>
579
+ </gml:featureMember>
580
+ </wfs:FeatureCollection>""" .encode ('UTF-8' ))
581
+
582
+ got_f = [f for f in vl .getFeatures ()]
583
+ got = got_f [0 ].geometry ().geometry ()
584
+ self .assertEqual ((got .x (), got .y ()), (1.0 , 2.0 ))
585
+
586
+ # Test with explicit OUTPUTFORMAT in URL
587
+ # For some reason this fails on Travis (on assert vl.isValid()) whereas it works locally for me...
588
+ if False :
589
+ vl = QgsVectorLayer ("url='http://" + endpoint + "?OUTPUTFORMAT=GML2' typename='my:typename' version='1.0.0'" , 'test' , 'WFS' )
590
+ assert vl .isValid ()
591
+
592
+ with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:32631&OUTPUTFORMAT=GML2' ), 'wb' ) as f :
593
+ f .write ("""
594
+ <wfs:FeatureCollection
595
+ xmlns:wfs="http://www.opengis.net/wfs"
596
+ xmlns:gml="http://www.opengis.net/gml"
597
+ xmlns:my="http://my">
598
+ <gml:boundedBy><gml:null>unknown</gml:null></gml:boundedBy>
599
+ <gml:featureMember>
600
+ <my:typename fid="typename.0">
601
+ <my:geometry>
602
+ <gml:Point srsName="urn:ogc:def:crs:EPSG::32631"><gml:coordinates decimal="." cs="," ts=" ">3,4</gml:coordinates></gml:Point>
603
+ </my:geometry>
604
+ </my:typename>
605
+ </gml:featureMember>
606
+ </wfs:FeatureCollection>""" .encode ('UTF-8' ))
607
+
608
+ got_f = [f for f in vl .getFeatures ()]
609
+ got = got_f [0 ].geometry ().geometry ()
610
+ self .assertEqual ((got .x (), got .y ()), (3.0 , 4.0 ))
611
+
491
612
def testWFS10_latlongboundingbox_in_WGS84 (self ):
492
613
"""Test WFS 1.0 with non conformatn LatLongBoundingBox"""
493
614
@@ -2362,5 +2483,6 @@ def testWFS20TransactionsEnabled(self):
2362
2483
self .assertNotEqual (vl .dataProvider ().capabilities () & vl .dataProvider ().EditingCapabilities , 0 )
2363
2484
self .assertEqual (vl .wkbType (), QgsWKBTypes .Point )
2364
2485
2486
+
2365
2487
if __name__ == '__main__' :
2366
2488
unittest .main ()
0 commit comments