QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Signals | Public Member Functions | Private Types | Private Slots | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
QgsGml Class Reference

This class reads data from a WFS server or alternatively from a GML file. More...

#include <qgsgml.h>

Collaboration diagram for QgsGml:
Collaboration graph
[legend]

Signals

void dataReadProgress (int progress)
void totalStepsUpdate (int totalSteps)
void dataProgressAndSteps (int progress, int totalSteps)

Public Member Functions

 QgsGml (const QString &typeName, const QString &geometryAttribute, const QgsFields &fields)
 ~QgsGml ()
int getFeatures (const QString &uri, QGis::WkbType *wkbType, QgsRectangle *extent=0)
 Does the Http GET request to the wfs server Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
int getFeatures (const QByteArray &data, QGis::WkbType *wkbType, QgsRectangle *extent=0)
 Read from GML data.
QMap< QgsFeatureId, QgsFeature * > featuresMap () const
 Get parsed features for given type name.
QMap< QgsFeatureId, QString > idsMap () const
 Get feature ids map.
QgsCoordinateReferenceSystem crs () const
 Returns features spatial reference system.

Private Types

enum  ParseMode {
  none, boundingBox, feature, attribute,
  geometry, coordinate, posList, multiPoint,
  multiLine, multiPolygon
}

Private Slots

void setFinished ()
void handleProgressEvent (qint64 progress, qint64 totalSteps)
 Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'.

Private Member Functions

void startElement (const XML_Char *el, const XML_Char **attr)
 XML handler methods.
void endElement (const XML_Char *el)
void characters (const XML_Char *chars, int len)
int readEpsgFromAttribute (int &epsgNr, const XML_Char **attr) const
 Reads attribute srsName="EpsgCrsId:...".
QString readAttribute (const QString &attributeName, const XML_Char **attr) const
 Reads attribute as string.
int createBBoxFromCoordinateString (QgsRectangle &bb, const QString &coordString) const
 Creates a rectangle from a coordinate string.
int pointsFromCoordinateString (QList< QgsPoint > &points, const QString &coordString) const
 Creates a set of points from a coordinate string.
int pointsFromPosListString (QList< QgsPoint > &points, const QString &coordString, int dimension) const
 Creates a set of points from a gml:posList or gml:pos coordinate string.
int pointsFromString (QList< QgsPoint > &points, const QString &coordString) const
int getPointWKB (unsigned char **wkb, int *size, const QgsPoint &) const
int getLineWKB (unsigned char **wkb, int *size, const QList< QgsPoint > &lineCoordinates) const
int getRingWKB (unsigned char **wkb, int *size, const QList< QgsPoint > &ringCoordinates) const
int createMultiLineFromFragments ()
 Creates a multiline from the information in mCurrentWKBFragments and mCurrentWKBFragmentSizes.
int createMultiPointFromFragments ()
int createPolygonFromFragments ()
int createMultiPolygonFromFragments ()
int totalWKBFragmentSize () const
 Adds all the integers contained in mCurrentWKBFragmentSizes.
QWidget * findMainWindow () const
 Returns pointer to main window or 0 if it does not exist.
void calculateExtentFromFeatures ()
 This function evaluates the layer bounding box from the features and sets it to mExtent.
ParseMode modeStackTop ()
 Get safely (if empty) top from mode stack.
ParseMode modeStackPop ()
 Safely (if empty) pop from mode stack.

Static Private Member Functions

static void start (void *data, const XML_Char *el, const XML_Char **attr)
static void end (void *data, const XML_Char *el)
static void chars (void *data, const XML_Char *chars, int len)

Private Attributes

QString mTypeName
QString mUri
QgsRectangle mExtent
 Bounding box of the layer.
QMap< QgsFeatureId, QgsFeature * > mFeatures
 The features of the layer, map of feature maps for each feature type.
QMap< QgsFeatureId, QString > mIdMap
 Stores the relation between provider ids and WFS server ids.
QString mGeometryAttribute
 Name of geometry attribute.
QMap< QString, QPair< int,
QgsField > > 
mThematicAttributes
QGis::WkbTypemWkbType
bool mFinished
 True if the request is finished.
QStack< ParseModemParseModeStack
 Keep track about the most important nested elements.
QString mStringCash
 This contains the character data if an important element has been encountered.
QgsFeaturemCurrentFeature
QVector< QVariant > mCurrentAttributes
QString mCurrentFeatureId
int mFeatureCount
unsigned char * mCurrentWKB
 The total WKB for a feature.
int mCurrentWKBSize
 The total WKB size for a feature.
