Skip to content

Commit 69c5d8e

Browse files
author
mhugent
committed
Some adjustments in wfs provider and implemented failback method to calculate the layer bounding box if the wfs server does not provide extent information. Fixes bug #1599
git-svn-id: http://svn.osgeo.org/qgis/trunk@10697 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 11ad2a4 commit 69c5d8e

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

src/plugins/wfs/qgswfssourceselect.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ int QgsWFSSourceSelect::getCapabilitiesGET( QString uri, std::list<QString>& typ
167167
{
168168
tname = nameList.at( 0 ).toElement().text();
169169
//strip away namespace prefixes
170-
if ( tname.contains( ":" ) )
170+
/* if ( tname.contains( ":" ) )
171171
{
172172
tname = tname.section( ":", 1, 1 );
173-
}
173+
}*/
174174
}
175175
//Title
176176
QDomNodeList titleList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Title" );

src/providers/wfs/qgswfsdata.cpp

+50-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "qgswfsdata.h"
1616
#include "qgsrectangle.h"
1717
#include "qgscoordinatereferencesystem.h"
18+
#include "qgsgeometry.h"
1819
#include "qgshttptransaction.h"
1920
#include "qgslogger.h"
2021
#include <QBuffer>
@@ -79,6 +80,11 @@ int QgsWFSData::getWFSData()
7980
XML_SetElementHandler( p, QgsWFSData::start, QgsWFSData::end );
8081
XML_SetCharacterDataHandler( p, QgsWFSData::chars );
8182

83+
//start with empty extent
84+
if(mExtent)
85+
{
86+
mExtent->set(0, 0, 0, 0);
87+
}
8288

8389
//separate host from query string
8490
QUrl requestUrl( mUri );
@@ -133,6 +139,15 @@ int QgsWFSData::getWFSData()
133139

134140
delete progressDialog;
135141

142+
if(mExtent)
143+
{
144+
if(mExtent->isEmpty())
145+
{
146+
//reading of bbox from the server failed, so we calculate it less efficiently by evaluating the features
147+
calculateExtentFromFeatures();
148+
}
149+
}
150+
136151
return 0; //soon
137152
}
138153

@@ -159,7 +174,7 @@ void QgsWFSData::handleProgressEvent( int progress, int totalSteps )
159174
void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )
160175
{
161176
QString elementName( el );
162-
QString localName = elementName.section( NS_SEPARATOR, 1, 1 );
177+
QString localName = elementName.section( NS_SEPARATOR, 1, 1 );
163178
if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" )
164179
{
165180
mParseModeStack.push( QgsWFSData::coordinate );
@@ -797,3 +812,37 @@ QWidget* QgsWFSData::findMainWindow() const
797812
}
798813
return mainWindow;
799814
}
815+
816+
void QgsWFSData::calculateExtentFromFeatures() const
817+
{
818+
if(mFeatures.size() < 1)
819+
{
820+
return;
821+
}
822+
823+
QgsRectangle bbox;
824+
825+
QgsFeature* currentFeature = 0;
826+
QgsGeometry* currentGeometry = 0;
827+
for(int i = 0; i < mFeatures.size(); ++i)
828+
{
829+
currentFeature = mFeatures[i];
830+
if(!currentFeature)
831+
{
832+
continue;
833+
}
834+
currentGeometry = currentFeature->geometry();
835+
if(currentGeometry)
836+
{
837+
if(bbox.isEmpty())
838+
{
839+
bbox = currentGeometry->boundingBox();
840+
}
841+
else
842+
{
843+
bbox.unionRect(currentGeometry->boundingBox());
844+
}
845+
}
846+
}
847+
(*mExtent) = bbox;
848+
}

src/providers/wfs/qgswfsdata.h

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class QgsWFSData: public QObject
135135

136136
/**Returns pointer to main window or 0 if it does not exist*/
137137
QWidget* findMainWindow() const;
138+
/**This function evaluates the layer bounding box from the features and sets it to mExtent.
139+
Less efficient compared to reading the bbox from the provider, so it is only done if the wfs server \
140+
does not provider extent information.*/
141+
void calculateExtentFromFeatures() const;
138142

139143
QString mUri;
140144
//results are members such that handler routines are able to manipulate them

0 commit comments

Comments
 (0)