QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
31 #include <nlohmann/json.hpp>
41 mBoundingBox(
c.mBoundingBox ),
42 mHasCachedValidity(
c.mHasCachedValidity ),
43 mValidityFailureReason(
c.mValidityFailureReason )
45 int nGeoms =
c.mGeometries.size();
47 for (
int i = 0; i < nGeoms; ++i )
59 int nGeoms =
c.mGeometries.size();
61 for (
int i = 0; i < nGeoms; ++i )
76 const QgsGeometryCollection *otherCollection = qgsgeometry_cast< const QgsGeometryCollection * >( &other );
77 if ( !otherCollection )
113 auto result = qgis::make_unique< QgsGeometryCollection >();
115 return result.release();
132 std::unique_ptr<QgsGeometryCollection> result;
136 std::unique_ptr<QgsAbstractGeometry> gridified { geom->
snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing ) };
146 return result.release();
154 if ( geom->removeDuplicateNodes( epsilon, useZValues ) ) result =
true;
178 if (
id.part < 0 || id.part >=
mGeometries.count() )
185 if ( part ==
id.part )
187 int partNumber = geometry->vertexNumberFromVertexId(
QgsVertexId( 0,
id.ring,
id.vertex ) );
188 if ( partNumber == -1 )
190 return number + partNumber;
194 number += geometry->nCoordinates();
220 if ( !geometry->isEmpty() )
267 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
270 int dim = ( *it )->dimension();
281 return QStringLiteral(
"GeometryCollection" );
288 g->transform( ct, d, transformZ );
297 g->transform( t, zTranslate, zScale, mTranslate, mScale );
304 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
325 wkbPtr >> nGeometries;
327 QVector<QgsAbstractGeometry *> geometryListBackup =
mGeometries;
330 for (
int i = 0; i < nGeometries; ++i )
343 qDeleteAll( geometryListBackup );
362 int binarySize =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
363 QVector<QByteArray> wkbForGeometries;
368 QByteArray wkb( geom->asWkb( flags ) );
369 binarySize += wkb.length();
370 wkbForGeometries << wkb;
375 wkbArray.resize( binarySize );
378 wkb << static_cast<quint32>(
wkbType() );
379 wkb << static_cast<quint32>( wkbForGeometries.count() );
380 for (
const QByteArray &wkbForGeometry : qgis::as_const( wkbForGeometries ) )
382 wkb << wkbForGeometry;
392 wkt += QStringLiteral(
" EMPTY" );
395 wkt += QLatin1String(
" (" );
398 QString childWkt = geom->asWkt(
precision );
401 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
403 wkt += childWkt +
',';
405 if ( wkt.endsWith(
',' ) )
416 QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral(
"MultiGeometry" ) );
419 QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral(
"geometryMember" ) );
420 elemGeometryMember.appendChild( geom->asGml2( doc,
precision, ns, axisOrder ) );
421 elemMultiGeometry.appendChild( elemGeometryMember );
423 return elemMultiGeometry;
428 QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral(
"MultiGeometry" ) );
431 QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral(
"geometryMember" ) );
432 elemGeometryMember.appendChild( geom->asGml3( doc,
precision, ns, axisOrder ) );
433 elemMultiGeometry.appendChild( elemGeometryMember );
435 return elemMultiGeometry;
440 json coordinates( json::array( ) );
443 coordinates.push_back( geom->asJsonObject(
precision ) );
447 {
"type",
"GeometryCollection" },
448 {
"geometries", coordinates }
455 kml.append( QLatin1String(
"<MultiGeometry>" ) );
456 const QVector< QgsAbstractGeometry * > &geometries =
mGeometries;
459 kml.append( geometry->asKml(
precision ) );
461 kml.append( QLatin1String(
"</MultiGeometry>" ) );
467 if ( mBoundingBox.
isNull() )
496 else if ( geomBox.
isNull() )
513 mHasCachedValidity =
false;
514 mValidityFailureReason.clear();
521 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
522 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
526 QgsCoordinateSequence::const_iterator cIt = geomCoords.constBegin();
527 for ( ; cIt != geomCoords.constEnd(); ++cIt )
529 sequence.push_back( *cIt );
540 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
541 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
543 count += ( *geomIt )->nCoordinates();
582 return mGeometries.at(
id.part )->nextVertex(
id, vertex );
592 bool success =
mGeometries.at( position.
part )->insertVertex( position, vertex );
607 bool success =
mGeometries.at( position.
part )->moveVertex( position, newPos );
646 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
647 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
649 length += ( *geomIt )->length();
657 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
658 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
660 area += ( *geomIt )->area();
668 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
669 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
684 qDeleteAll( subtypes );
689 if (
parts.second.compare( QLatin1String(
"EMPTY" ), Qt::CaseInsensitive ) == 0 )
692 QString defChildWkbType = QStringLiteral(
"%1%2%3 " ).arg( defaultChildWkbType,
is3D() ? QStringLiteral(
"Z" ) : QString(),
isMeasure() ? QStringLiteral(
"M" ) : QString() );
695 for (
const QString &childWkt : blocks )
699 bool success =
false;
715 qDeleteAll( subtypes );
719 qDeleteAll( subtypes );
727 hasZ = hasZ || geom->is3D();
728 hasM = hasM || geom->isMeasure();
742 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
745 if ( ( *it )->hasCurvedSegments() )
757 if ( !geomCollection )
763 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
764 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
766 geomCollection->
addGeometry( ( *geomIt )->segmentize( tolerance, toleranceType ) );
768 return geom.release();
835 if ( flags == 0 && mHasCachedValidity )
838 error = mValidityFailureReason;
839 return error.isEmpty();
846 mValidityFailureReason = !res ? error : QString();
847 mHasCachedValidity =
true;
861 geom->addZValue( zValue );
876 geom->addMValue( mValue );
916 geom->filterVertices( filter );
947 newCollection->addGeometry( geom->toCurveType() );
949 return newCollection.release();
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.
QgsAbstractGeometry * childGeometry(int index) const override
Returns pointer to child geometry (for geometries with child geometries - i.e.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
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.
static Type linearType(Type type)
Returns the linear type for a WKB type.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Point geometry type, with support for z-dimension and m-values.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
int numGeometries() const
Returns the number of geometries within the collection.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
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.
Multi line string geometry collection.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
double length() const override
Returns the planar, 2-dimensional length of the geometry.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
QVector< QgsAbstractGeometry * > mGeometries
Type
The WKB type describes the number of dimensions a geometry has.
QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
QgsWkbTypes::Type mWkbType
Multi surface geometry collection.
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type.
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.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
double perimeter() const override
Returns the planar, 2-dimensional perimeter of the geometry.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
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 dimension() const override
Returns the inherent dimension of the geometry.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
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.
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.
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.
AxisOrder
Axis order for GML generation.
bool isEmpty() const override
Returns true if the geometry is empty.
Multi curve geometry collection.
~QgsGeometryCollection() override
@ FlagAllowSelfTouchingHoles
Indicates that self-touching holes are permitted. OGC validity states that self-touching holes are NO...
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.
bool operator!=(const QgsAbstractGeometry &other) const override
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry * > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
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.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
Multi polygon geometry collection.
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.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
bool isValid(QString &error, int flags=0) const override
Checks validity of the geometry, and returns true if the geometry is valid.
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.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
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.
bool isMeasure() const
Returns true if the geometry contains m values.
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)
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.
static Type dropZ(Type type)
Drops the z dimension (if present) for a WKB type and returns the new type.
QgsWkbTypes::Type readHeader() const
readHeader
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 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()).
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override SIP_THROW(QgsCsException)
Transforms the geometry using a coordinate transform.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Compound curve geometry type.
QString geometryType() const override
Returns a unique string representing the geometry type.
double area() const override
Returns the planar, 2-dimensional area of the geometry.