Skip to content

Commit

Permalink
[WFS provider] Use EPSG:XXXX format for SRSNAME= parameter for server…
Browse files Browse the repository at this point in the history
…s that adverize SRS in GetCapabilities response in that format. And also append srsname to value of BBOX parameter
  • Loading branch information
rouault committed Jun 10, 2016
1 parent 734a3a5 commit 08ead81
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/providers/wfs/qgswfscapabilities.cpp
Expand Up @@ -72,6 +72,7 @@ void QgsWFSCapabilities::Capabilities::clear()
setAllTypenames.clear();
mapUnprefixedTypenameToPrefixedTypename.clear();
setAmbiguousUnprefixedTypename.clear();
useEPSGColumnFormat = false;
}

QString QgsWFSCapabilities::Capabilities::addPrefixIfNeeded( const QString& name ) const
Expand Down Expand Up @@ -283,7 +284,11 @@ void QgsWFSCapabilities::capabilitiesReplyFinished()
defaultCRSList = featureTypeElem.elementsByTagName( "DefaultCRS" );
if ( defaultCRSList.length() > 0 )
{
featureType.crslist.append( NormalizeSRSName( defaultCRSList.at( 0 ).toElement().text() ) );
QString srsname( defaultCRSList.at( 0 ).toElement().text() );
// Some servers like Geomedia advertize EPSG:XXXX even in WFS 1.1 or 2.0
if ( srsname.startsWith( "EPSG:" ) )
mCaps.useEPSGColumnFormat = true;
featureType.crslist.append( NormalizeSRSName( srsname ) );
}

