Skip to content

Commit

Permalink
Re-add QgsGeometryEngine::combine taking a list of QgsAbstractGeometries
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 23, 2017
1 parent efc00c3 commit fde740a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/core/geometry/qgsgeometryengine.sip
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class QgsGeometryEngine
%Docstring
Calculate the combination of this and ``geom``.

.. versionadded:: 3.0
:rtype: QgsAbstractGeometry
%End

virtual QgsAbstractGeometry *combine( const QList<QgsAbstractGeometry *> &geomList, QString *errorMsg ) const = 0 /Factory/;
%Docstring
Calculate the combination of this and ``geometries``.

.. versionadded:: 3.0
:rtype: QgsAbstractGeometry
%End
Expand Down
7 changes: 7 additions & 0 deletions src/core/geometry/qgsgeometryengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class CORE_EXPORT QgsGeometryEngine
*/
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;

/**
* Calculate the combination of this and \a geometries.
*
* \since QGIS 3.0 \a geom is a pointer
*/
virtual QgsAbstractGeometry *combine( const QList<QgsAbstractGeometry *> &geomList, QString *errorMsg ) const = 0 SIP_FACTORY;

/**
* Calculate the combination of this and \a geometries.
*
Expand Down
24 changes: 24 additions & 0 deletions src/core/geometry/qgsgeos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,30 @@ QgsAbstractGeometry *QgsGeos::combine( const QgsAbstractGeometry *geom, QString
return overlay( geom, OverlayUnion, errorMsg ).release();
}

QgsAbstractGeometry *QgsGeos::combine( const QList<QgsAbstractGeometry *> &geomList, QString *errorMsg ) const
{
QVector< GEOSGeometry * > geosGeometries;
geosGeometries.reserve( geomList.size() );
for ( const QgsAbstractGeometry *g : geomList )
{
if ( !g )
continue;

geosGeometries << asGeos( g, mPrecision ).release();
}

geos::unique_ptr geomUnion;
try
{
geos::unique_ptr geomCollection = createGeosCollection( GEOS_GEOMETRYCOLLECTION, geosGeometries );
geomUnion.reset( GEOSUnaryUnion_r( geosinit.ctxt, geomCollection.get() ) );
}
CATCH_GEOS_WITH_ERRMSG( nullptr )

std::unique_ptr< QgsAbstractGeometry > result = fromGeos( geomUnion.get() );
return result.release();
}

QgsAbstractGeometry *QgsGeos::combine( const QList<QgsGeometry> &geomList, QString *errorMsg ) const
{
QVector< GEOSGeometry * > geosGeometries;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsgeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
std::unique_ptr< QgsAbstractGeometry > subdivide( int maxNodes, QString *errorMsg = nullptr ) const;

QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const override;
QgsAbstractGeometry *combine( const QList<QgsAbstractGeometry *> &geomList, QString *errorMsg ) const override;
QgsAbstractGeometry *combine( const QList< QgsGeometry > &, QString *errorMsg = nullptr ) const override;
QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const override;
QgsAbstractGeometry *buffer( double distance, int segments, QString *errorMsg = nullptr ) const override;
Expand Down

0 comments on commit fde740a

Please sign in to comment.