28 #include <QDomDocument>    29 #include <QtCore/qmath.h>    58   for ( 
int i = 0; i < mX.
count(); ++i )
   107   importVerticesFromWkb( wkbPtr );
   114   importVerticesFromWkb( wkb );
   124   Q_FOREACH ( 
double x, mX )
   131   Q_FOREACH ( 
double y, mY )
   163   int size = 
sizeof( char ) + 
sizeof( quint32 ) + 
sizeof( quint32 );
   171   unsigned char* geomPtr = 
new unsigned char[binarySize];
   174   wkb << static_cast<quint32>( 
wkbType() );
   204   return elemLineString;
   214   return elemLineString;
   234   int size = mX.
size();
   236   for ( 
int i = 1; i < size; ++i )
   238     dx = mX.
at( i ) - mX.
at( i - 1 );
   239     dy = mY.
at( i ) - mY.
at( i - 1 );
   240     length += sqrt( dx * dx + dy * dy );
   271   Q_UNUSED( tolerance );
   272   Q_UNUSED( toleranceType );
   283   if ( i < 0 || i >= mX.
size() )
   288   double x = mX.
at( i );
   289   double y = mY.
at( i );
   309   else if ( hasZ && hasM )
   332   if ( index >= 0 && index < mX.
size() )
   333     return mX.
at( index );
   340   if ( index >= 0 && index < mY.
size() )
   341     return mY.
at( index );
   348   if ( index >= 0 && index < mZ.
size() )
   349     return mZ.
at( index );
   356   if ( index >= 0 && index < mM.
size() )
   357     return mM.
at( index );
   364   if ( index >= 0 && index < mX.
size() )
   371   if ( index >= 0 && index < mY.
size() )
   378   if ( index >= 0 && index < mZ.
size() )
   384   if ( index >= 0 && index < mM.
size() )
   398   for ( 
int i = 0; i < nPoints; ++i )
   416   bool hasZ = firstPt.
is3D();
   440   for ( 
int i = 0; i < points.
size(); ++i )
   442     mX[i] = points.
at( i ).x();
   443     mY[i] = points.
at( i ).y();
   446       mZ[i] = points.
at( i ).z();
   450       mM[i] = points.
at( i ).m();
   526   std::reverse( copy->mX.
begin(), copy->mX.
end() );
   527   std::reverse( copy->mY.
begin(), copy->mY.
end() );
   530     std::reverse( copy->mZ.
begin(), copy->mZ.
end() );
   534     std::reverse( copy->mM.
begin(), copy->mM.
end() );
   563   for ( 
int i = 1; i < nPoints; ++i )
   577   for ( 
int i = 0; i < mX.
count(); ++i )
   588   return compoundCurve;
   599   double* zArray = mZ.
data();
   603   bool useDummyZ = !hasZ || !transformZ;
   606     zArray = 
new double[nPoints];
   607     for ( 
int i = 0; i < nPoints; ++i )
   623   for ( 
int i = 0; i < nPoints; ++i )
   626     t.
map( mX.
at( i ), mY.
at( i ), &x, &y );
   671   mX[position.
vertex] = newPos.
x();
   672   mY[position.
vertex] = newPos.
y();
   675     mZ[position.
vertex] = newPos.
z();
   679     mM[position.
vertex] = newPos.
m();
   742   double segmentPtX, segmentPtY;
   744   int size = mX.
size();
   745   if ( size == 0 || size == 1 )
   750   for ( 
int i = 1; i < size; ++i )
   752     double prevX = mX.
at( i - 1 );
   753     double prevY = mY.
at( i - 1 );
   754     double currentX = mX.
at( i );
   755     double currentY = mY.
at( i );
   757     if ( testDist < sqrDist )
   760       segmentPt.
setX( segmentPtX );
   761       segmentPt.
setY( segmentPtY );
   766       vertexAfter.
part = 0;
   767       vertexAfter.
ring = 0;
   797   if ( numPoints == 1 )
   800   double totalLineLength = 0.0;
   801   double prevX = mX.
at( 0 );
   802   double prevY = mY.
at( 0 );
   808     double currentX = mX.
at( i );
   809     double currentY = mY.
