34 return equals( *otherCurve );
57 if (
is3D() && closed )
61 closed &=
qgsDoubleNear( start.
z(), end.
z() ) || ( std::isnan( start.
z() ) && std::isnan( end.
z() ) );
83 points( sequence.back().back() );
110 return pointAt(
id.vertex, vertex,
id.type );
131 if ( vertex.
vertex == n - 1 )
143 if (
id.part != 0 ||
id.ring != 0 )
145 if (
id.vertex < 0 || id.vertex >=
numPoints() )
167 std::unique_ptr<QgsLineString> lineString(
curveToLine() );
172 QString kml = lineString->asKml( precision );
222 int minCoordinateIndex = 0;
231 minCoordinateIndex = i;
236 scroll( minCoordinateIndex );
250 if ( flags == 0 && mHasCachedValidity )
253 error = mValidityFailureReason;
254 return error.isEmpty();
261 mValidityFailureReason = !res ? error : QString();
262 mHasCachedValidity =
true;
269 std::unique_ptr< QgsLineString > segmentized(
curveToLine() );
270 return segmentized->asQPolygonF();
282 return std::numeric_limits<double>::quiet_NaN();
297 mHasCachedValidity =
false;
298 mValidityFailureReason.clear();
313 const bool res =
pointAt( index, point, type );
320 const QVector<double> &srcX,
const QVector<double> &srcY,
const QVector<double> &srcZ,
const QVector<double> &srcM,
321 QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM,
bool removeRedundantPoints )
const
327 const bool hasZ =
is3D();
337 const double *xIn = srcX.constData();
338 const double *yIn = srcY.constData();
339 const double *zIn = hasZ ? srcZ.constData() :
nullptr;
340 const double *mIn = hasM ? srcM.constData() :
nullptr;
342 double previousX = 0;
343 double previousY = 0;
344 double previousZ = 0;
345 double previousM = 0;
347 for (
int i = 0; i <
length; ++i )
349 const double currentX = *xIn++;
350 const double currentY = *yIn++;
351 const double currentZ = zIn ? *zIn++ : 0;
352 const double currentM = mIn ? *mIn++ : 0;
354 const double roundedX = hSpacing > 0 ? ( std::round( currentX / hSpacing ) * hSpacing ) : currentX;
355 const double roundedY = vSpacing > 0 ? ( std::round( currentY / vSpacing ) * vSpacing ) : currentY;
356 const double roundedZ = hasZ && dSpacing > 0 ? ( std::round( currentZ / dSpacing ) * dSpacing ) : currentZ;
357 const double roundedM = hasM && mSpacing > 0 ? ( std::round( currentM / mSpacing ) * mSpacing ) : currentM;
361 outX.append( roundedX );
362 outY.append( roundedY );
364 outZ.append( roundedZ );
366 outM.append( roundedM );
371 const bool isPointEqual =
qgsDoubleNear( roundedX, previousX )
373 && ( !hasZ || dSpacing <= 0 ||
qgsDoubleNear( roundedZ, previousZ ) )
374 && ( !hasM || mSpacing <= 0 ||
qgsDoubleNear( roundedM, previousM ) );
379 bool previousPointRedundant =
false;
380 if ( removeRedundantPoints && outSize > 1 && !hasZ && !hasM )
383 outY.at( outSize - 1 ),
384 outX.at( outSize - 2 ),
385 outY.at( outSize - 2 ),
386 roundedX, roundedY ) == 0;
388 if ( previousPointRedundant )
390 outX[ outSize - 1 ] = roundedX;
391 outY[ outSize - 1 ] = roundedY;
395 outX.append( roundedX );
396 outY.append( roundedY );
398 outZ.append( roundedZ );
400 outM.append( roundedM );
405 previousX = roundedX;
406 previousY = roundedY;
407 previousZ = roundedZ;
408 previousM = roundedM;
411 if ( removeRedundantPoints &&
isClosed() && outSize > 4 && !hasZ && !hasM )
416 outX.at( outSize - 2 ),
417 outY.at( outSize - 2 ),
418 outX.at( 1 ), outY.at( 1 ) ) == 0;
419 if ( firstVertexIsRedundant )
423 outX[ outSize - 2 ] = outX.at( 0 );
424 outY[ outSize - 2 ] = outY.at( 0 );
437 return outSize >= 4 || ( !
isClosed() && outSize >= 2 );
@ AllowSelfTouchingHoles
Indicates that self-touching holes are permitted. OGC validity states that self-touching holes are NO...
AngularDirection
Angular directions.
@ CounterClockwise
Counter-clockwise direction.
@ Clockwise
Clockwise direction.
QFlags< GeometryValidityFlag > GeometryValidityFlags
Geometry validity flags.
VertexType
Types of vertex.
QFlags< GeosCreationFlag > GeosCreationFlags
Geos geometry creation behavior flags.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
virtual QgsBox3D calculateBoundingBox3D() const
Calculates the minimal 3D bounding box for the geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
virtual bool isEmpty() const
Returns true if the geometry is empty.
vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
virtual int compareTo(const QgsAbstractGeometry *other) const
Comparator for sorting of geometry.
QgsAbstractGeometry()=default
A 3-dimensional box composed of x, y, z coordinates.
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
Qgis::AngularDirection orientation() const
Returns the curve's orientation, e.g.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
virtual int numPoints() const =0
Returns the number of points in the curve.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
double sinuosity() const
Returns the curve sinuosity, which is the ratio of the curve length() to curve straightDistance2d().
bool mHasCachedSummedUpArea
void normalize() final
Reorganizes the geometry into a normalized form (or "canonical" form).
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
virtual void scroll(int firstVertexIndex)=0
Scrolls the curve vertices so that they start with the vertex at the given index.
int partCount() const override
Returns count of parts contained in the geometry.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
virtual bool isRing() const
Returns true if the curve is a ring.
virtual bool pointAt(int node, QgsPoint &point, Qgis::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
QgsBox3D boundingBox3D() const override
Returns the 3D bounding box for the geometry.
bool mHasCachedSummedUpArea3D
virtual bool isClosed() const
Returns true if the curve is closed.
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
virtual bool isClosed2D() const
Returns true if the curve is closed.
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
virtual void addToPainterPath(QPainterPath &path) const =0
Adds a curve to a painter path.
QgsCurve * toCurveType() const override
Returns the geometry converted to the more generic curve type.
virtual void sumUpArea(double &sum) const =0
Sums up the area of the curve by iterating over the vertices (shoelace formula).
bool operator==(const QgsAbstractGeometry &other) const override
bool snapToGridPrivate(double hSpacing, double vSpacing, double dSpacing, double mSpacing, const QVector< double > &srcX, const QVector< double > &srcY, const QVector< double > &srcZ, const QVector< double > &srcM, QVector< double > &outX, QVector< double > &outY, QVector< double > &outZ, QVector< double > &outM, bool removeRedundantPoints) const
Helper function for QgsCurve subclasses to snap to grids.
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
QgsBox3D mBoundingBox
Cached bounding box.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
int ringCount(int part=0) const override
Returns the number of rings of which this geometry is built.
virtual QgsPoint startPoint() const =0
Returns the starting point of the curve.
bool operator!=(const QgsAbstractGeometry &other) const override
double straightDistance2d() const
Returns the straight distance of the curve, i.e.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
virtual void points(QgsPointSequence &pt) const =0
Returns a list of points within the curve.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
static int leftOfLine(const double x, const double y, const double x1, const double y1, const double x2, const double y2)
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> (x2, y2).
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Multi point geometry collection.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
Point geometry type, with support for z-dimension and m-values.
bool isEmpty() const override
Returns true if the geometry is empty.
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Contains geos related utilities and functions.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
Utility class for identifying a unique vertex within a geometry.