Skip to content

Commit

Permalink
Some adjustments in wfs provider and implemented failback method to c…
Browse files Browse the repository at this point in the history
…alculate 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
  • Loading branch information
mhugent committed May 2, 2009
1 parent 11ad2a4 commit 69c5d8e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/plugins/wfs/qgswfssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ int QgsWFSSourceSelect::getCapabilitiesGET( QString uri, std::list<QString>& typ
{
tname = nameList.at( 0 ).toElement().text();
//strip away namespace prefixes
if ( tname.contains( ":" ) )
/* if ( tname.contains( ":" ) )
{
tname = tname.section( ":", 1, 1 );
}
}*/
}
//Title
QDomNodeList titleList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Title" );
Expand Down
51 changes: 50 additions & 1 deletion src/providers/wfs/qgswfsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "qgswfsdata.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsgeometry.h"
#include "qgshttptransaction.h"
#include "qgslogger.h"
#include <QBuffer>
Expand Down Expand Up @@ -79,6 +80,11 @@ int QgsWFSData::getWFSData()
XML_SetElementHandler( p, QgsWFSData::start, QgsWFSData::end );
XML_SetCharacterDataHandler( p, QgsWFSData::chars );

//start with empty extent
if(mExtent)
{
mExtent->set(0, 0, 0, 0);
}

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

delete progressDialog;

if(mExtent)
{
if(mExtent->isEmpty())
{
//reading of bbox from the server failed, so we calculate it less efficiently by evaluating the features
calculateExtentFromFeatures();
}
}

return 0; //soon
}

Expand All @@ -159,7 +174,7 @@ void QgsWFSData::handleProgressEvent( int progress, int totalSteps )
void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )
{
QString elementName( el );
QString localName = elementName.section( NS_SEPARATOR, 1, 1 );
QString localName = elementName.section( NS_SEPARATOR, 1, 1 );
if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" )
{
mParseModeStack.push( QgsWFSData::coordinate );
Expand Down Expand Up @@ -797,3 +812,37 @@ QWidget* QgsWFSData::findMainWindow() const
}
return mainWindow;
}

void QgsWFSData::calculateExtentFromFeatures() const
{
if(mFeatures.size() < 1)
{
return;
}

QgsRectangle bbox;

QgsFeature* currentFeature = 0;
QgsGeometry* currentGeometry = 0;
for(int i = 0; i < mFeatures.size(); ++i)
{
currentFeature = mFeatures[i];
if(!currentFeature)
{
continue;
}
currentGeometry = currentFeature->geometry();
if(currentGeometry)
{
if(bbox.isEmpty())
{
bbox = currentGeometry->boundingBox();
}
else
{
bbox.unionRect(currentGeometry->boundingBox());
}
}
}
(*mExtent) = bbox;
}
4 changes: 4 additions & 0 deletions src/providers/wfs/qgswfsdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class QgsWFSData: public QObject

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

QString mUri;
//results are members such that handler routines are able to manipulate them
Expand Down

0 comments on commit 69c5d8e

Please sign in to comment.