QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
32 #include <nlohmann/json.hpp>
42 mBoundingBox(
c.mBoundingBox ),
43 mHasCachedValidity(
c.mHasCachedValidity ),
44 mValidityFailureReason(
c.mValidityFailureReason )
46 int nGeoms =
c.mGeometries.size();
48 for (
int i = 0; i < nGeoms; ++i )
60 int nGeoms =
c.mGeometries.size();
62 for (
int i = 0; i < nGeoms; ++i )
77 const QgsGeometryCollection *otherCollection = qgsgeometry_cast< const QgsGeometryCollection * >( &other );
78 if ( !otherCollection )
114 auto result = std::make_unique< QgsGeometryCollection >();
116 return result.release();
133 std::unique_ptr<QgsGeometryCollection> result;
137 std::unique_ptr<QgsAbstractGeometry> gridified { geom->
snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing ) };
147 return result.release();
155 if ( geom->removeDuplicateNodes( epsilon, useZValues ) ) result =
true;
179 if (
id.part < 0 || id.part >=
mGeometries.count() )
186 if ( part ==
id.part )
188 int partNumber = geometry->vertexNumberFromVertexId(
QgsVertexId( 0,
id.ring,
id.vertex ) );
189 if ( partNumber == -1 )
191 return number + partNumber;
195 number += geometry->nCoordinates();
209 if ( !mBoundingBox.
isNull() )
221 if ( geometry->boundingBoxIntersects( rectangle ) )
250 if ( !geometry->isEmpty() )
275 index = std::min(
static_cast<int>(
mGeometries.count() ), index );
298 geometry->normalize();
302 return a->compareTo( b ) > 0;
309 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
312 int dim = ( *it )->dimension();
323 return QStringLiteral(
"GeometryCollection" );
330 g->transform( ct, d, transformZ );
339 g->transform( t, zTranslate, zScale, mTranslate, mScale );
346 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
358 QPainterPath partPath = geom->asQPainterPath();
359 if ( !partPath.isEmpty() )
360 p.addPath( partPath );
379 wkbPtr >> nGeometries;
381 QVector<QgsAbstractGeometry *> geometryListBackup =
mGeometries;
384 for (
int i = 0; i < nGeometries; ++i )
397 qDeleteAll( geometryListBackup );
416 int binarySize =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
421 binarySize += geom->wkbSize( flags );
430 int countNonNull = 0;
443 wkb << static_cast<quint32>(
wkbType() );
444 wkb << static_cast<quint32>( countNonNull );
449 wkb << geom->asWkb( flags );
460 wkt += QLatin1String(
" EMPTY" );
463 wkt += QLatin1String(
" (" );
466 QString childWkt = geom->asWkt(
precision );
469 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
471 wkt += childWkt +
',';
473 if ( wkt.endsWith(
',' ) )
484 QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral(
"MultiGeometry" ) );
487 QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral(
"geometryMember" ) );
488 elemGeometryMember.appendChild( geom->asGml2( doc,
precision, ns, axisOrder ) );
489 elemMultiGeometry.appendChild( elemGeometryMember );
491 return elemMultiGeometry;
496 QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral(
"MultiGeometry" ) );
499 QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral(
"geometryMember" ) );
500 elemGeometryMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
501 elemMultiGeometry.appendChild( elemGeometryMember );
503 return elemMultiGeometry;
508 json coordinates( json::array( ) );
511 coordinates.push_back( geom->asJsonObject(
precision ) );
515 {
"type",
"GeometryCollection" },
516 {
"geometries", coordinates }
523 kml.append( QLatin1String(
"<MultiGeometry>" ) );
524 const QVector< QgsAbstractGeometry * > &geometries =
mGeometries;
527 kml.append( geometry->asKml(
precision ) );
529 kml.append( QLatin1String(
"</MultiGeometry>" ) );
535 if ( mBoundingBox.
isNull() )
564 else if ( geomBox.
isNull() )
581 mHasCachedValidity =
false;
582 mValidityFailureReason.clear();
589 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
590 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
594 QgsCoordinateSequence::const_iterator cIt = geomCoords.constBegin();
595 for ( ; cIt != geomCoords.constEnd(); ++cIt )
597 sequence.push_back( *cIt );
608 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
609 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
611 count += ( *geomIt )->nCoordinates();
650 return mGeometries.at(
id.part )->nextVertex(
id, vertex );
660 bool success =
mGeometries.at( position.
part )->insertVertex( position, vertex );
675 bool success =
mGeometries.at( position.
part )->moveVertex( position, newPos );
714 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
715 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
717 length += ( *geomIt )->length();
725 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
726 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
728 area += ( *geomIt )->area();
736 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
737 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
752 qDeleteAll( subtypes );
757 QString secondWithoutParentheses =
parts.second;
758 secondWithoutParentheses = secondWithoutParentheses.remove(
'(' ).remove(
')' ).simplified().remove(
' ' );
759 if ( (
parts.second.compare( QLatin1String(
"EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
760 secondWithoutParentheses.isEmpty() )
763 QString defChildWkbType = QStringLiteral(
"%1%2%3 " ).arg( defaultChildWkbType,
is3D() ? QStringLiteral(
"Z" ) : QString(),
isMeasure() ? QStringLiteral(
"M" ) : QString() );
766 for (
const QString &childWkt : blocks )
770 bool success =
false;
786 qDeleteAll( subtypes );
790 qDeleteAll( subtypes );
798 hasZ = hasZ || geom->is3D();
799 hasM = hasM || geom->isMeasure();
813 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
816 if ( ( *it )->hasCurvedSegments() )
828 if ( !geomCollection )
834 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
835 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
837 geomCollection->
addGeometry( ( *geomIt )->segmentize( tolerance, toleranceType ) );
839 return geom.release();
906 if ( flags == 0 && mHasCachedValidity )
909 error = mValidityFailureReason;
910 return error.isEmpty();
914 bool res =
geos.isValid( &error, flags & Qgis::GeometryValidityFlag::AllowSelfTouchingHoles,
nullptr );
917 mValidityFailureReason = !res ? error : QString();
918 mHasCachedValidity =
true;
932 geom->addZValue( zValue );
947 geom->addMValue( mValue );
987 geom->filterVertices( filter );
1018 newCollection->addGeometry( geom->toCurveType() );
1020 return newCollection.release();
1040 res = geom->transform( transformer, feedback );
1071 const QgsGeometryCollection *otherCollection = qgsgeometry_cast<const QgsGeometryCollection *>( other );
1072 if ( !otherCollection )
1081 const int comparison = aGeom->
compareTo( bGeom );
1082 if ( comparison != 0 )
bool intersects(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle intersects with other rectangle.
QVector< QgsRingSequence > QgsCoordinateSequence
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
QgsAbstractGeometry * childGeometry(int index) const override
Returns pointer to child geometry (for geometries with child geometries - i.e.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
static Type dropM(Type type) SIP_HOLDGIL
Drops the m dimension (if present) for a WKB type and returns the new type.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
int dimension() const override SIP_HOLDGIL
Returns the inherent dimension of the geometry.
bool hasCurvedSegments() const override SIP_HOLDGIL
Returns true if the geometry contains curved segments.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void normalize() final SIP_HOLDGIL
Reorganizes the geometry into a normalized form (or "canonical" form).
QString geometryType() const override SIP_HOLDGIL
Returns a unique string representing the geometry type.
Point geometry type, with support for z-dimension and m-values.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkb(QgsConstWkbPtr &wkb)
Construct geometry from a WKB string.
Curve polygon geometry type.
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
Contains geos related utilities and functions.
double area() const override SIP_HOLDGIL
Returns the planar, 2-dimensional area of the geometry.
Multi line string geometry collection.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
QVector< QgsAbstractGeometry * > mGeometries
Type
The WKB type describes the number of dimensions a geometry has.
QPainterPath asQPainterPath() const override
Returns the geometry represented as a QPainterPath.
QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
QgsWkbTypes::Type mWkbType
Multi surface geometry collection.
double length() const override SIP_HOLDGIL
Returns the planar, 2-dimensional length of the geometry.
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
QgsGeometryCollection * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Line string geometry type, with support for z-dimension and m-values.
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
virtual int compareTo(const QgsAbstractGeometry *other) const
Comparator for sorting of geometry.
void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) override SIP_THROW(QgsCsException)
Transforms the geometry using a coordinate transform.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
A rectangle specified with double values.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
bool operator==(const QgsAbstractGeometry &other) const override
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const override
Searches for the closest segment of the geometry to a given point.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
QgsGeometryCollection * clone() const override
Clones the geometry by performing a deep copy.
QgsGeometryCollection() SIP_HOLDGIL
Constructor for an empty geometry collection.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
int partCount() const override
Returns count of parts contained in the geometry.
static double closestSegmentFromComponents(T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon)
Circular string geometry type.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
AxisOrder
Axis order for GML generation.
Multi curve geometry collection.
~QgsGeometryCollection() override
static Type linearType(Type type) SIP_HOLDGIL
Returns the linear type for a WKB type.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
int ringCount(int part=0) const override
Returns the number of rings of which this geometry is built.
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
Does vector analysis using the geos library and handles import, export, exception handling*.
bool operator!=(const QgsAbstractGeometry &other) const override
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
double perimeter() const override SIP_HOLDGIL
Returns the planar, 2-dimensional perimeter of the geometry.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry * > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
int compareToSameClass(const QgsAbstractGeometry *other) const final
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
static endian_t endian()
Returns whether this machine uses big or little endian.
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
virtual bool wktOmitChildType() const
Returns whether child type names are omitted from Wkt representations of the collection.
static Type dropZ(Type type) SIP_HOLDGIL
Drops the z dimension (if present) for a WKB type and returns the new type.
Multi polygon geometry collection.
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
bool dropMValue() override
Drops any measure values which exist in the geometry.
QgsAbstractGeometry * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
virtual bool isEmpty() const
Returns true if the geometry is empty.
Multi point geometry collection.
Abstract base class for all geometries.
bool boundingBoxIntersects(const QgsRectangle &rectangle) const override SIP_HOLDGIL
Returns true if the bounding box of this geometry intersects with a rectangle.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform) override
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
void swapXy() override
Swaps the x and y coordinates from the geometry.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
Utility class for identifying a unique vertex within a geometry.
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
void clear() override
Clears the geometry, ie reset it to a null geometry.
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
QgsGeometryCollection & operator=(const QgsGeometryCollection &c)
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
QgsGeometryCollection * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
TransformDirection
Indicates the direction (forward or inverse) of a transform.
bool isValid(QString &error, Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const override
Checks validity of the geometry, and returns true if the geometry is valid.
QgsWkbTypes::Type readHeader() const
readHeader
virtual bool boundingBoxIntersects(const QgsRectangle &rectangle) const SIP_HOLDGIL
Returns true if the bounding box of this geometry intersects with a rectangle.
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 (...
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
void reserve(int size) SIP_HOLDGIL
Attempts to allocate memory for at least size geometries.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(QgsWkbTypes::Type t)
Returns empty geometry from wkb type.
virtual bool removeGeometry(int nr)
Removes a geometry from the collection.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Compound curve geometry type.
const QgsAbstractGeometry * simplifiedTypeRef() const override SIP_HOLDGIL
Returns a reference to the simplest lossless representation of this geometry, e.g.