[QGIS Commit] r10697 - in trunk/qgis/src: plugins/wfs providers/wfs

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat May 2 05:00:14 EDT 2009


Author: mhugent
Date: 2009-05-02 05:00:14 -0400 (Sat, 02 May 2009)
New Revision: 10697

Modified:
   trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp
   trunk/qgis/src/providers/wfs/qgswfsdata.cpp
   trunk/qgis/src/providers/wfs/qgswfsdata.h
Log:
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

Modified: trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp
===================================================================
--- trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp	2009-05-02 03:59:09 UTC (rev 10696)
+++ trunk/qgis/src/plugins/wfs/qgswfssourceselect.cpp	2009-05-02 09:00:14 UTC (rev 10697)
@@ -167,10 +167,10 @@
     {
       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" );

Modified: trunk/qgis/src/providers/wfs/qgswfsdata.cpp
===================================================================
--- trunk/qgis/src/providers/wfs/qgswfsdata.cpp	2009-05-02 03:59:09 UTC (rev 10696)
+++ trunk/qgis/src/providers/wfs/qgswfsdata.cpp	2009-05-02 09:00:14 UTC (rev 10697)
@@ -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 @@
   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 @@
 
   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::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 @@
   }
   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;
+}

Modified: trunk/qgis/src/providers/wfs/qgswfsdata.h
===================================================================
--- trunk/qgis/src/providers/wfs/qgswfsdata.h	2009-05-02 03:59:09 UTC (rev 10696)
+++ trunk/qgis/src/providers/wfs/qgswfsdata.h	2009-05-02 09:00:14 UTC (rev 10697)
@@ -135,6 +135,10 @@
 
     /**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



More information about the QGIS-commit mailing list