26 #include <QDomDocument>
62 importVerticesFromWkb( wkbPtr );
69 importVerticesFromWkb( wkb );
88 int size =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
96 unsigned char* geomPtr =
new unsigned char[binarySize];
99 wkb << static_cast<quint32>(
wkbType() );
123 return elemLineString;
152 int size = mCoords.
size();
154 for (
int i = 1; i < size; ++i )
156 dx = mCoords[i].x() - mCoords[ i - 1 ].x();
157 dy = mCoords[i].y() - mCoords[ i - 1 ].y();
158 length += sqrt( dx * dx + dy * dy );
188 return mCoords.
size();
193 if ( mCoords.
size() <= i )
233 for (
int i = 0; i < nPoints; ++i )
241 if ( points.
size() < 1 )
252 bool hasZ = firstPt.
is3D();
275 for (
int i = 0; i < points.
size(); ++i )
277 mCoords[i].rx() = points[i].x();
278 mCoords[i].ry() = points[i].y();
281 mZ[i] = points[i].z();
285 mM[i] = points[i].m();
302 mCoords += line->mCoords;
322 path.
moveTo( mCoords[0] );
325 for (
int i = 1; i < nPoints; ++i )
327 path.
lineTo( mCoords[i] );
343 mCoords = t.
map( mCoords );
371 mCoords[position.
vertex].rx() = newPos.
x();
372 mCoords[position.
vertex].ry() = newPos.
y();
375 mZ[position.
vertex] = newPos.
z();
379 mM[position.
vertex] = newPos.
m();
428 double segmentPtX, segmentPtY;
430 int size = mCoords.
size();
431 for (
int i = 1; i < size; ++i )
433 const QPointF& prev = mCoords.
at( i - 1 );
434 const QPointF& currentPt = mCoords.
at( i );
436 if ( testDist < sqrDist )
439 segmentPt.
setX( segmentPtX );
440 segmentPt.
setY( segmentPtY );
445 vertexAfter.
part = 0; vertexAfter.
ring = 0; vertexAfter.
vertex = i;
465 for (
int i = 0; i < maxIndex; ++i )
467 sum += 0.5 * ( mCoords[i].x() * mCoords[i+1].y() - mCoords[i].y() * mCoords[i+1].x() );
471 void QgsLineStringV2::importVerticesFromWkb(
const QgsConstWkbPtr& wkb )
477 mCoords.
resize( nVertices );
480 for (
int i = 0; i < nVertices; ++i )
482 wkb >> mCoords[i].rx();
483 wkb >> mCoords[i].ry();
515 else if ( vertex.
vertex == 0 )
545 for (
int i = 0; i < nPoints; ++i )
562 for (
int i = 0; i < nPoints; ++i )
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
void close()
Appends first point if not already closed.
A rectangle specified with double values.
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
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 (...
virtual bool moveVertex(const QgsVertexId &position, const QgsPointV2 &newPos) override
Moves a vertex within the geometry.
QPointF currentPosition() const
QDomNode appendChild(const QDomNode &newChild)
void append(const T &value)
void push_back(const T &value)
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.
void points(QList< QgsPointV2 > &pt) const override
Returns a list of points within the curve.
virtual bool insertVertex(const QgsVertexId &position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
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
static QString pointsToWKT(const QList< QgsPointV2 > &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list.
static QString pointsToJSON(const QList< QgsPointV2 > &points, int precision)
Returns a geoJSON coordinates string.
void insert(int i, const T &value)
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
static double linePerpendicularAngle(double x1, double y1, double x2, double y2)
Calculates angle perpendicular to line.
virtual bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
void moveTo(const QPointF &point)
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.
void append(const QgsLineStringV2 *line)
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)
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.
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...
QgsWKBTypes::Type readHeader() const
double vertexAngle(const QgsVertexId &vertex) const override
Returns approximate rotation angle for a vertex.
bool pointAt(int i, QgsPointV2 &vertex, QgsVertexId::VertexType &type) const override
Returns the point and vertex id of a point within the curve.
static Type flatType(Type type)
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
virtual bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
Utility class for identifying a unique vertex within a geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
Line string geometry type.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
void lineTo(const QPointF &endPoint)
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
void fromWkbPoints(QgsWKBTypes::Type type, const QgsConstWkbPtr &wkb)
virtual double length() const override
Returns the length of the geometry.
QgsWKBTypes::Type mWkbType
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
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.
virtual bool deleteVertex(const QgsVertexId &position) override
Deletes a vertex within the geometry.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
static QDomElement pointsToGML3(const QList< QgsPointV2 > &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element.
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.
virtual QgsPointV2 startPoint() const override
Returns the starting point of the curve.
void addVertex(const QgsPointV2 &pt)
const T & at(int i) const
void setPoints(const QList< QgsPointV2 > &points)
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.
static QList< QgsPointV2 > pointsFromWKT(const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string.
QgsRectangle mBoundingBox
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 parseType(const QString &wktStr)
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.
virtual bool fromWkb(const unsigned char *wkb) override
Sets the geometry from a WKB 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.
static void pointsToWKB(QgsWkbPtr &wkb, const QList< QgsPointV2 > &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
static QDomElement pointsToGML2(const QList< QgsPointV2 > &points, QDomDocument &doc, int precision, const QString &ns)
Returns a gml::coordinates DOM element.
virtual void clear() override
Clears the geometry, ie reset it to a null geometry.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
int numPoints() const override
Returns the number of points in the curve.