/usr/include/qgis/qgsgml.h is in libqgis-dev 2.18.17+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | /***************************************************************************
qgsgml.h
---------------------
begin : February 2013
copyright : (C) 2013 by Radim Blazek
email : radim dot blazek at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGML_H
#define QGSGML_H
#include <expat.h>
#include "qgis.h"
#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsdataprovider.h"
#include "qgsfeature.h"
#include "qgsfield.h"
#include "qgslogger.h"
#include "qgspoint.h"
#include "qgsrectangle.h"
#include "qgswkbptr.h"
#include <QPair>
#include <QByteArray>
#include <QDomElement>
#include <QStringList>
#include <QStack>
#include <QVector>
#include <string>
/** \ingroup core
* This class builds features from GML data in a streaming way. The caller must call processData()
* as soon it has new content from the source. At any point, it can call
* getAndStealReadyFeatures() to collect the features that have been completely
* parsed.
* @note not available in Python bindings
* @note Added in QGIS 2.16
*/
class CORE_EXPORT QgsGmlStreamingParser
{
public:
typedef QPair<QgsFeature*, QString> QgsGmlFeaturePtrGmlIdPair;
/** \ingroup core
* Layer properties
*/
class LayerProperties
{
public:
/** Constructor */
LayerProperties() {}
/** Layer name */
QString mName;
/** Geometry attribute name */
QString mGeometryAttribute;
};
/** Axis orientation logic. */
typedef enum
{
/** Honour EPSG axis order only if srsName is of the form urn:ogc:def:crs:EPSG: **/
Honour_EPSG_if_urn,
/** Honour EPSG axis order */
Honour_EPSG,
/** Ignore EPSG axis order */
Ignore_EPSG,
} AxisOrientationLogic;
/** Constructor */
QgsGmlStreamingParser( const QString& typeName,
const QString& geometryAttribute,
const QgsFields & fields,
AxisOrientationLogic axisOrientationLogic = Honour_EPSG_if_urn,
bool invertAxisOrientation = false );
/** Constructor for a join layer, or dealing with renamed fields*/
QgsGmlStreamingParser( const QList<LayerProperties>& layerProperties,
const QgsFields & fields,
const QMap< QString, QPair<QString, QString> >& mapFieldNameToSrcLayerNameFieldName,
AxisOrientationLogic axisOrientationLogic = Honour_EPSG_if_urn,
bool invertAxisOrientation = false );
~QgsGmlStreamingParser();
/** Process a new chunk of data. atEnd must be set to true when this is
the last chunk of data. */
bool processData( const QByteArray& data, bool atEnd, QString& errorMsg );
/** Process a new chunk of data. atEnd must be set to true when this is
the last chunk of data. */
bool processData( const QByteArray& data, bool atEnd );
/** Returns the list of features that have been completely parsed. This
can be called at any point. This will empty the list maintained internally
by the parser, so that features already returned will no longer be returned
by later calls. */
QVector<QgsGmlFeaturePtrGmlIdPair> getAndStealReadyFeatures();
/** Return the EPSG code, or 0 if unknown */
int getEPSGCode() const { return mEpsg; }
/** Return the value of the srsName attribute */
const QString& srsName() const { return mSrsName; }
/** Return layer bounding box */
const QgsRectangle& layerExtent() const { return mLayerExtent; }
/** Return the geometry type */
QGis::WkbType wkbType() const { return mWkbType; }
/** Return WFS 2.0 "numberMatched" attribute, or -1 if invalid/not found */
int numberMatched() const { return mNumberMatched; }
/** Return WFS 2.0 "numberReturned" or WFS 1.1 "numberOfFeatures" attribute, or -1 if invalid/not found */
int numberReturned() const { return mNumberReturned; }
/** Return whether the document parser is a OGC exception */
bool isException() const { return mIsException; }
/** Return the exception text. */
const QString& exceptionText() const { return mExceptionText; }
/** Return whether a "truncatedResponse" element is found */
bool isTruncatedResponse() const { return mTruncatedResponse; }
private:
enum ParseMode
{
none,
boundingBox,
null,
envelope,
lowerCorner,
upperCorner,
feature, // feature element containing attrs and geo (inside gml:featureMember)
attribute,
tuple, // wfs:Tuple of a join layer
featureTuple,
attributeTuple,
geometry,
coordinate,
posList,
multiPoint,
multiLine,
multiPolygon,
ExceptionReport,
ExceptionText
};
/** XML handler methods*/
void startElement( const XML_Char* el, const XML_Char** attr );
void endElement( const XML_Char* el );
void characters( const XML_Char* chars, int len );
static void start( void* data, const XML_Char* el, const XML_Char** attr )
{
static_cast<QgsGmlStreamingParser*>( data )->startElement( el, attr );
}
static void end( void* data, const XML_Char* el )
{
static_cast<QgsGmlStreamingParser*>( data )->endElement( el );
}
static void chars( void* data, const XML_Char* chars, int len )
{
static_cast<QgsGmlStreamingParser*>( data )->characters( chars, len );
}
// Set current feature attribute
void setAttribute( const QString& name, const QString& value );
//helper routines
/** Reads attribute srsName="EpsgCrsId:..."
@param epsgNr result
@param attr attribute strings
@return 0 in case of success
*/
int readEpsgFromAttribute( int& epsgNr, const XML_Char** attr );
/** Reads attribute as string
@param attributeName
@param attr
@return attribute value or an empty string if no such attribute
*/
QString readAttribute( const QString& attributeName, const XML_Char** attr ) const;
/** Creates a rectangle from a coordinate string. */
bool createBBoxFromCoordinateString( QgsRectangle &bb, const QString& coordString ) const;
/** Creates a set of points from a coordinate string.
@param points list that will contain the created points
@param coordString the text containing the coordinates
@return 0 in case of success
*/
int pointsFromCoordinateString( QList<QgsPoint>& points, const QString& coordString ) const;
/** Creates a set of points from a gml:posList or gml:pos coordinate string.
@param points list that will contain the created points
@param coordString the text containing the coordinates
@param dimension number of dimensions
@return 0 in case of success
*/
int pointsFromPosListString( QList<QgsPoint>& points, const QString& coordString, int dimension ) const;
int pointsFromString( QList<QgsPoint>& points, const QString& coordString ) const;
int getPointWKB( QgsWkbPtr &wkbPtr, const QgsPoint& ) const;
int getLineWKB( QgsWkbPtr &wkbPtr, const QList<QgsPoint>& lineCoordinates ) const;
int getRingWKB( QgsWkbPtr &wkbPtr, const QList<QgsPoint>& ringCoordinates ) const;
/** Creates a multiline from the information in mCurrentWKBFragments and
* mCurrentWKBFragmentSizes. Assign the result. The multiline is in
* mCurrentWKB. The function deletes the memory in
* mCurrentWKBFragments. Returns 0 in case of success.
*/
int createMultiLineFromFragments();
int createMultiPointFromFragments();
int createPolygonFromFragments();
int createMultiPolygonFromFragments();
/** Adds all the integers contained in mCurrentWKBFragmentSizes*/
int totalWKBFragmentSize() const;
/** Get safely (if empty) top from mode stack */
ParseMode modeStackTop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.top(); }
/** Safely (if empty) pop from mode stack */
ParseMode modeStackPop() { return mParseModeStack.isEmpty() ? none : mParseModeStack.pop(); }
/** Expat parser */
XML_Parser mParser;
/** List of (feature, gml_id) pairs */
QVector<QgsGmlFeaturePtrGmlIdPair> mFeatureList;
/** Describe the various feature types of a join layer */
QList<LayerProperties> mLayerProperties;
QMap< QString, LayerProperties > mMapTypeNameToProperties;
/** Typename without namespace prefix */
QString mTypeName;
QByteArray mTypeNameBA;
const char* mTypeNamePtr;
size_t mTypeNameUTF8Len;
QGis::WkbType mWkbType;
//results are members such that handler routines are able to manipulate them
/** Name of geometry attribute*/
QString mGeometryAttribute;
QByteArray mGeometryAttributeBA;
const char* mGeometryAttributePtr;
size_t mGeometryAttributeUTF8Len;
QgsFields mFields;
QMap<QString, QPair<int, QgsField> > mThematicAttributes;
bool mIsException;
QString mExceptionText;
bool mTruncatedResponse;
/** Parsing depth */
int mParseDepth;
int mFeatureTupleDepth;
QString mCurrentTypename; /** Used to track the current (unprefixed) typename for wfs:Member in join layer */
/** Keep track about the most important nested elements*/
QStack<ParseMode> mParseModeStack;
/** This contains the character data if an important element has been encountered*/
QString mStringCash;
QgsFeature* mCurrentFeature;
QVector<QVariant> mCurrentAttributes; //attributes of current feature
QString mCurrentFeatureId;
int mFeatureCount;
/** The total WKB for a feature*/
QgsWkbPtr mCurrentWKB;
QgsRectangle mCurrentExtent;
bool mBoundedByNullFound;
/** 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*/
QList< QList<QgsWkbPtr> > mCurrentWKBFragments;
QString mAttributeName;
char mEndian;
/** Coordinate separator for coordinate strings. Usually "," */
QString mCoordinateSeparator;
/** Tuple separator for coordinate strings. Usually " " */
QString mTupleSeparator;
/** Keep track about number of dimensions in pos or posList */
QStack<int> mDimensionStack;
/** Number of dimensions in pos or posList for the current geometry */
int mDimension;
/** Coordinates mode, coordinate or posList */
ParseMode mCoorMode;
/** EPSG of parsed features geometries */
int mEpsg;
/** Literal srsName attribute */
QString mSrsName;
/** Layer bounding box */
QgsRectangle mLayerExtent;
/** GML namespace URI */
QString mGMLNameSpaceURI;
const char* mGMLNameSpaceURIPtr;
/** Axis orientation logic */
AxisOrientationLogic mAxisOrientationLogic;
/** Whether to invert axis orientation. This value is immutable, but combined with what is infered from data and mAxisOrientationLogic, is used to compute mInvertAxisOrientation */
bool mInvertAxisOrientationRequest;
/** Whether to invert axis orientation: result of mAxisOrientationLogic, mInvertAxisOrientationRequest and what is infered from data and mAxisOrientationLogic */
bool mInvertAxisOrientation;
/** WFS 2.0 "numberReturned" or WFS 1.1 "numberOfFeatures" attribute, or -1 if invalid/not found */
int mNumberReturned;
/** WFS 2.0 "numberMatched" attribute, or -1 if invalid/not found */
int mNumberMatched;
/** XML blob containing geometry */
std::string mGeometryString;
/** Whether we found a unhandled geometry element */
bool mFoundUnhandledGeometryElement;
};
/** \ingroup core
* 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 */
class CORE_EXPORT QgsGml : public QObject
{
Q_OBJECT
public:
QgsGml(
const QString& typeName,
const QString& geometryAttribute,
const QgsFields & fields );
~QgsGml();
/** Does the Http GET request to the wfs server
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
* @param uri GML URL
* @param wkbType wkbType to retrieve
* @param extent retrieved extents
* @param userName username for authentication
* @param password password for authentication
* @param authcfg authentication configuration id
* @return 0 in case of success
* @note available in python as getFeaturesUri
*/
int getFeatures( const QString& uri,
QGis::WkbType* wkbType,
QgsRectangle* extent = nullptr,
const QString& userName = QString(),
const QString& password = QString(),
const QString& authcfg = QString() );
/** Read from GML data. Constructor uri param is ignored
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
*/
int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = nullptr );
/** Get parsed features for given type name */
QMap<QgsFeatureId, QgsFeature* > featuresMap() const { return mFeatures; }
/** Get feature ids map */
QMap<QgsFeatureId, QString > idsMap() const { return mIdMap; }
/** Returns features spatial reference system
@note Added in QGIS 2.1 */
QgsCoordinateReferenceSystem crs() const;
private slots:
void setFinished();
/** Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'*/
void handleProgressEvent( qint64 progress, qint64 totalSteps );
signals:
void dataReadProgress( int progress );
void totalStepsUpdate( int totalSteps );
//also emit signal with progress and totalSteps together (this is better for the status message)
void dataProgressAndSteps( int progress, int totalSteps );
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.
*/
void calculateExtentFromFeatures();
void fillMapsFromParser();
QgsGmlStreamingParser mParser;
/** Typename without namespace prefix */
QString mTypeName;
/** True if the request is finished*/
bool mFinished;
/** The features of the layer, map of feature maps for each feature type*/
//QMap<QgsFeatureId, QgsFeature* > &mFeatures;
QMap<QgsFeatureId, QgsFeature* > mFeatures;
//QMap<QString, QMap<QgsFeatureId, QgsFeature* > > mFeatures;
/** Stores the relation between provider ids and WFS server ids*/
//QMap<QgsFeatureId, QString > &mIdMap;
QMap<QgsFeatureId, QString > mIdMap;
//QMap<QString, QMap<QgsFeatureId, QString > > mIdMap;
/** Bounding box of the layer*/
QgsRectangle mExtent;
};
#endif
|