28 const QgsCurve *otherCurve = qgsgeometry_cast< const QgsCurve * >( &other );
32 return equals( *otherCurve );
55 if (
is3D() && closed )
59 closed &=
qgsDoubleNear( start.
z(), end.
z() ) || ( std::isnan( start.
z() ) && std::isnan( end.
z() ) );
81 points( sequence.back().back() );
108 return pointAt(
id.vertex, vertex,
id.type );
129 if ( vertex.
vertex == n - 1 )
141 if (
id.part != 0 ||
id.ring != 0 )
143 if (
id.vertex < 0 || id.vertex >=
numPoints() )
165 std::unique_ptr<QgsLineString> lineString(
curveToLine() );
170 QString kml = lineString->asKml(
precision );
220 int minCoordinateIndex = 0;
229 minCoordinateIndex = i;
234 scroll( minCoordinateIndex );
248 if ( flags == 0 && mHasCachedValidity )
251 error = mValidityFailureReason;
252 return error.isEmpty();
259 mValidityFailureReason = !res ? error : QString();
260 mHasCachedValidity =
true;
267 std::unique_ptr< QgsLineString > segmentized(
curveToLine() );
268 return segmentized->asQPolygonF();
280 return std::numeric_limits<double>::quiet_NaN();
295 mHasCachedValidity =
false;
296 mValidityFailureReason.clear();
309 bool res =
pointAt( index, point, type );
316 const QVector<double> &srcX,
const QVector<double> &srcY,
const QVector<double> &srcZ,
const QVector<double> &srcM,
317 QVector<double> &outX, QVector<double> &outY, QVector<double> &outZ, QVector<double> &outM )
const
328 auto roundVertex = [hSpacing, vSpacing, dSpacing, mSpacing, hasZ, hasM, &srcX, &srcY, &srcZ, &srcM](
QgsPoint & out,
int i )
331 out.setX( std::round( srcX.at( i ) / hSpacing ) * hSpacing );
333 out.setX( srcX.at( i ) );
336 out.setY( std::round( srcY.at( i ) / vSpacing ) * vSpacing );
338 out.setY( srcY.at( i ) );
343 out.setZ( std::round( srcZ.at( i ) / dSpacing ) * dSpacing );
345 out.setZ( srcZ.at( i ) );
351 out.setM( std::round( srcM.at( i ) / mSpacing ) * mSpacing );
353 out.setM( srcM.at( i ) );
358 auto append = [hasZ, hasM, &outX, &outY, &outM, &outZ](
QgsPoint const & point )
360 outX.append( point.x() );
362 outY.append( point.y() );
365 outZ.append( point.z() );
368 outM.append( point.m() );
371 auto isPointEqual = [dSpacing, mSpacing, hasZ, hasM](
const QgsPoint & a,
const QgsPoint & b )
373 return ( a.x() == b.x() )
374 && ( a.y() == b.y() )
375 && ( !hasZ || dSpacing <= 0 || a.z() == b.z() )
376 && ( !hasM || mSpacing <= 0 || a.m() == b.m() );
385 roundVertex( last, 0 );
388 for (
int i = 1; i <
length; ++i )
390 roundVertex( current, i );
391 if ( !isPointEqual( current, last ) )
400 if ( outX.length() < 2 || (
isClosed() && outX.length() < 4 ) )
Abstract base class for all geometries.
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.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
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.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
Abstract base class for curved geometry type.
virtual bool equals(const QgsCurve &other) const =0
Checks whether this curve exactly equals another curve.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
void normalize() final SIP_HOLDGIL
Reorganizes the geometry into a normalized form (or "canonical" form).
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().
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 isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
virtual bool isRing() const SIP_HOLDGIL
Returns true if the curve is a ring.
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) const
Helper function for QgsCurve subclasses to snap to grids.
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.
Orientation orientation() const
Returns the curve's orientation, e.g.
bool isValid(QString &error, int flags=0) const override
Checks validity of the geometry, and returns true if the geometry is valid.
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
virtual bool isClosed2D() const SIP_HOLDGIL
Returns true if the curve is closed.
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
Orientation
Curve orientation.
@ Clockwise
Clockwise orientation.
@ CounterClockwise
Counter-clockwise orientation.
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.
QgsRectangle mBoundingBox
Cached bounding box.
virtual bool pointAt(int node, QgsPoint &point, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
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.
void reserve(int size) SIP_HOLDGIL
Attempts to allocate memory for at least size geometries.
@ FlagAllowSelfTouchingHoles
Indicates that self-touching holes are permitted. OGC validity states that self-touching holes are NO...
Does vector analysis using the geos library and handles import, export, 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.
double distance(double x, double y) const SIP_HOLDGIL
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
A rectangle specified with double values.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Type
The WKB type describes the number of dimensions a geometry has.
static Type zmType(Type type, bool hasZ, bool hasM) SIP_HOLDGIL
Returns the modified input geometry type according to hasZ / hasM.
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)
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
Utility class for identifying a unique vertex within a geometry.
VertexType
Type of vertex.