19#include <nlohmann/json.hpp>
29#include "moc_qgsabstractgeometry.cpp"
58 return ( diff > 0 ) - ( diff < 0 );
98 const bool hasZ = subgeom->
is3D();
131 double xmin = std::numeric_limits<double>::max();
132 double ymin = std::numeric_limits<double>::max();
133 double zmin = std::numeric_limits<double>::max();
134 double xmax = -std::numeric_limits<double>::max();
135 double ymax = -std::numeric_limits<double>::max();
136 double zmax = -std::numeric_limits<double>::max();
149 xmin = std::min( xmin, x );
150 xmax = std::max( xmax, x );
152 ymin = std::min( ymin, y );
153 ymax = std::max( ymax, y );
155 zmin = std::min( zmin, z );
156 zmax = std::max( zmax, z );
165 xmin = std::min( xmin, x );
166 xmax = std::max( xmax, x );
168 ymin = std::min( ymin, y );
169 ymax = std::max( ymax, y );
171 zmin = std::numeric_limits<double>::quiet_NaN();
172 zmax = std::numeric_limits<double>::quiet_NaN();
175 return QgsBox3D( xmin, ymin, zmin, xmax, ymax, zmax );
225 if ( !suffix.isEmpty() )
234 return QString::fromStdString(
asJsonObject( precision ).dump() );
239 Q_UNUSED( precision )
267 for ( ; j < n; i = j++ )
275 const double d = vi.
x() * vj.
y() - vj.
x() * vi.
y();
277 Cx += ( vi.
x() + vj.
x() ) * d;
278 Cy += ( vi.
y() + vj.
y() ) * d;
284 for (
int i = 0; i < n - 1; ++i )
290 return QgsPoint( Cx / ( n - 1 ), Cy / ( n - 1 ) );
294 return QgsPoint( v0.
x() + Cx / ( 3. * A ), v0.
y() + Cy / ( 3. * A ) );
314 addZValue( std::numeric_limits<double>::quiet_NaN() );
323 addMValue( std::numeric_limits<double>::quiet_NaN() );
444 Q_UNUSED( tolerance )
445 Q_UNUSED( toleranceType )
453 levels.fill( Level() );
455 levels[0].index = index;
462 if ( depth == 0 && levels[0].index >= levels[0].g->childCount() )
465 Q_ASSERT( !levels[depth].g->hasChildGeometries() );
467 ++levels[depth].index;
470 while ( depth > 0 && levels[depth].index >= levels[depth].g->childCount() )
473 ++levels[depth].index;
490 Q_ASSERT( !levels[depth].g->hasChildGeometries() );
491 return levels[depth].g->childPoint( levels[depth].index );
496 int part = 0, ring = 0, vertex = levels[depth].index;
501 else if ( depth == 1 )
504 part = levels[0].index;
506 ring = levels[0].index;
508 else if ( depth == 2 )
510 part = levels[0].index;
511 ring = levels[1].index;
521 if (
const QgsCurve *curve =
dynamic_cast<const QgsCurve *
>( levels[depth].g ) )
524 curve->pointAt( vertex, p, vertexType );
527 return QgsVertexId( part, ring, vertex, vertexType );
532 if ( depth != other.depth )
534 return std::equal( std::begin( levels ), std::begin( levels ) + depth + 1, std::begin( other.levels ) );
537void QgsAbstractGeometry::vertex_iterator::digDown()
539 if ( levels[depth].g->hasChildGeometries() && levels[depth].index >= levels[depth].g->childCount() )
543 while ( levels[depth].g->hasChildGeometries() )
546 Q_ASSERT( depth < 3 );
547 levels[depth].index = 0;
548 levels[depth].g = levels[depth - 1].g->childGeometry( levels[depth - 1].index );
604 return mGeometry == other.mGeometry && mIndex == other.mIndex;
660 return mGeometry == other.mGeometry && mIndex == other.mIndex;
669bool QgsAbstractGeometry::vertex_iterator::Level::operator==(
const QgsAbstractGeometry::vertex_iterator::Level &other )
const
671 return g == other.g && index == other.index;
VertexType
Types of vertex.
@ Segment
The actual start or end point of a segment.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ LineString25D
LineString25D.
@ CompoundCurve
CompoundCurve.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ CircularString
CircularString.
@ GeometryCollection
GeometryCollection.
@ CurvePolygon
CurvePolygon.
@ MultiSurface
MultiSurface.
The part_iterator class provides an STL-style iterator for const references to geometry parts.
const_part_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next part and returns an iterator to the n...
const_part_iterator()=default
Create invalid iterator.
const QgsAbstractGeometry * operator*() const
Returns the current item.
int partNumber() const
Returns the part number of the current item.
bool operator==(const_part_iterator other) const
The part_iterator class provides an STL-style iterator for geometry parts.
part_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next part and returns an iterator to the n...
part_iterator()=default
Create invalid iterator.
QgsAbstractGeometry * operator*() const
Returns the current item.
bool operator==(part_iterator other) const
int partNumber() const
Returns the part number of the current item.
The vertex_iterator class provides an STL-style iterator for vertices.
vertex_iterator()=default
Create invalid iterator.
bool operator==(const vertex_iterator &other) const
QgsPoint operator*() const
Returns the current item.
vertex_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next vertex and returns an iterator to the...
QgsVertexId vertexId() const
Returns vertex ID of the current item.
Abstract base class for all geometries.
virtual QgsPoint childPoint(int index) const
Returns point at index (for geometries without child geometries - i.e.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
virtual bool convertTo(Qgis::WkbType type)
Converts the geometry to a specified type.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
virtual QgsBox3D calculateBoundingBox3D() const
Calculates the minimal 3D bounding box for the geometry.
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
QgsVertexIterator vertices() const
Returns a read-only, Java-style iterator for traversal of vertices of all the geometry,...
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
bool isMeasure() const
Returns true if the geometry contains m values.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
virtual void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QgsBox3D boundingBox3D() const =0
Returns the 3D bounding box for the geometry.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
int sortIndex() const
Returns the sort index for the geometry, used in the compareTo() method to compare geometries of diff...
QString wktTypeStr() const
Returns the WKT type string of the geometry.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual double area3D() const
Returns the 3-dimensional surface area of the geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
QString asJson(int precision=17)
Returns a GeoJSON representation of the geometry as a QString.
part_iterator parts_end()
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary const part after the last part of the geometry.
virtual bool isEmpty() const
Returns true if the geometry is empty.
virtual json asJsonObject(int precision=17) const
Returns a json object representation of the geometry.
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual bool hasChildGeometries() const
Returns whether the geometry has any child geometries (false for point / curve, true otherwise).
virtual bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
virtual void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
virtual int compareTo(const QgsAbstractGeometry *other) const
Comparator for sorting of geometry.
QgsAbstractGeometry()=default
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
virtual int compareToSameClass(const QgsAbstractGeometry *other) const =0
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
A 3-dimensional box composed of x, y, z coordinates.
bool intersects(const QgsBox3D &other) const
Returns true if box intersects with another box.
QgsRectangle toRectangle() const
Converts the box to a 2D rectangle.
Abstract base class for curved geometry type.
int partCount() const override
Returns count of parts contained in the geometry.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
Java-style iterator for const traversal of parts of a geometry.
const QgsAbstractGeometry * next()
Returns next part of the geometry (undefined behavior if hasNext() returns false before calling next(...
Java-style iterator for traversal of parts of a geometry.
QgsAbstractGeometry * next()
Returns next part of the geometry (undefined behavior if hasNext() returns false before calling next(...
Point geometry type, with support for z-dimension and m-values.
double & rx()
Returns a reference to the x-coordinate of this point.
double & ry()
Returns a reference to the y-coordinate of this point.
A rectangle specified with double values.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
Java-style iterator for traversal of vertices of a geometry.
QgsPoint next()
Returns next vertex of the geometry (undefined behavior if hasNext() returns false before calling nex...
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
Utility class for identifying a unique vertex within a geometry.