27 #include <QDomDocument> 28 #include <QtCore/qmath.h> 57 for (
int i = 0; i < mX.
count(); ++i )
106 importVerticesFromWkb( wkbPtr );
113 importVerticesFromWkb( wkb );
123 Q_FOREACH (
double x, mX )
130 Q_FOREACH (
double y, mY )
162 int size =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
170 unsigned char* geomPtr =
new unsigned char[binarySize];
173 wkb << static_cast<quint32>(
wkbType() );
203 return elemLineString;
238 int size = mX.
size();
240 for (
int i = 1; i < size; ++i )
242 dx = mX.
at( i ) - mX.
at( i - 1 );
243 dy = mY.
at( i ) - mY.
at( i - 1 );
244 length += sqrt( dx * dx + dy * dy );
285 if ( i < 0 || i >= mX.
size() )
290 double x = mX.
at( i );
291 double y = mY.
at( i );
311 else if ( hasZ && hasM )
334 if ( index >= 0 && index < mX.
size() )
335 return mX.
at( index );
342 if ( index >= 0 && index < mY.
size() )
343 return mY.
at( index );
350 if ( index >= 0 && index < mZ.
size() )
351 return mZ.
at( index );
358 if ( index >= 0 && index < mM.
size() )
359 return mM.
at( index );
366 if ( index >= 0 && index < mX.
size() )
373 if ( index >= 0 && index < mY.
size() )
380 if ( index >= 0 && index < mZ.
size() )
386 if ( index >= 0 && index < mM.
size() )
400 for (
int i = 0; i < nPoints; ++i )
418 bool hasZ = firstPt.
is3D();
442 for (
int i = 0; i < points.
size(); ++i )
444 mX[i] = points.
at( i ).x();
445 mY[i] = points.
at( i ).y();
448 mZ[i] = points.
at( i ).z();
452 mM[i] = points.
at( i ).m();
528 std::reverse( copy->mX.
begin(), copy->mX.
end() );
529 std::reverse( copy->mY.
begin(), copy->mY.
end() );
532 std::reverse( copy->mZ.
begin(), copy->mZ.
end() );
536 std::reverse( copy->mM.
begin(), copy->mM.
end() );
565 for (
int i = 1; i < nPoints; ++i )
579 for (
int i = 0; i < mX.
count(); ++i )
594 double* zArray = mZ.
data();
600 zArray =
new double[nPoints];
601 for (
int i = 0; i < nPoints; ++i )
617 for (
int i = 0; i < nPoints; ++i )
620 t.
map( mX.
at( i ), mY.
at( i ), &x, &y );
665 mX[position.
vertex] = newPos.
x();
666 mY[position.
vertex] = newPos.
y();
669 mZ[position.
vertex] = newPos.
z();
673 mM[position.
vertex] = newPos.
m();
736 double segmentPtX, segmentPtY;
738 int size = mX.
size();
744 else if ( 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 );
841 for (
int i = 0; i < maxIndex; ++i )
843 sum += 0.5 * ( mX.
at( i ) * mY.
at( i + 1 ) - mY.
at( i ) * mX.
at( i + 1 ) );
847 void QgsLineStringV2::importVerticesFromWkb(
const QgsConstWkbPtr& wkb )
857 for (
int i = 0; i < nVertices; ++i )
890 if ( mX.
count() < 2 )
902 double currentX = mX.
at( 0 );
903 double currentY = mY.
at( 0 );
904 double afterX = mX.
at( 1 );
905 double afterY = mY.
at( 1 );
908 else if ( vertex.
vertex == 0 )
921 double previousX = mX.
at( vertex.
vertex - 1 );
922 double previousY = mY.
at( vertex.
vertex - 1 );
923 double currentX = mX.
at( vertex.
vertex );
924 double currentY = mY.
at( vertex.
vertex );
925 double afterX = mX.
at( vertex.
vertex + 1 );
926 double afterY = mY.
at( vertex.
vertex + 1 );
954 for (
int i = 0; i < nPoints; ++i )
985 for (
int i = 0; i < nPoints; ++i )
virtual bool insertVertex(QgsVertexId position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of 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.
QgsPointV2 pointN(int i) const
Returns the specified point from inside the line string.
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)
double x() const
Returns the point's x-coordinate.
void push_back(const T &value)
void points(QgsPointSequenceV2 &pt) const override
Returns a list of points within the curve.
QPolygonF asQPolygonF() const
Returns a QPolygonF representing the line string.
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.
double xAt(int index) const
Returns the x-coordinate of the specified node in the line string.
static void pointsToWKB(QgsWkbPtr &wkb, const QgsPointSequenceV2 &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
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.
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.
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform) override
Transforms the geometry using a coordinate transform.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
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.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
void setY(double y)
Sets the point's y-coordinate.
double zAt(int index) const
Returns the z-coordinate of the specified node in the line string.
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 y() const
Returns the point's y-coordinate.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
virtual QgsLineStringV2 * curveToLine() const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
QgsWKBTypes::Type readHeader() const
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
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.
static double sqrDistance2D(const QgsPointV2 &pt1, const QgsPointV2 &pt2)
Returns the squared 2D distance between two points.
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
double z() const
Returns the point's z-coordinate.
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.
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.
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.
virtual QString geometryType() const override
Returns a unique string representing the geometry type.
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.
double yAt(int index) const
Returns the y-coordinate of the specified node in the line string.
static QDomElement pointsToGML3(const QgsPointSequenceV2 &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element.
double mAt(int index) const
Returns the m value of the specified node in the line string.
void setXAt(int index, double x)
Sets the x-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 addVertex(const QgsPointV2 &pt)
Adds a new vertex to the end of the line string.
const T & at(int i) const
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.
virtual bool isClosed() const
Returns true if the curve is closed.
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.
double m() const
Returns the point's m value.
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.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT 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'.
int wkbSize() const override
Returns the size of the WKB representation of the geometry.
void sumUpArea(double &sum) const override
Calculates the area of the curve.
Abstract base class for curved geometry type.
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.
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.
void setMAt(int index, double m)
Sets the m value of the specified node in the line string.