|
Quantum GIS API Documentation
master-ce49b66
|
00001 /*************************************************************************** 00002 qgsgml.h 00003 --------------------- 00004 begin : February 2013 00005 copyright : (C) 2013 by Radim Blazek 00006 email : radim dot blazek at gmail 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 QGSGML_H 00016 #define QGSGML_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 "qgslogger.h" 00025 #include "qgspoint.h" 00026 #include "qgsrectangle.h" 00027 00028 #include <QPair> 00029 #include <QByteArray> 00030 #include <QDomElement> 00031 #include <QStringList> 00032 #include <QStack> 00033 00034 class QgsRectangle; 00035 class QgsCoordinateReferenceSystem; 00036 00038 class CORE_EXPORT QgsGml: public QObject 00039 { 00040 Q_OBJECT 00041 public: 00042 QgsGml( 00043 const QString& typeName, 00044 const QString& geometryAttribute, 00045 const QgsFields & fields ); 00046 00047 ~QgsGml(); 00048 00055 int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0 ); 00056 00058 int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 ); 00059 00061 QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; } 00062 00064 QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; } 00065 00066 private slots: 00067 00068 void setFinished(); 00069 00071 void handleProgressEvent( qint64 progress, qint64 totalSteps ); 00072 00073 signals: 00074 void dataReadProgress( int progress ); 00075 void totalStepsUpdate( int totalSteps ); 00076 //also emit signal with progress and totalSteps together (this is better for the status message) 00077 void dataProgressAndSteps( int progress, int totalSteps ); 00078 00079 private: 00080 00081 enum ParseMode 00082 { 00083 none, 00084 boundingBox, 00085 //featureMember, // gml:featureMember 00086 feature, // feature element containint attrs and geo (inside gml:featureMember) 00087 attribute, 00088 geometry, 00089 coordinate, 00090 point, 00091 line, 00092 polygon, 00093 multiPoint, 00094 multiLine, 00095 multiPolygon 00096 }; 00097 00099 void startElement( const XML_Char* el, const XML_Char** attr ); 00100 void endElement( const XML_Char* el ); 00101 void characters( const XML_Char* chars, int len ); 00102 static void start( void* data, const XML_Char* el, const XML_Char** attr ) 00103 { 00104 static_cast<QgsGml*>( data )->startElement( el, attr ); 00105 } 00106 static void end( void* data, const XML_Char* el ) 00107 { 00108 static_cast<QgsGml*>( data )->endElement( el ); 00109 } 00110 static void chars( void* data, const XML_Char* chars, int len ) 00111 { 00112 static_cast<QgsGml*>( data )->characters( chars, len ); 00113 } 00114 00115 //helper routines 00116 00121 int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr ) const; 00126 QString readAttribute( const QString& attributeName, const XML_Char** attr ) const; 00129 int createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const; 00134 int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const; 00135 00136 int getPointWKB( unsigned char** wkb, int* size, const QgsPoint& ) const; 00137 int getLineWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& lineCoordinates ) const; 00138 int getRingWKB( unsigned char** wkb, int* size, const QList<QgsPoint>& ringCoordinates ) const; 00140 int createMultiLineFromFragments(); 00141 int createMultiPointFromFragments(); 00142 int createPolygonFromFragments(); 00143 int createMultiPolygonFromFragments(); 00145 int totalWKBFragmentSize() const; 00146 00148 QWidget* findMainWindow() const; 00152 void calculateExtentFromFeatures(); 00153 00155 ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); } 00156 00158 ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); } 00159 00160 QString mTypeName; 00161 QString mUri; 00162 //results are members such that handler routines are able to manipulate them 00164 QgsRectangle mExtent; 00166 //QMap<QgsFeatureId, QgsFeature* > &mFeatures; 00167 QMap<QgsFeatureId, QgsFeature* > mFeatures; 00168 //QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures; 00169 00171 //QMap<QgsFeatureId, QString > &mIdMap; 00172 QMap<QgsFeatureId, QString > mIdMap; 00173 //QMap<QString, QMap<QgsFeatureId, QString > > mIdMap; 00175 QString mGeometryAttribute; 00176 //const QMap<QString, QPair<int, QgsField> > &mThematicAttributes; 00177 QMap<QString, QPair<int, QgsField> > mThematicAttributes; 00178 QGis::WkbType* mWkbType; 00180 bool mFinished; 00182 QStack<ParseMode> mParseModeStack; 00184 QString mStringCash; 00185 QgsFeature* mCurrentFeature; 00186 QVector<QVariant> mCurrentAttributes; //attributes of current feature 00187 QString mCurrentFeatureId; 00188 int mFeatureCount; 00190 unsigned char* mCurrentWKB; 00192 int mCurrentWKBSize; 00193 QgsRectangle mCurrentExtent; 00195 QList< QList<unsigned char*> > mCurrentWKBFragments; 00197 QList< QList<int> > mCurrentWKBFragmentSizes; 00198 QString mAttributeName; 00199 QgsApplication::endian_t mEndian; 00201 QString mCoordinateSeparator; 00203 QString mTupleSeparator; 00204 }; 00205 00206 #endif