Quantum GIS API Documentation  master-7dce617
src/core/qgswfsdata.h
Go to the documentation of this file.
00001 /***************************************************************************
00002      qgswfsdata.h
00003      --------------------------------------
00004     Date                 : Sun Sep 16 12:19:55 AKDT 2007
00005     Copyright            : (C) 2007 by Gary E. Sherman
00006     Email                : sherman at mrcc dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #ifndef QGSWFSDATA_H
00016 #define QGSWFSDATA_H
00017 
00018 #include <expat.h>
00019 #include "qgis.h"
00020 #include "qgsapplication.h"
00021 #include "qgsdataprovider.h"
00022 #include "qgsfeature.h"
00023 #include "qgsfield.h"
00024 #include "qgspoint.h"
00025 #include <list>
00026 #include <set>
00027 #include <stack>
00028 #include <QPair>
00029 class QgsRectangle;
00030 class QgsCoordinateReferenceSystem;
00031 
00032 
00034 class CORE_EXPORT QgsWFSData: public QObject
00035 {
00036     Q_OBJECT
00037   public:
00046     QgsWFSData(
00047       const QString& uri,
00048       QgsRectangle* extent,
00049       QMap<QgsFeatureId, QgsFeature* > &features,
00050       QMap<QgsFeatureId, QString > &idMap,
00051       const QString& geometryAttribute,
00052       const QMap<QString, QPair<int, QgsField> >& thematicAttributes,
00053       QGis::WkbType* wkbType );
00054     ~QgsWFSData();
00055 
00058     int getWFSData();
00059 
00060   private slots:
00061     void setFinished();
00062 
00064     void handleProgressEvent( qint64 progress, qint64 totalSteps );
00065 
00066   signals:
00067     void dataReadProgress( int progress );
00068     void totalStepsUpdate( int totalSteps );
00069     //also emit signal with progress and totalSteps together (this is better for the status message)
00070     void dataProgressAndSteps( int progress, int totalSteps );
00071 
00072   private:
00073 
00074     enum parseMode
00075     {
00076       boundingBox,
00077       featureMember,
00078       attribute,
00079       geometry,
00080       coordinate,
00081       point,
00082       line,
00083       polygon,
00084       multiPoint,
00085       multiLine,
00086       multiPolygon
00087     };
00088 
00089     QgsWFSData();
00090 
00092     void startElement( const XML_Char* el, const XML_Char** attr );
00093     void endElement( const XML_Char* el );
00094     void characters( const XML_Char* chars, int len );
00095     static void start( void* data, const XML_Char* el, const XML_Char** attr )
00096     {
00097       static_cast<QgsWFSData*>( data )->startElement( el, attr );
00098     }
00099     static void end( void* data, const XML_Char* el )
00100     {
00101       static_cast<QgsWFSData*>( data )->endElement( el );
00102     }
00103     static void chars( void* data, const XML_Char* chars, int len )
00104     {
00105       static_cast<QgsWFSData*>( data )->characters( chars, len );
00106     }
00107 
00108     //helper routines
00113     int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const;
00118     QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
00121     int createBBoxFromCoordinateString( QgsRectangle* bb, const QString& coordString ) const;
00126     int pointsFromCoordinateString( std::list<QgsPoint>& points, const QString& coordString ) const;
00127 
00128     int getPointWKB( unsigned char** wkb, int* size, const QgsPoint& ) const;
00129     int getLineWKB( unsigned char** wkb, int* size, const std::list<QgsPoint>& lineCoordinates ) const;
00130     int getRingWKB( unsigned char** wkb, int* size, const std::list<QgsPoint>& ringCoordinates ) const;
00132     int createMultiLineFromFragments();
00133     int createMultiPointFromFragments();
00134     int createPolygonFromFragments();
00135     int createMultiPolygonFromFragments();
00137     int totalWKBFragmentSize() const;
00138 
00140     QWidget* findMainWindow() const;
00144     void calculateExtentFromFeatures() const;
00145 
00146     QString mUri;
00147     //results are members such that handler routines are able to manipulate them
00149     QgsRectangle* mExtent;
00151     QMap<QgsFeatureId, QgsFeature* > &mFeatures;
00153     QMap<QgsFeatureId, QString > &mIdMap;
00155     QString mGeometryAttribute;
00156     const QMap<QString, QPair<int, QgsField> > &mThematicAttributes;
00157     QGis::WkbType* mWkbType;
00159     bool mFinished;
00161     std::stack<parseMode> mParseModeStack;
00163     QString mStringCash;
00164     QgsFeature* mCurrentFeature;
00165     QVector<QVariant> mCurrentAttributes; //attributes of current feature
00166     QString mCurrentFeatureId;
00167     int mFeatureCount;
00169     unsigned char* mCurrentWKB;
00171     int mCurrentWKBSize;
00173     std::list< std::list<unsigned char*> > mCurrentWKBFragments;
00175     std::list< std::list<int> > mCurrentWKBFragmentSizes;
00176     QString mAttributeName;
00177     QString mTypeName;
00178     QgsApplication::endian_t mEndian;
00180     QString mCoordinateSeparator;
00182     QString mTupleSeparator;
00183 };
00184 
00185 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines