QGIS API Documentation
2.4.0-Chugiak
|
This class reads data from a WFS server or alternatively from a GML file. More...
#include <qgsgml.h>
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, const QString &userName=QString(), const QString &password=QString()) |
Does the Http GET request to the wfs server Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings. More... | |
int | getFeatures (const QByteArray &data, QGis::WkbType *wkbType, QgsRectangle *extent=0) |
Read from GML data. More... | |
QMap< QgsFeatureId, QgsFeature * > | featuresMap () const |
Get parsed features for given type name. More... | |
QMap< QgsFeatureId, QString > | idsMap () const |
Get feature ids map. More... | |
QgsCoordinateReferenceSystem | crs () const |
Returns features spatial reference system. More... | |
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'. More... | |
Private Member Functions | |
void | startElement (const XML_Char *el, const XML_Char **attr) |
XML handler methods. More... | |
void | endElement (const XML_Char *el) |
void | characters (const XML_Char *chars, int len) |
void | setAttribute (const QString &name, const QString &value) |
int | readEpsgFromAttribute (int &epsgNr, const XML_Char **attr) const |
Reads attribute srsName="EpsgCrsId:...". More... | |
QString | readAttribute (const QString &attributeName, const XML_Char **attr) const |
Reads attribute as string. More... | |
int | createBBoxFromCoordinateString (QgsRectangle &bb, const QString &coordString) const |
Creates a rectangle from a coordinate string. More... | |
int | pointsFromCoordinateString (QList< QgsPoint > &points, const QString &coordString) const |
Creates a set of points from a coordinate string. More... | |
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. More... | |
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. More... | |
int | createMultiPointFromFragments () |
int | createPolygonFromFragments () |
int | createMultiPolygonFromFragments () |
int | totalWKBFragmentSize () const |
Adds all the integers contained in mCurrentWKBFragmentSizes. More... | |
QWidget * | findMainWindow () const |
Returns pointer to main window or 0 if it does not exist. More... | |
void | calculateExtentFromFeatures () |
This function evaluates the layer bounding box from the features and sets it to mExtent. More... | |
ParseMode | modeStackTop () |
Get safely (if empty) top from mode stack. More... | |
ParseMode | modeStackPop () |
Safely (if empty) pop from mode stack. More... | |
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. More... | |
QMap< QgsFeatureId, QgsFeature * > | mFeatures |
The features of the layer, map of feature maps for each feature type. More... | |
QMap< QgsFeatureId, QString > | mIdMap |
Stores the relation between provider ids and WFS server ids. More... | |
QString | mGeometryAttribute |
Name of geometry attribute. More... | |
QMap< QString, QPair< int, QgsField > > | mThematicAttributes |
QGis::WkbType * | mWkbType |
bool | mFinished |
True if the request is finished. More... | |
QStack< ParseMode > | mParseModeStack |
Keep track about the most important nested elements. More... | |
QString | mStringCash |
This contains the character data if an important element has been encountered. More... | |
QgsFeature * | mCurrentFeature |
QVector< QVariant > | mCurrentAttributes |
QString | mCurrentFeatureId |
int | mFeatureCount |
unsigned char * | mCurrentWKB |
The total WKB for a feature. More... | |
int | mCurrentWKBSize |
The total WKB size for a feature. More... | |
QgsRectangle | mCurrentExtent |
QList< QList< unsigned char * > > | mCurrentWKBFragments |
WKB intermediate storage during parsing. More... | |
QList< QList< int > > | mCurrentWKBFragmentSizes |
Similar to mCurrentWKB, but only the size. More... | |
QString | mAttributeName |
QgsApplication::endian_t | mEndian |
QString | mCoordinateSeparator |
Coordinate separator for coordinate strings. More... | |
QString | mTupleSeparator |
Tuple separator for coordinate strings. More... | |
int | mDimension |
Number of dimensions in pos or posList. More... | |
ParseMode | mCoorMode |
Coordinates mode, coordinate or posList. More... | |
int | mEpsg |
EPSG of parsed features geometries. More... | |
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
|
private |
QgsGml::QgsGml | ( | const QString & | typeName, |
const QString & | geometryAttribute, | ||
const QgsFields & | fields | ||
) |
Definition at line 36 of file qgsgml.cpp.
References QgsApplication::endian(), index, mEndian, mThematicAttributes, mTypeName, and QgsFields::size().
QgsGml::~QgsGml | ( | ) |
Definition at line 64 of file qgsgml.cpp.
|
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 953 of file qgsgml.cpp.
References QgsGeometry::boundingBox(), QgsFeature::geometry(), mExtent, mFeatures, and QgsRectangle::unionRect().
Referenced by getFeatures().
|
private |
Definition at line 530 of file qgsgml.cpp.
References attribute, coordinate, mParseModeStack, mStringCash, and posList.
|
inlinestaticprivate |
Definition at line 119 of file qgsgml.h.
Referenced by getFeatures().
|
private |
Creates a rectangle from a coordinate string.
Definition at line 617 of file qgsgml.cpp.
References pointsFromCoordinateString(), and QgsRectangle::set().
Referenced by endElement().
|
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 783 of file qgsgml.cpp.
References mCurrentWKB, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mCurrentWKBSize, mEndian, mWkbType, totalWKBFragmentSize(), and QGis::WKBMultiLineString.
Referenced by endElement().
|
private |
Definition at line 817 of file qgsgml.cpp.
References mCurrentWKB, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mCurrentWKBSize, mEndian, mWkbType, totalWKBFragmentSize(), and QGis::WKBMultiPoint.
Referenced by endElement().
|
private |
Definition at line 884 of file qgsgml.cpp.
References mCurrentWKB, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mCurrentWKBSize, mEndian, mWkbType, totalWKBFragmentSize(), QGis::WKBMultiPolygon, and QGis::WKBPolygon.
Referenced by endElement().
|
private |
Definition at line 852 of file qgsgml.cpp.
References mCurrentWKB, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mCurrentWKBSize, mEndian, mWkbType, totalWKBFragmentSize(), and QGis::WKBPolygon.
Referenced by endElement().
QgsCoordinateReferenceSystem QgsGml::crs | ( | ) | const |
Returns features spatial reference system.
Definition at line 987 of file qgsgml.cpp.
References QgsCoordinateReferenceSystem::createFromOgcWmsCrs(), and mEpsg.
|
signal |
Referenced by handleProgressEvent().
|
signal |
Referenced by getFeatures(), and handleProgressEvent().
|
inlinestaticprivate |
Definition at line 115 of file qgsgml.h.
Referenced by getFeatures().
|
private |
Definition at line 327 of file qgsgml.cpp.
References attribute, boundingBox, coordinate, createBBoxFromCoordinateString(), createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), feature, QgsGeometry::fromRect(), geometry, getLineWKB(), getPointWKB(), getRingWKB(), GML_NAMESPACE, QgsFeature::id(), QgsRectangle::isEmpty(), mAttributeName, mCurrentExtent, mCurrentFeature, mCurrentFeatureId, mCurrentWKB, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mCurrentWKBSize, mFeatureCount, mFeatures, mGeometryAttribute, mIdMap, mParseModeStack, mStringCash, mTypeName, multiLine, multiPoint, multiPolygon, mWkbType, none, NS_SEPARATOR, pointsFromString(), posList, QgsDebugMsg, setAttribute(), QgsFeature::setGeometry(), QgsFeature::setGeometryAndOwnership(), QgsFeature::setValid(), QGis::WKBLineString, QGis::WKBMultiLineString, QGis::WKBMultiPoint, QGis::WKBMultiPolygon, QGis::WKBPoint, and QGis::WKBPolygon.
|
inline |
|
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 , |
||
const QString & | userName = QString() , |
||
const QString & | password = QString() |
||
) |
Does the Http GET request to the wfs server Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
uri | GML URL |
wkbType | wkbType to retrieve |
extent | retrieved extents |
userName | username for authentication |
password | password for authentication |
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 169 of file qgsgml.cpp.
References chars(), end(), mExtent, mWkbType, NS_SEPARATOR, QgsRectangle::setMinimal(), and start().
|
private |
Definition at line 728 of file qgsgml.cpp.
References mEndian, and QGis::WKBLineString.
Referenced by endElement().
|
private |
Definition at line 708 of file qgsgml.cpp.
References mEndian, QGis::WKBPoint, QgsPoint::x(), and QgsPoint::y().
Referenced by endElement().
|
private |
Definition at line 759 of file qgsgml.cpp.
Referenced by endElement().
|
privateslot |
Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'.
Definition at line 192 of file qgsgml.cpp.
References dataProgressAndSteps(), dataReadProgress(), and totalStepsUpdate().
Referenced by getFeatures().
|
inline |
|
inlineprivate |
|
inlineprivate |
|
private |
Creates a set of points from a coordinate string.
points | list that will contain the created points |
coordString | the text containing the coordinates |
Definition at line 635 of file qgsgml.cpp.
References mCoordinateSeparator, and mTupleSeparator.
Referenced by createBBoxFromCoordinateString(), and pointsFromString().
|
private |
Creates a set of points from a gml:posList or gml:pos coordinate string.
points | list that will contain the created points |
coordString | the text containing the coordinates |
dimension | number of dimensions |
Definition at line 666 of file qgsgml.cpp.
References QgsDebugMsg.
Referenced by pointsFromString().
|
private |
Definition at line 695 of file qgsgml.cpp.
References coordinate, mCoorMode, mDimension, pointsFromCoordinateString(), pointsFromPosListString(), and posList.
Referenced by endElement().
|
private |
Reads attribute as string.
attributeName | |
attr |
Definition at line 603 of file qgsgml.cpp.
Referenced by startElement().
|
private |
Reads attribute srsName="EpsgCrsId:...".
epsgNr | result |
attr | attribute strings |
Definition at line 572 of file qgsgml.cpp.
Referenced by startElement().
|
private |
Definition at line 545 of file qgsgml.cpp.
References mCurrentFeature, mThematicAttributes, and QgsFeature::setAttribute().
Referenced by endElement(), and startElement().
|
privateslot |
|
inlinestaticprivate |
Definition at line 111 of file qgsgml.h.
Referenced by getFeatures().
|
private |
XML handler methods.
Definition at line 204 of file qgsgml.cpp.
References attribute, boundingBox, coordinate, feature, geometry, GML_NAMESPACE, mAttributeName, mCoordinateSeparator, mCoorMode, mCurrentFeature, mCurrentFeatureId, mCurrentWKBFragments, mCurrentWKBFragmentSizes, mDimension, mEpsg, mFeatureCount, mGeometryAttribute, mParseModeStack, mStringCash, mThematicAttributes, mTupleSeparator, mTypeName, multiLine, multiPoint, multiPolygon, none, NS_SEPARATOR, posList, QgsDebugMsg, readAttribute(), readEpsgFromAttribute(), setAttribute(), and QgsFeature::setAttributes().
|
signal |
Referenced by getFeatures(), and handleProgressEvent().
|
private |
Adds all the integers contained in mCurrentWKBFragmentSizes.
Definition at line 940 of file qgsgml.cpp.
References mCurrentWKBFragmentSizes.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), and createPolygonFromFragments().
|
private |
Definition at line 231 of file qgsgml.h.
Referenced by endElement(), and startElement().
|
private |
Coordinate separator for coordinate strings.
Usually ","
Definition at line 234 of file qgsgml.h.
Referenced by pointsFromCoordinateString(), and startElement().
|
private |
Coordinates mode, coordinate or posList.
Definition at line 240 of file qgsgml.h.
Referenced by pointsFromString(), and startElement().
|
private |
Definition at line 223 of file qgsgml.h.
Referenced by endElement().
|
private |
Definition at line 215 of file qgsgml.h.
Referenced by endElement(), setAttribute(), and startElement().
|
private |
Definition at line 217 of file qgsgml.h.
Referenced by endElement(), and startElement().
|
private |
The total WKB for a feature.
Definition at line 220 of file qgsgml.h.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), and endElement().
|
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 228 of file qgsgml.h.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), endElement(), and startElement().
|
private |
Similar to mCurrentWKB, but only the size.
Definition at line 230 of file qgsgml.h.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), endElement(), startElement(), and totalWKBFragmentSize().
|
private |
The total WKB size for a feature.
Definition at line 222 of file qgsgml.h.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), and endElement().
|
private |
Number of dimensions in pos or posList.
Definition at line 238 of file qgsgml.h.
Referenced by pointsFromString(), and startElement().
|
private |
Definition at line 232 of file qgsgml.h.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), getLineWKB(), getPointWKB(), and QgsGml().
|
private |
EPSG of parsed features geometries.
Definition at line 242 of file qgsgml.h.
Referenced by crs(), and startElement().
|
private |
Bounding box of the layer.
Definition at line 194 of file qgsgml.h.
Referenced by calculateExtentFromFeatures(), and getFeatures().
|
private |
Definition at line 218 of file qgsgml.h.
Referenced by endElement(), and startElement().
|
private |
The features of the layer, map of feature maps for each feature type.
Definition at line 197 of file qgsgml.h.
Referenced by calculateExtentFromFeatures(), and endElement().
|
private |
True if the request is finished.
Definition at line 210 of file qgsgml.h.
Referenced by getFeatures(), and setFinished().
|
private |
Name of geometry attribute.
Definition at line 205 of file qgsgml.h.
Referenced by endElement(), and startElement().
|
private |
Stores the relation between provider ids and WFS server ids.
Definition at line 202 of file qgsgml.h.
Referenced by endElement().
|
private |
Keep track about the most important nested elements.
Definition at line 212 of file qgsgml.h.
Referenced by characters(), endElement(), and startElement().
|
private |
This contains the character data if an important element has been encountered.
Definition at line 214 of file qgsgml.h.
Referenced by characters(), endElement(), and startElement().
|
private |
Definition at line 207 of file qgsgml.h.
Referenced by QgsGml(), setAttribute(), and startElement().
|
private |
Tuple separator for coordinate strings.
Usually " "
Definition at line 236 of file qgsgml.h.
Referenced by pointsFromCoordinateString(), and startElement().
|
private |
Definition at line 190 of file qgsgml.h.
Referenced by endElement(), getFeatures(), QgsGml(), and startElement().
|
private |
Definition at line 191 of file qgsgml.h.
Referenced by getFeatures().
|
private |
Definition at line 208 of file qgsgml.h.
Referenced by createMultiLineFromFragments(), createMultiPointFromFragments(), createMultiPolygonFromFragments(), createPolygonFromFragments(), endElement(), and getFeatures().