QgsRectangle mCurrentExtent
QList< QList< unsigned char * > > mCurrentWKBFragments
 WKB intermediate storage during parsing.
QList< QList< int > > mCurrentWKBFragmentSizes
 Similar to mCurrentWKB, but only the size.
QString mAttributeName
QgsApplication::endian_t mEndian
QString mCoordinateSeparator
 Coordinate separator for coordinate strings.
QString mTupleSeparator
 Tuple separator for coordinate strings.
int mDimension
 Number of dimensions in pos or posList.
ParseMode mCoorMode
 Coordinates mode, coordinate or posList.
int mEpsg
 EPSG of parsed features geometries.

Detailed Description

This class reads data from a WFS server or alternatively from a GML file.

It uses the expat XML parser and an event based model to keep performance high. The parsing starts when the first data arrives, it does not wait until the request is finished

Definition at line 41 of file qgsgml.h.

Member Enumeration Documentation

enum QgsGml::ParseMode
private
Enumerator:
none 
boundingBox 
feature 
attribute 
geometry 
coordinate 
posList 
multiPoint 
multiLine 
multiPolygon 

Definition at line 91 of file qgsgml.h.

Constructor & Destructor Documentation

QgsGml::QgsGml ( const QString &  typeName,
const QString &  geometryAttribute,
const QgsFields fields 
)
QgsGml::~QgsGml ( )

Definition at line 64 of file qgsgml.cpp.

Member Function Documentation

void QgsGml::calculateExtentFromFeatures ( )
private

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.

Definition at line 930 of file qgsgml.cpp.

References QgsGeometry::boundingBox(), QgsFeature::geometry(), mExtent, mFeatures, and QgsRectangle::unionRect().

Referenced by getFeatures().

void QgsGml::characters ( const XML_Char *  chars,
int  len 
)
private

Definition at line 534 of file qgsgml.cpp.

References attribute, coordinate, mParseModeStack, mStringCash, and posList.

static void QgsGml::chars ( void *  data,
const XML_Char *  chars,
int  len 
)
inlinestaticprivate

Definition at line 117 of file qgsgml.h.

Referenced by getFeatures().

int QgsGml::createBBoxFromCoordinateString ( QgsRectangle bb,
const QString &  coordString 
) const
private

Creates a rectangle from a coordinate string.

Returns
0 in case of success

Definition at line 594 of file qgsgml.cpp.

References pointsFromCoordinateString(), and QgsRectangle::set().

Referenced by endElement().

int QgsGml::createMultiLineFromFragments ( )
private

Creates a multiline from the information in mCurrentWKBFragments and mCurrentWKBFragmentSizes.

Assign the result. The multiline is in mCurrentWKB and mCurrentWKBSize. The function deletes the memory in mCurrentWKBFragments. Returns 0 in case of success.

Definition at line 760 of file qgsgml.cpp.

References mCurrentWKB, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mCurrentWKBSize, mEndian, mWkbType, totalWKBFragmentSize(), and QGis::WKBMultiLineString.

Referenced by endElement().

int QgsGml::createMultiPointFromFragments ( )
private
int QgsGml::createMultiPolygonFromFragments ( )
private
int QgsGml::createPolygonFromFragments ( )
private
QgsCoordinateReferenceSystem QgsGml::crs ( ) const

Returns features spatial reference system.

Note
Added in QGIS 2.1

Definition at line 964 of file qgsgml.cpp.

References QgsCoordinateReferenceSystem::createFromOgcWmsCrs(), and mEpsg.

void QgsGml::dataProgressAndSteps ( int  progress,
int  totalSteps 
)
signal

Referenced by handleProgressEvent().

void QgsGml::dataReadProgress ( int  progress)
signal

Referenced by getFeatures(), and handleProgressEvent().

static void QgsGml::end ( void *  data,
const XML_Char *  el 
)
inlinestaticprivate

Definition at line 113 of file qgsgml.h.

Referenced by getFeatures().

void QgsGml::endElement ( const XML_Char *  el)
private
QMap<QgsFeatureId, QgsFeature* > QgsGml::featuresMap ( ) const
inline

Get parsed features for given type name.

Definition at line 67 of file qgsgml.h.

QWidget* QgsGml::findMainWindow ( ) const
private

Returns pointer to main window or 0 if it does not exist.

int QgsGml::getFeatures ( const QString &  uri,
QGis::WkbType wkbType,
QgsRectangle extent = 0 
)

Does the Http GET request to the wfs server Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.

Parameters
uriGML URL
wkbTypewkbType to retrieve
extentretrieved extents
Returns
0 in case of success

Definition at line 68 of file qgsgml.cpp.

