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;
239 int size = mX.
size();
241 for (
int i = 1; i < size; ++i )
243 dx = mX.
at( i ) - mX.
at( i - 1 );
244 dy = mY.
at( i ) - mY.
at( i - 1 );
245 length += sqrt( dx * dx + dy * dy );
286 if ( i < 0 || i >= mX.
size() )
291 double x = mX.
at( i );
292 double y = mY.
at( i );
312 else if ( hasZ && hasM )
335 if ( index >= 0 && index < mX.
size() )
336 return mX.
at( index );
343 if ( index >= 0 && index < mY.
size() )
344 return mY.
at( index );
351 if ( index >= 0 && index < mZ.
size() )
352 return mZ.
at( index );
359 if ( index >= 0 && index < mM.
size() )
360 return mM.
at( index );
367 if ( index >= 0 && index < mX.
size() )
374 if ( index >= 0 && index < mY.
size() )
381 if ( index >= 0 && index < mZ.
size() )
387 if ( index >= 0 && index < mM.
size() )
401 for (
int i = 0; i < nPoints; ++i )
419 bool hasZ = firstPt.
is3D();
443 for (
int i = 0; i < points.
size(); ++i )
445 mX[i] = points.
at( i ).x();
446 mY[i] = points.
at( i ).y();
449 mZ[i] = points.
at( i ).z();
453 mM[i] = points.
at( i ).m();
529 std::reverse( copy->mX.
begin(), copy->mX.
end() );
530 std::reverse( copy->mY.
begin(), copy->mY.
end() );
533 std::reverse( copy->mZ.
begin(), copy->mZ.
end() );
537 std::reverse( copy->mM.
begin(), copy->mM.
end() );
566 for (
int i = 1; i < nPoints; ++i )
580 for (
int i = 0; i < mX.
count(); ++i )
591 return compoundCurve;
602 double* zArray = mZ.
data();
608 zArray =
new double[nPoints];
609 for (
int i = 0; i < nPoints; ++i )
625 for (
int i = 0; i < nPoints; ++i )
628 t.
map( mX.
at( i ), mY.
at( i ), &x, &y );
673 mX[position.
vertex] = newPos.
x();
674 mY[position.
vertex] = newPos.
y();
677 mZ[position.
vertex] = newPos.
z();
681 mM[position.
vertex] = newPos.
m();
744 double segmentPtX, segmentPtY;
746 int size = mX.
size();
752 else if ( size == 1 )
758 for (
int i = 1; i < size; ++i )
760 double prevX = mX.
at( i - 1 );
761 double prevY = mY.
at( i - 1 );
762 double currentX = mX.
at( i );
763 double currentY = mY.
at( i );
765 if ( testDist < sqrDist )
768 segmentPt.
setX( segmentPtX );
769 segmentPt.
setY( segmentPtY );
774 vertexAfter.
part = 0;
775 vertexAfter.
ring = 0;
805 if ( numPoints == 1 )
808 double totalLineLength = 0.0;
809 double prevX = mX.
at( 0 );
810 double prevY = mY.
at( 0 );
816 double currentX = mX.
at( i );
817 double currentY = mY.
at( i );
818 double segmentLength = sqrt( qPow( currentX - prevX, 2.0 ) +
819 qPow( currentY - prevY, 2.0 ) );
823 totalLineLength += segmentLength;
824 sumX += segmentLength * 0.5 * ( currentX + prevX );
825 sumY += segmentLength * 0.5 * ( currentY + prevY );
833 return QgsPointV2( sumX / totalLineLength, sumY / totalLineLength );
849 for (
int i = 0; i < maxIndex; ++i )
851 sum += 0.5 * ( mX.
at( i ) * mY.
at( i + 1 ) - mY.
at( i ) * mX.
at( i + 1 ) );
855 void QgsLineStringV2::importVerticesFromWkb(
const QgsConstWkbPtr& wkb )
865 for (
int i = 0; i < nVertices; ++i )
898 if ( mX.
count() < 2 )
910 double currentX = mX.
at( 0 );
911 double currentY = mY.
at( 0 );
912 double afterX = mX.
at( 1 );
913 double afterY = mY.
at( 1 );
916 else if ( vertex.
vertex == 0 )
929 double previousX = mX.
at( vertex.
vertex - 1 );
930 double previousY = mY.
at( vertex.
vertex - 1 );
931 double currentX = mX.
at( vertex.
vertex );
932 double currentY = mY.
at( vertex.
vertex );
933 double afterX = mX.
at( vertex.
vertex + 1 );
934 double afterY = mY.
at( vertex.
vertex + 1 );
962 for (
int i = 0; i < nPoints; ++i )
993 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]; }.
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.
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)
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)
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 QgsLineStringV2 * curveToLine() const override
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
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.
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.
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.
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 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.
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 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.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
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
Calculates the area of the curve.
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.