at( i );
   810     double segmentLength = sqrt( qPow( currentX - prevX, 2.0 ) +
   811                                  qPow( currentY - prevY, 2.0 ) );
   815     totalLineLength += segmentLength;
   816     sumX += segmentLength * 0.5 * ( currentX + prevX );
   817     sumY += segmentLength * 0.5 * ( currentY + prevY );
   825     return QgsPointV2( sumX / totalLineLength, sumY / totalLineLength );
   838   for ( 
int i = 0; i < maxIndex; ++i )
   840     sum += 0.5 * ( mX.
at( i ) * mY.
at( i + 1 ) - mY.
at( i ) * mX.
at( i + 1 ) );
   844 void QgsLineStringV2::importVerticesFromWkb( 
const QgsConstWkbPtr& wkb )
   854   for ( 
int i = 0; i < nVertices; ++i )
   887   if ( mX.
count() < 2 )
   899       double currentX = mX.
at( 0 );
   900       double currentY = mY.
at( 0 );
   901       double afterX = mX.
at( 1 );
   902       double afterY = mY.
at( 1 );
   905     else if ( vertex.
vertex == 0 )
   918     double previousX = mX.
at( vertex.
vertex - 1 );
   919     double previousY = mY.
at( vertex.
vertex - 1 );
   920     double currentX = mX.
at( vertex.
vertex );
   921     double currentY = mY.
at( vertex.
vertex );
   922     double afterX = mX.
at( vertex.
vertex + 1 );
   923     double afterY = mY.
at( vertex.
vertex + 1 );
   951   for ( 
int i = 0; i < nPoints; ++i )
   982   for ( 
int i = 0; i < nPoints; ++i )
 QString wktTypeStr() const
Returns the WKT type string of the geometry. 
 
double xAt(int index) const
Returns the x-coordinate of the specified node in the line string. 
 
virtual bool insertVertex(QgsVertexId position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry. 
 
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
 
A rectangle specified with double values. 
 
virtual QgsPointV2 centroid() const override
Returns the centroid of the geometry. 
 
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry. 
 
static QPair< QgsWKBTypes::Type, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
 
QPointF currentPosition() const
 
virtual bool fromWkb(QgsConstWkbPtr wkb) override
Sets the geometry from a WKB string. 
 
QDomNode appendChild(const QDomNode &newChild)
 
static double lineAngle(double x1, double y1, double x2, double y2)
Calculates the direction of line joining two points in radians, clockwise from the north direction...
 
void append(const T &value)
 
void push_back(const T &value)
 
void points(QgsPointSequenceV2 &pt) const override
Returns a list of points within the curve. 
 
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter. 
 
static double averageAngle(double x1, double y1, double x2, double y2, double x3, double y3)
Angle between two linear segments. 
 
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type. 
 
static bool hasM(Type type)
Tests whether a WKB type contains m values. 
 
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequenceV2 &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }. 
 
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
 
void drawPolyline(const QPointF *points, int pointCount)
 
virtual bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string. 
 
const T & at(int i) const
 
bool operator==(const QgsCurveV2 &other) const override
 
void insert(int i, const T &value)
 
static QString pointsToJSON(const QgsPointSequenceV2 &points, int precision)
Returns a geoJSON coordinates string. 
 
Abstract base class for all geometries. 
 
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
 
virtual bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value. 
 
void moveTo(const QPointF &point)
 
void setX(double x)
Sets the point's x-coordinate. 
 
static double leftOfLine(double x, double y, double x1, double y1, double x2, double y2)
Returns < 0 if point(x/y) is left of the line x1,y1 -> x2,y2. 
 
virtual QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry. 
 
void append(const QgsLineStringV2 *line)
Appends the contents of another line string to the end of this line string. 
 
QDomElement createElementNS(const QString &nsURI, const QString &qName)
 
double z() const
Returns the point's z-coordinate. 
 
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension. 
 
double y() const
Returns the point's y-coordinate. 
 
virtual QgsPointV2 endPoint() const override
Returns the end point of the curve. 
 
static endian_t endian()
Returns whether this machine uses big or little endian. 
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference) 
 
void setY(double y)
Sets the point's y-coordinate. 
 