References calculateExtentFromFeatures(), chars(), QgsMessageLog::CRITICAL, dataReadProgress(), end(), handleProgressEvent(), QgsNetworkAccessManager::instance(), QgsRectangle::isEmpty(), QgsMessageLog::logMessage(), mExtent, mFinished, mTypeName, mUri, mWkbType, NS_SEPARATOR, setFinished(), QgsRectangle::setMinimal(), start(), totalStepsUpdate(), tr, and QGis::WKBNoGeometry.

int QgsGml::getFeatures ( const QByteArray &  data,
QGis::WkbType wkbType,
QgsRectangle extent = 0 
)

Read from GML data.

Constructor uri param is ignored Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.

Definition at line 165 of file qgsgml.cpp.

References chars(), end(), mExtent, mWkbType, NS_SEPARATOR, QgsRectangle::setMinimal(), and start().

int QgsGml::getLineWKB ( unsigned char **  wkb,
int *  size,
const QList< QgsPoint > &  lineCoordinates 
) const
private

Definition at line 705 of file qgsgml.cpp.

References mEndian, and QGis::WKBLineString.

Referenced by endElement().

int QgsGml::getPointWKB ( unsigned char **  wkb,
int *  size,
const QgsPoint point 
) const
private

Definition at line 685 of file qgsgml.cpp.

References mEndian, QGis::WKBPoint, QgsPoint::x(), and QgsPoint::y().

Referenced by endElement().

int QgsGml::getRingWKB ( unsigned char **  wkb,
int *  size,
const QList< QgsPoint > &  ringCoordinates 
) const
private

Definition at line 736 of file qgsgml.cpp.

Referenced by endElement().

void QgsGml::handleProgressEvent ( qint64  progress,
qint64  totalSteps 
)
privateslot

Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'.

Definition at line 188 of file qgsgml.cpp.

References dataProgressAndSteps(), dataReadProgress(), and totalStepsUpdate().

Referenced by getFeatures().

QMap<QgsFeatureId, QString > QgsGml::idsMap ( ) const
inline

Get feature ids map.

Definition at line 70 of file qgsgml.h.

ParseMode QgsGml::modeStackPop ( )
inlineprivate

Safely (if empty) pop from mode stack.

Definition at line 183 of file qgsgml.h.

ParseMode QgsGml::modeStackTop ( )
inlineprivate

Get safely (if empty) top from mode stack.

Definition at line 180 of file qgsgml.h.

int QgsGml::pointsFromCoordinateString ( QList< QgsPoint > &  points,
const QString &  coordString 
) const
private

Creates a set of points from a coordinate string.

Parameters
pointslist that will contain the created points
coordStringthe text containing the coordinates
Returns
0 in case of success

Definition at line 612 of file qgsgml.cpp.

References mCoordinateSeparator, and mTupleSeparator.

Referenced by createBBoxFromCoordinateString(), and pointsFromString().

int QgsGml::pointsFromPosListString ( QList< QgsPoint > &  points,
const QString &  coordString,
int  dimension 
) const
private

Creates a set of points from a gml:posList or gml:pos coordinate string.

Parameters
pointslist that will contain the created points
coordStringthe text containing the coordinates
dimensionnumber of dimensions
Returns
0 in case of success

Definition at line 643 of file qgsgml.cpp.

References QgsDebugMsg.

Referenced by pointsFromString().

int QgsGml::pointsFromString ( QList< QgsPoint > &  points,
const QString &  coordString 
) const
private
QString QgsGml::readAttribute ( const QString &  attributeName,
const XML_Char **  attr 
) const
private

Reads attribute as string.

Parameters
attributeName
attr
Returns
attribute value or an empty string if no such attribute

Definition at line 580 of file qgsgml.cpp.

Referenced by startElement().

int QgsGml::readEpsgFromAttribute ( int &  epsgNr,
const XML_Char **  attr 
) const
private

Reads attribute srsName="EpsgCrsId:...".

Parameters
epsgNrresult
attrattribute strings
Returns
0 in case of success

Definition at line 549 of file qgsgml.cpp.

Referenced by startElement().

void QgsGml::setFinished ( )
privateslot

Definition at line 183 of file qgsgml.cpp.

References mFinished.

Referenced by getFeatures().

static void QgsGml::start ( void *  data,
const XML_Char *  el,
const XML_Char **  attr 
)
inlinestaticprivate

Definition at line 109 of file qgsgml.h.

Referenced by getFeatures().

void QgsGml::startElement ( const XML_Char *  el,
const XML_Char **  attr 
)
private
void QgsGml::totalStepsUpdate ( int  totalSteps)
signal

