40 for (
int i = 0; i < nGeoms; ++i )
54 for (
int i = 0; i < nGeoms; ++i )
70 if ( !otherCollection )
95 auto result = qgis::make_unique< QgsGeometryCollection >();
97 return result.release();
114 std::unique_ptr<QgsGeometryCollection> result;
118 std::unique_ptr<QgsAbstractGeometry> gridified { geom->
snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing ) };
128 return result.release();
136 result = result || geom->removeDuplicateNodes( epsilon, useZValues );
155 mGeometries.at( vertex.
part )->adjacentVertices( vertex, previousVertex, nextVertex );
160 if (
id.part < 0 || id.part >=
mGeometries.count() )
167 if ( part ==
id.part )
169 int partNumber = geometry->vertexNumberFromVertexId(
QgsVertexId( 0,
id.ring,
id.vertex ) );
170 if ( partNumber == -1 )
172 return number + partNumber;
176 number += geometry->nCoordinates();
197 if ( !geometry->isEmpty() )
244 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
247 int dim = ( *it )->dimension();
258 return QStringLiteral(
"GeometryCollection" );
265 g->transform( ct, d, transformZ );
274 g->transform( t, zTranslate, zScale, mTranslate, mScale );
281 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
302 wkbPtr >> nGeometries;
304 QVector<QgsAbstractGeometry *> geometryListBackup =
mGeometries;
306 for (
int i = 0; i < nGeometries; ++i )
319 qDeleteAll( geometryListBackup );
338 int binarySize =
sizeof( char ) +
sizeof( quint32 ) +
sizeof( quint32 );
339 QVector<QByteArray> wkbForGeometries;
344 QByteArray wkb( geom->asWkb() );
345 binarySize += wkb.length();
346 wkbForGeometries << wkb;
351 wkbArray.resize( binarySize );
354 wkb << static_cast<quint32>(
wkbType() );
355 wkb << static_cast<quint32>( wkbForGeometries.count() );
356 for (
const QByteArray &wkbForGeometry : qgis::as_const( wkbForGeometries ) )
358 wkb << wkbForGeometry;
368 QString childWkt = geom->asWkt( precision );
371 childWkt = childWkt.mid( childWkt.indexOf(
'(' ) );
373 wkt += childWkt +
',';
375 if ( wkt.endsWith(
',' ) )
385 QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral(
"MultiGeometry" ) );
388 QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral(
"geometryMember" ) );
389 elemGeometryMember.appendChild( geom->asGml2( doc, precision, ns, axisOrder ) );
390 elemMultiGeometry.appendChild( elemGeometryMember );
392 return elemMultiGeometry;
397 QDomElement elemMultiGeometry = doc.createElementNS( ns, QStringLiteral(
"MultiGeometry" ) );
400 QDomElement elemGeometryMember = doc.createElementNS( ns, QStringLiteral(
"geometryMember" ) );
401 elemGeometryMember.appendChild( geom->asGml3( doc, precision, ns, axisOrder ) );
402 elemMultiGeometry.appendChild( elemGeometryMember );
404 return elemMultiGeometry;
409 QString json = QStringLiteral(
"{\"type\": \"GeometryCollection\", \"geometries\": [" );
412 json += geom->asJson( precision ) +
", ";
414 if ( json.endsWith( QLatin1String(
", " ) ) )
418 json += QLatin1String(
"] }" );
424 if ( mBoundingBox.
isNull() )
456 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
457 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
461 QgsCoordinateSequence::const_iterator cIt = geomCoords.constBegin();
462 for ( ; cIt != geomCoords.constEnd(); ++cIt )
464 sequence.push_back( *cIt );
475 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
476 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
478 count += ( *geomIt )->nCoordinates();
517 return mGeometries.at(
id.part )->nextVertex(
id, vertex );
527 bool success =
mGeometries.at( position.
part )->insertVertex( position, vertex );
542 bool success =
mGeometries.at( position.
part )->moveVertex( position, newPos );
581 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
582 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
584 length += ( *geomIt )->length();
592 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
593 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
595 area += ( *geomIt )->area();
603 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
604 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
606 perimeter += ( *geomIt )->perimeter();
619 qDeleteAll( subtypes );
624 QString defChildWkbType = QStringLiteral(
"%1%2%3 " ).arg( defaultChildWkbType,
is3D() ?
"Z" :
"",
isMeasure() ?
"M" :
"" );
627 for (
const QString &childWkt : blocks )
631 bool success =
false;
647 qDeleteAll( subtypes );
651 qDeleteAll( subtypes );
659 hasZ = hasZ || geom->is3D();
660 hasM = hasM || geom->isMeasure();
674 QVector< QgsAbstractGeometry * >::const_iterator it =
mGeometries.constBegin();
677 if ( ( *it )->hasCurvedSegments() )
689 if ( !geomCollection )
694 QVector< QgsAbstractGeometry * >::const_iterator geomIt =
mGeometries.constBegin();
695 for ( ; geomIt !=
mGeometries.constEnd(); ++geomIt )
697 geomCollection->
addGeometry( ( *geomIt )->segmentize( tolerance, toleranceType ) );
699 return geom.release();
773 geom->addZValue( zValue );
788 geom->addMValue( mValue );
828 geom->filterVertices( filter );
848 newCollection->addGeometry( geom->toCurveType() );
850 return newCollection.release();
bool isMeasure() const
Returns true if the geometry contains m values.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkb(QgsConstWkbPtr &wkb)
Construct geometry from a WKB string.
virtual bool removeGeometry(int nr)
Removes a geometry from the collection.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
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...
bool operator!=(const QgsAbstractGeometry &other) const override
virtual bool isEmpty() const
Returns true if the geometry is empty.
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.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(QgsWkbTypes::Type t)
Returns empty geometry from wkb type.
virtual bool deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
bool operator==(const QgsAbstractGeometry &other) const override
void clear() override
Clears the geometry, ie reset it to a null geometry.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
Multi point geometry collection.
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 (...
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...
QVector< QgsRingSequence > QgsCoordinateSequence
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
bool hasCurvedSegments() const override
Returns true if the geometry contains curved segments.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
Multi line string geometry collection.
Curve polygon geometry type.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual bool wktOmitChildType() const
Returns whether child type names are omitted from Wkt representations of the collection.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
QgsGeometryCollection & operator=(const QgsGeometryCollection &c)
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
bool dropMValue() override
Drops any measure values which exist in the geometry.
static endian_t endian()
Returns whether this machine uses big or little endian.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT.
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type.
Multi surface geometry collection.
double length() const override
Returns the length of the geometry.
QString asJson(int precision=17) const override
Returns a GeoJSON representation of the geometry.
QgsWkbTypes::Type mWkbType
virtual bool insertGeometry(QgsAbstractGeometry *g, int index)
Inserts a geometry before a specified index and takes ownership.
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
QString wktTypeStr() const
Returns the WKT type string of the geometry.
bool isEmpty() const override
Returns true if the geometry is empty.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Type
The WKB type describes the number of dimensions a geometry has.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
void swapXy() override
Swaps the x and y coordinates from the geometry.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
int dimension() const override
Returns the inherent dimension of the geometry.
Utility class for identifying a unique vertex within a geometry.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership...
double area() const override
Returns the area of the geometry.
QgsAbstractGeometry * childGeometry(int index) const override
Returns pointer to child geometry (for geometries with child geometries - i.e.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Multi curve geometry collection.
QgsAbstractGeometry * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
QString geometryType() const override
Returns a unique string representing the geometry type.
QByteArray asWkb() const override
Returns a WKB representation of the geometry.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Abstract base class for all geometries.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.
Point geometry type, with support for z-dimension and m-values.
bool fromCollectionWkt(const QString &wkt, const QVector< QgsAbstractGeometry *> &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
AxisOrder
Axis order for GML generation.
int numGeometries() const
Returns the number of geometries within the collection.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
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...
int partCount() const override
Returns count of parts contained in the geometry.
QVector< QgsAbstractGeometry *> mGeometries
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.
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.
static Type dropZ(Type type)
Drops the z dimension (if present) for a WKB type and returns the new type.
Multi polygon geometry collection.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Line string geometry type, with support for z-dimension and m-values.
QgsGeometryCollection * toCurveType() const override
Returns the geometry converted to the more generic curve type.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
double perimeter() const override
Returns the perimeter of the geometry.
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 bool hasM(Type type)
Tests whether a WKB type contains m values.
Compound curve geometry type.
Circular string geometry type.
QgsGeometryCollection * clone() const override
Clones the geometry by performing a deep copy.
static Type flatType(Type type)
Returns the flat type for a WKB type.
QgsWkbTypes::Type readHeader() const
readHeader
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
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'. Negativ values mean left a...
static double closestSegmentFromComponents(T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon)
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
double vertexAngle(QgsVertexId vertex) const override
Returns approximate angle at a vertex.
QgsRectangle calculateBoundingBox() const override
Default calculator for the minimal bounding box for the geometry.
~QgsGeometryCollection() override
int ringCount(int part=0) const override
Returns the number of rings of which this geometry is built.