bool pointAt(int node, QgsPointV2 &point, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve. 
 
virtual bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry. 
 
void addToPainterPath(QPainterPath &path) const override
Adds a curve to a painter path. 
 
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal. 
 
virtual bool dropMValue() override
Drops any measure values which exist in the geometry. 
 
static Type dropZ(Type type)
Drops the z dimension (if present) for a WKB type and returns the new type. 
 
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type. 
 
virtual void clearCache() const override
Clears any cached parameters associated with the geometry, eg bounding boxes. 
 
virtual bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value. 
 
virtual bool isClosed() const
Returns true if the curve is closed. 
 
Utility class for identifying a unique vertex within a geometry. 
 
Line string geometry type, with support for z-dimension and m-values. 
 
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry. 
 
static QString pointsToWKT(const QgsPointSequenceV2 &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list. 
 
void lineTo(const QPointF &endPoint)
 
void setPoints(const QgsPointSequenceV2 &points)
Resets the line string to match the specified list of points. 
 
bool isMeasure() const
Returns true if the geometry contains m values. 
 
Point geometry type, with support for z-dimension and m-values. 
 
virtual double length() const override
Returns the length of the geometry. 
 
QgsWKBTypes::Type mWkbType
 
virtual QgsLineStringV2 * clone() const override
Clones the geometry by performing a deep copy. 
 
unsigned char * asWkb(int &binarySize) const override
Returns a WKB representation of the geometry. 
 
double x() const
Returns the point's x-coordinate. 
 
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry. 
 
void setZMTypeFromSubGeometry(const QgsAbstractGeometryV2 *subggeom, QgsWKBTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values. 
 
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the line string. 
 
bool operator!=(const QgsCurveV2 &other) const override
 
void setYAt(int index, double y)
Sets the y-coordinate of the specified node in the line string. 
 
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry. 
 
static QDomElement pointsToGML3(const QgsPointSequenceV2 &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element. 
 
Compound curve geometry type. 
 
void setXAt(int index, double x)
Sets the x-coordinate of the specified node in the line string. 
 
double yAt(int index) const
Returns the y-coordinate of the specified node in the line string. 
 
bool convertTo(QgsWKBTypes::Type type) override
Converts the geometry to a specified type. 
 
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex. 
 
virtual bool convertTo(QgsWKBTypes::Type type)
Converts the geometry to a specified type. 
 
double closestSegment(const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon) const override
Searches for the closest segment of the geometry to a given point. 
 
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type. 
 
virtual QgsPointV2 startPoint() const override
Returns the starting point of the curve. 
 
void addCurve(QgsCurveV2 *c)
Adds a curve to the geometr (takes ownership) 
 
QgsAbstractGeometryV2 * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsCompoundCurveV2. ...
 
void addVertex(const QgsPointV2 &pt)
Adds a new vertex to the end of the line string. 
 
const T & at(int i) const
 
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string. 
 
virtual QgsLineStringV2 * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
 
static QgsPointSequenceV2 pointsFromWKT(const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string. 
 
virtual bool dropZValue() override
Drops any z-dimensions which exist in the geometry. 
 
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry. 
 
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override
Transforms the geometry using a coordinate transform. 
 
void drawAsPolygon(QPainter &p) const override
Draws the curve as a polygon on the specified QPainter. 
 
int count(const T &value) const
 
virtual QgsLineStringV2 * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped. 
 
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line. 
 
static Type flatType(Type type)
Returns the flat type for a WKB type. 
 
QPolygonF asQPolygonF() const
Returns a QPolygonF representing the line string. 
 
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. 
 
QgsWKBTypes::Type readHeader() const
 
double mAt(int index) const
Returns the m value of the specified node in the line string. 
 
int wkbSize() const override
Returns the size of the WKB representation of the geometry. 
 
void sumUpArea(double &sum) const override
Sums up the area of the curve by iterating over the vertices (shoelace formula). 
 
Abstract base class for curved geometry type. 
 
double m() const
Returns the point's m value. 
 
virtual void clear() override
Clears the geometry, ie reset it to a null geometry. 
 
static QDomElement pointsToGML2(const QgsPointSequenceV2 &points, QDomDocument &doc, int precision, const QString &ns)
Returns a gml::coordinates DOM element. 
 
bool is3D() const
Returns true if the geometry is 3D and contains a z-value. 
 
virtual bool moveVertex(QgsVertexId position, const QgsPointV2 &newPos) override
Moves a vertex within the geometry. 
 
int numPoints() const override
Returns the number of points in the curve. 
 
QgsPointV2 pointN(int i) const
Returns the specified point from inside the line string. 
 
void setMAt(int index, double m)
Sets the m value of the specified node in the line string.