Skip to content
Permalink
Browse files

Some adjustments in wfs provider and implemented failback method to c…

…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
mhugent committed May 2, 2009
1 parent 11ad2a4 commit 69c5d8e032246ac78362fe01e30478046bc38070
Showing with 56 additions and 3 deletions.
  1. +2 −2 src/plugins/wfs/qgswfssourceselect.cpp
  2. +50 −1 src/providers/wfs/qgswfsdata.cpp
  3. +4 −0 src/providers/wfs/qgswfsdata.h
@@ -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" );
@@ -15,6 +15,7 @@
#include "qgswfsdata.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsgeometry.h"
#include "qgshttptransaction.h"
#include "qgslogger.h"
#include <QBuffer>
@@ -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 );
@@ -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
}

@@ -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 );
@@ -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;
}
@@ -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

0 comments on commit 69c5d8e

Please sign in to comment.
You can’t perform that action at this time.