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 );
281 if ( i < 0 || i >= mX.
size() )
286 double x = mX.
at( i );
287 double y = mY.
at( i );
307 else if ( hasZ && hasM )
330 if ( index >= 0 && index < mX.
size() )
331 return mX.
at( index );
338 if ( index >= 0 && index < mY.
size() )
339 return mY.
at( index );
346 if ( index >= 0 && index < mZ.
size() )
347 return mZ.
at( index );
354 if ( index >= 0 && index < mM.
size() )
355 return mM.
at( index );
362 if ( index >= 0 && index < mX.
size() )
369 if ( index >= 0 && index < mY.
size() )
376 if ( index >= 0 && index < mZ.
size() )
382 if ( index >= 0 && index < mM.
size() )
396 for (
int i = 0; i < nPoints; ++i )
414 bool hasZ = firstPt.
is3D();
438 for (
int i = 0; i < points.
size(); ++i )
440 mX[i] = points.
at( i ).x();
441 mY[i] = points.
at( i ).y();
444 mZ[i] = points.
at( i ).z();
448 mM[i] = points.
at( i ).m();
524 std::reverse( copy->mX.
begin(), copy->mX.
end() );
525 std::reverse( copy->mY.
begin(), copy->mY.
end() );
528 std::reverse( copy->mZ.
begin(), copy->mZ.
end() );
532 std::reverse( copy->mM.
begin(), copy->mM.
end() );
561 for (
int i = 1; i < nPoints; ++i )
575 for (
int i = 0; i < mX.
count(); ++i )
586 return compoundCurve;
597 double* zArray = mZ.
data();
603 zArray =
new double[nPoints];
604 for (
int i = 0; i < nPoints; ++i )
620 for (
int i = 0; i < nPoints; ++i )
623 t.
map( mX.
at( i ), mY.
at( i ), &x, &y );
668 mX[position.
vertex] = newPos.
x();
669 mY[position.
vertex] = newPos.
y();
672 mZ[position.
vertex] = newPos.
z();
676 mM[position.
vertex] = newPos.
m();
739 double segmentPtX, segmentPtY;
741 int size = mX.
size();
742 if ( size == 0 || size == 1 )
747 for (
int i = 1; i < size; ++i )
749 double prevX = mX.
at( i - 1 );
750 double prevY = mY.
at( i - 1 );
751 double currentX = mX.
at( i );
752 double currentY = mY.
at( i );
754 if ( testDist < sqrDist )
757 segmentPt.
setX( segmentPtX );
758 segmentPt.
setY( segmentPtY );
763 vertexAfter.
part = 0;
764 vertexAfter.
ring = 0;
794 if ( numPoints == 1 )
797 double totalLineLength = 0.0;
798 double prevX = mX.
at( 0 );
799 double prevY = mY.
at( 0 );
805 double currentX = mX.
at( i );
806 double currentY = mY.
at( i );
807 double segmentLength = sqrt( qPow( currentX - prevX, 2.0 ) +
808 qPow( currentY - prevY, 2.0 ) );
812 totalLineLength += segmentLength;
813 sumX += segmentLength * 0.5 * ( currentX + prevX );
814 sumY += segmentLength * 0.5 * ( currentY + prevY );
822 return QgsPointV2( sumX / totalLineLength, sumY / totalLineLength );
835 for (
int i = 0; i < maxIndex; ++i )
837 sum += 0.5 * ( mX.
at( i ) * mY.
at( i + 1 ) - mY.
at( i ) * mX.
at( i + 1 ) );
841 void QgsLineStringV2::importVerticesFromWkb(
const QgsConstWkbPtr& wkb )
851 for (
int i = 0; i < nVertices; ++i )
884 if ( mX.
count() < 2 )
896 double currentX = mX.
at( 0 );
897 double currentY = mY.
at( 0 );
898 double afterX = mX.
at( 1 );
899 double afterY = mY.
at( 1 );
902 else if ( vertex.
vertex == 0 )
915 double previousX = mX.
at( vertex.
vertex - 1 );
916 double previousY = mY.
at( vertex.
vertex - 1 );
917 double currentX = mX.
at( vertex.
vertex );
918 double currentY = mY.
at( vertex.
vertex );
919 double afterX = mX.
at( vertex.
vertex + 1 );
920 double afterY = mY.
at( vertex.
vertex + 1 );
948 for (
int i = 0; i < nPoints; ++i )
979 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.
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
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.