//OtherSRS
Expand Down
4 changes: 4 additions & 0 deletions src/providers/wfs/qgswfscapabilities.h
Expand Up @@ -35,6 +35,9 @@ class QgsWFSCapabilities : public QgsWFSRequest
//! description of a vector layer
struct FeatureType
{
//! Default constructor
FeatureType() : insertCap( false ), updateCap( false ), deleteCap( false ) {}

QString name;
QString title;
QString abstract;
Expand Down Expand Up @@ -92,6 +95,7 @@ class QgsWFSCapabilities : public QgsWFSRequest
QList<FeatureType> featureTypes;
QList<Function> spatialPredicatesList;
QList<Function> functionList;
bool useEPSGColumnFormat; // whether to use EPSG:XXXX srsname

QSet< QString > setAllTypenames;
QMap< QString, QString> mapUnprefixedTypenameToPrefixedTypename;
Expand Down
14 changes: 9 additions & 5 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -302,11 +302,15 @@ QUrl QgsWFSFeatureDownloader::buildURL( int startIndex, int maxFeatures, bool fo
{
invertAxis = !invertAxis;
}
getFeatureUrl.addQueryItem( "BBOX", QString(( invertAxis ) ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
.arg( qgsDoubleToString( mShared->mRect.xMinimum() ),
qgsDoubleToString( mShared->mRect.yMinimum() ),
qgsDoubleToString( mShared->mRect.xMaximum() ),
qgsDoubleToString( mShared->mRect.yMaximum() ) ) );
QString bbox( QString(( invertAxis ) ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
.arg( qgsDoubleToString( mShared->mRect.xMinimum() ),
qgsDoubleToString( mShared->mRect.yMinimum() ),
qgsDoubleToString( mShared->mRect.xMaximum() ),
qgsDoubleToString( mShared->mRect.yMaximum() ) ) );
// Some servers like Geomedia need the srsname to be explictly appended
// otherwise they are confused and do not interpret it properly
bbox += "," + mShared->srsName();
getFeatureUrl.addQueryItem( "BBOX", bbox );
}
else if ( !mShared->mWFSFilter.isEmpty() )
{
Expand Down
4 changes: 3 additions & 1 deletion src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -70,7 +70,9 @@ QString QgsWFSSharedData::srsName() const
if ( !mSourceCRS.authid().isEmpty() )
{
if ( mWFSVersion.startsWith( "1.0" ) ||
!mSourceCRS.authid().startsWith( "EPSG:" ) )
!mSourceCRS.authid().startsWith( "EPSG:" ) ||
// For servers like Geomedia that advertize EPSG:XXXX in capabilities even in WFS 1.1 or 2.0
mCaps.useEPSGColumnFormat )
{
srsName = mSourceCRS.authid();
}
Expand Down
14 changes: 7 additions & 7 deletions tests/src/python/test_provider_wfs.py
Expand Up @@ -842,7 +842,7 @@ def testWFSGetOnlyFeaturesInViewExtent(self):
assert vl.isValid()
self.assertEqual(vl.wkbType(), QgsWKBTypes.Point)

last_url = sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=2&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=60,-70,80,-60')
last_url = sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=2&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=60,-70,80,-60,urn:ogc:def:crs:EPSG::4326')
with open(last_url, 'wb') as f:
f.write("""
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs"
Expand Down Expand Up @@ -883,7 +883,7 @@ def testWFSGetOnlyFeaturesInViewExtent(self):
self.assertEqual(values, [2])

# Move to a neighbouring area, and reach the download limit
last_url = sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=2&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=65,-70,90,-60')
last_url = sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=2&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=65,-70,90,-60,urn:ogc:def:crs:EPSG::4326')
with open(last_url, 'wb') as f:
f.write("""
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs"
Expand All @@ -908,7 +908,7 @@ def testWFSGetOnlyFeaturesInViewExtent(self):
self.assertEqual(values, [2, 3])

# Zoom-in again, and bring more features
last_url = sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=2&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=66,-69,89,-61')
last_url = sanitize(endpoint, '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&TYPENAME=my:typename&MAXFEATURES=2&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=66,-69,89,-61,urn:ogc:def:crs:EPSG::4326')
with open(last_url, 'wb') as f:
f.write("""
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs"
Expand Down Expand Up @@ -1823,7 +1823,7 @@ def testWrongCapabilityExtent(self):
assert vl.isValid()

# First request that will be attempted
with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=-0.125,-0.125,1.125,1.125"""), 'wb') as f:
with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::4326&BBOX=-0.125,-0.125,1.125,1.125,urn:ogc:def:crs:EPSG::4326"""), 'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
Expand Down Expand Up @@ -1868,7 +1868,7 @@ def testGeomedia(self):
<Name>my:typename</Name>
<Title>Title</Title>
<Abstract>Abstract</Abstract>
<DefaultCRS>urn:ogc:def:crs:EPSG::32631</DefaultCRS>
<DefaultCRS>EPSG:32631</DefaultCRS>
<ows:WGS84BoundingBox>
<ows:LowerCorner>0 40</ows:LowerCorner>
<ows:UpperCorner>15 50</ows:UpperCorner>
Expand All @@ -1895,7 +1895,7 @@ def testGeomedia(self):
</xsd:schema>
""".encode('UTF-8'))

with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::32631"""), 'wb') as f:
with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&SRSNAME=EPSG:32631"""), 'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
Expand All @@ -1904,7 +1904,7 @@ def testGeomedia(self):
<wfs:member>
<my:typename gml:id="typename.0">
<my:intfield>1</my:intfield>
<my:geometryProperty><gml:Polygon srsName="urn:ogc:def:crs:EPSG::32631" gml:id="typename.geom.0"><gml:exterior><gml:LinearRing><gml:posList>500000 4500000 500000 4510000 510000 4510000 510000 4500000 500000 4500000</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></my:geometryProperty>
<my:geometryProperty><gml:Polygon srsName="EPSG:32631" gml:id="typename.geom.0"><gml:exterior><gml:LinearRing><gml:posList>500000 4500000 500000 4510000 510000 4510000 510000 4500000 500000 4500000</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></my:geometryProperty>
</my:typename>
</wfs:member>
</wfs:FeatureCollection>""".encode('UTF-8'))
Expand Down

0 comments on commit 08ead81

Please sign in to comment.