Referenced by getFeatures(), and handleProgressEvent().

int QgsGml::totalWKBFragmentSize ( ) const
private

Adds all the integers contained in mCurrentWKBFragmentSizes.

Definition at line 917 of file qgsgml.cpp.

References mCurrentWKBFragmentSizes.

Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), and createPolygonFromFragments().

Member Data Documentation

QString QgsGml::mAttributeName
private

Definition at line 226 of file qgsgml.h.

Referenced by endElement(), and startElement().

QString QgsGml::mCoordinateSeparator
private

Coordinate separator for coordinate strings.

Usually ","

Definition at line 229 of file qgsgml.h.

Referenced by pointsFromCoordinateString(), and startElement().

ParseMode QgsGml::mCoorMode
private

Coordinates mode, coordinate or posList.

Definition at line 235 of file qgsgml.h.

Referenced by pointsFromString(), and startElement().

QVector<QVariant> QgsGml::mCurrentAttributes
private

Definition at line 211 of file qgsgml.h.

QgsRectangle QgsGml::mCurrentExtent
private

Definition at line 218 of file qgsgml.h.

Referenced by endElement().

QgsFeature* QgsGml::mCurrentFeature
private

Definition at line 210 of file qgsgml.h.

Referenced by endElement(), and startElement().

QString QgsGml::mCurrentFeatureId
private

Definition at line 212 of file qgsgml.h.

Referenced by endElement(), and startElement().

unsigned char* QgsGml::mCurrentWKB
private
QList< QList<unsigned char*> > QgsGml::mCurrentWKBFragments
private

WKB intermediate storage during parsing.

For points and lines, no intermediate WKB is stored at all. For multipoints and multilines and polygons, only one nested list is used. For multipolygons, both nested lists are used

Definition at line 223 of file qgsgml.h.

Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), endElement(), and startElement().

QList< QList<int> > QgsGml::mCurrentWKBFragmentSizes
private
int QgsGml::mCurrentWKBSize
private
int QgsGml::mDimension
private

Number of dimensions in pos or posList.

Definition at line 233 of file qgsgml.h.

Referenced by pointsFromString(), and startElement().

QgsApplication::endian_t QgsGml::mEndian
private
int QgsGml::mEpsg
private

EPSG of parsed features geometries.

Definition at line 237 of file qgsgml.h.

Referenced by crs(), and startElement().

QgsRectangle QgsGml::mExtent
private

Bounding box of the layer.

Definition at line 189 of file qgsgml.h.

Referenced by calculateExtentFromFeatures(), and getFeatures().

int QgsGml::mFeatureCount
private

Definition at line 213 of file qgsgml.h.

Referenced by endElement(), and startElement().

QMap<QgsFeatureId, QgsFeature* > QgsGml::mFeatures
private

The features of the layer, map of feature maps for each feature type.

Definition at line 192 of file qgsgml.h.

Referenced by calculateExtentFromFeatures(), and endElement().

bool QgsGml::mFinished
private

True if the request is finished.

Definition at line 205 of file qgsgml.h.

Referenced by getFeatures(), and setFinished().

QString QgsGml::mGeometryAttribute
private

Name of geometry attribute.

Definition at line 200 of file qgsgml.h.

Referenced by endElement(), and startElement().

QMap<QgsFeatureId, QString > QgsGml::mIdMap
private

Stores the relation between provider ids and WFS server ids.

Definition at line 197 of file qgsgml.h.

Referenced by endElement().

QStack<ParseMode> QgsGml::mParseModeStack
private

Keep track about the most important nested elements.

Definition at line 207 of file qgsgml.h.

Referenced by characters(), endElement(), and startElement().

QString QgsGml::mStringCash
private

This contains the character data if an important element has been encountered.

Definition at line 209 of file qgsgml.h.

Referenced by characters(), endElement(), and startElement().

QMap<QString, QPair<int, QgsField> > QgsGml::mThematicAttributes
private

Definition at line 202 of file qgsgml.h.

Referenced by endElement(), QgsGml(), and startElement().

QString QgsGml::mTupleSeparator
private

Tuple separator for coordinate strings.

Usually " "

Definition at line 231 of file qgsgml.h.

Referenced by pointsFromCoordinateString(), and startElement().

QString QgsGml::mTypeName
private

Definition at line 185 of file qgsgml.h.

Referenced by endElement(), getFeatures(), QgsGml(), and startElement().

QString QgsGml::mUri
private

Definition at line 186 of file qgsgml.h.

Referenced by getFeatures().

QGis::WkbType* QgsGml::mWkbType
private

The documentation for this class was generated from the following files: