[QGIS Commit] r10866 - trunk/qgis/src/providers/wfs

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun May 31 03:43:16 EDT 2009


Author: mhugent
Date: 2009-05-31 03:43:15 -0400 (Sun, 31 May 2009)
New Revision: 10866

Modified:
   trunk/qgis/src/providers/wfs/qgswfsdata.cpp
   trunk/qgis/src/providers/wfs/qgswfsdata.h
   trunk/qgis/src/providers/wfs/qgswfsprovider.cpp
Log:
Improved handling of attribute types in WFS provider

Modified: trunk/qgis/src/providers/wfs/qgswfsdata.cpp
===================================================================
--- trunk/qgis/src/providers/wfs/qgswfsdata.cpp	2009-05-30 22:17:14 UTC (rev 10865)
+++ trunk/qgis/src/providers/wfs/qgswfsdata.cpp	2009-05-31 07:43:15 UTC (rev 10866)
@@ -36,7 +36,7 @@
   QgsCoordinateReferenceSystem* srs,
   QList<QgsFeature*> &features,
   const QString& geometryAttribute,
-  const QSet<QString>& thematicAttributes,
+  const QMap<QString, QPair<int, QgsField> >& thematicAttributes,
   QGis::WkbType* wkbType )
     : QObject(),
     mUri( uri ),
@@ -193,7 +193,6 @@
   else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "featureMember" )
   {
     mCurrentFeature = new QgsFeature( mFeatureCount );
-    mAttributeIndex = 0;
     mParseModeStack.push( QgsWFSData::featureMember );
   }
   else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "Box" && mParseModeStack.top() == QgsWFSData::boundingBox )
@@ -262,15 +261,35 @@
       mParseModeStack.pop();
     }
   }
-  else if ( localName == mAttributeName )
+  else if ( localName == mAttributeName ) //add a thematic attribute to the feature
   {
     if ( !mParseModeStack.empty() )
     {
       mParseModeStack.pop();
     }
 
-    mCurrentFeature->addAttribute( mAttributeIndex, QVariant( mStringCash ) );
-    ++mAttributeIndex;
+    //find index with attribute name
+    QMap<QString, QPair<int, QgsField> >::const_iterator att_it = mThematicAttributes.find(mAttributeName);
+    if(att_it != mThematicAttributes.constEnd())
+    {
+      QVariant var;
+      switch(att_it.value().second.type())
+      {
+        case QVariant::Double:
+          var = QVariant(mStringCash.toDouble());
+          break;
+        case QVariant::Int:
+          var = QVariant(mStringCash.toInt());
+          break;
+        case QVariant::LongLong:
+          var = QVariant(mStringCash.toLongLong());
+          break;
+        default: //string type is default
+          var = QVariant( mStringCash );
+          break;
+      }
+       mCurrentFeature->addAttribute(att_it.value().first, QVariant( mStringCash ));
+    }
   }
   else if ( localName == mGeometryAttribute )
   {

Modified: trunk/qgis/src/providers/wfs/qgswfsdata.h
===================================================================
--- trunk/qgis/src/providers/wfs/qgswfsdata.h	2009-05-30 22:17:14 UTC (rev 10865)
+++ trunk/qgis/src/providers/wfs/qgswfsdata.h	2009-05-31 07:43:15 UTC (rev 10866)
@@ -21,6 +21,7 @@
 #include "qgsapplication.h"
 #include "qgsdataprovider.h"
 #include "qgsfeature.h"
+#include "qgsfield.h"
 #include "qgspoint.h"
 #include <list>
 #include <set>
@@ -40,7 +41,7 @@
       QgsCoordinateReferenceSystem* srs,
       QList<QgsFeature*> &features,
       const QString& geometryAttribute,
-      const QSet<QString>& thematicAttributes,
+      const QMap<QString, QPair<int, QgsField> >& thematicAttributes,
       QGis::WkbType* wkbType );
     ~QgsWFSData();
 
@@ -150,7 +151,7 @@
     QList<QgsFeature*> &mFeatures;
     /**Name of geometry attribute*/
     QString mGeometryAttribute;
-    const QSet<QString> &mThematicAttributes;
+    const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
     QGis::WkbType* mWkbType;
     /**True if the request is finished*/
     bool mFinished;
@@ -171,8 +172,6 @@
     /**Similar to mCurrentWKB, but only the size*/
     std::list< std::list<int> > mCurrentWKBFragmentSizes;
     QString mAttributeName;
-    /**Index where the current attribute should be inserted*/
-    int mAttributeIndex;
     QString mTypeName;
     QgsApplication::endian_t mEndian;
     /**Coordinate separator for coordinate strings. Usually "," */

Modified: trunk/qgis/src/providers/wfs/qgswfsprovider.cpp
===================================================================
--- trunk/qgis/src/providers/wfs/qgswfsprovider.cpp	2009-05-30 22:17:14 UTC (rev 10865)
+++ trunk/qgis/src/providers/wfs/qgswfsprovider.cpp	2009-05-31 07:43:15 UTC (rev 10866)
@@ -234,7 +234,7 @@
 
 int QgsWFSProvider::getFeatureGET( const QString& uri, const QString& geometryAttribute )
 {
-#if 0
+#if 0 //the old and slower method with DOM
   //assemble request string
   QString request = uri /*+ "&OUTPUTFORMAT=gml3"*/; //use gml2 as it is supported by most wfs servers
   QByteArray result;
@@ -265,11 +265,13 @@
   return 0;
 #endif
 
-  //the new and faster method with the expat parser
-  QSet<QString> thematicAttributes;
+  //the new and faster method with the expat SAX parser
+
+  //allows fast searchings with attribute name. Also needed is attribute Index and type infos
+  QMap<QString, QPair<int, QgsField> > thematicAttributes;
   for ( QgsFieldMap::const_iterator it = mFields.begin(); it != mFields.end(); ++it )
   {
-    thematicAttributes << it->name();
+    thematicAttributes.insert(it.value().name(), qMakePair(it.key(), it.value()));
   }
 
   QgsWFSData dataReader( uri, &mExtent, &mSourceCRS, mFeatures, geometryAttribute, thematicAttributes, &mWKBType );
@@ -512,7 +514,20 @@
     }
     else //todo: distinguish between numerical and non-numerical types
     {
-      fields[fields.size()] = QgsField( name, QVariant::String, type );
+      QVariant::Type  attributeType = QVariant::String; //string is default type
+      if(type.contains("double", Qt::CaseInsensitive) || type.contains("float", Qt::CaseInsensitive))
+      {
+        attributeType = QVariant::Double;
+      }
+      else if(type.contains("int", Qt::CaseInsensitive))
+      {
+        attributeType = QVariant::Int;
+      }
+      else if(type.contains("long", Qt::CaseInsensitive))
+      {
+        attributeType = QVariant::LongLong;
+      }
+      fields[fields.size()] = QgsField( name, attributeType, type );
     }
   }
   return 0;



More information about the QGIS-commit mailing list