Skip to content

Commit d5626d9

Browse files
committed
Remove geos include from qgsgeometry.h
Avoids the need to include geos from some build targets
1 parent 3e2694a commit d5626d9

26 files changed

+164
-191
lines changed

python/core/geometry/qgsgeometry.sip.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414

1515

16-
17-
1816
typedef QVector<QgsPointXY> QgsPolylineXY;
1917

2018
typedef QVector<QgsPoint> QgsPolyline;
@@ -230,15 +228,13 @@ need to be segmentized to convert to a standard Polygon geometry.
230228
%End
231229

232230

233-
234231
void fromWkb( const QByteArray &wkb );
235232
%Docstring
236233
Set the geometry, feeding in the buffer containing OGC Well-Known Binary
237234

238235
.. versionadded:: 3.0
239236
%End
240237

241-
242238
QgsWkbTypes::Type wkbType() const;
243239
%Docstring
244240
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
@@ -606,7 +602,6 @@ Adds a new part to this geometry.
606602
:return: OperationResult a result code: success or reason of failure
607603
%End
608604

609-
610605
OperationResult addPart( const QgsGeometry &newPart ) /PyName=addPartGeometry/;
611606
%Docstring
612607
Adds a new island polygon to a multipolygon feature
@@ -1540,7 +1535,6 @@ was performed on the geometry.
15401535
.. versionadded:: 3.0
15411536
%End
15421537

1543-
15441538
static QgsGeometry fromQPointF( QPointF point );
15451539
%Docstring
15461540
Construct geometry from a QPointF

src/analysis/vector/qgszonalstatistics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,13 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( const QgsGeometry &poly,
395395
cellCenterY = rasterBBox.yMaximum() - pixelOffsetY * cellSizeY - cellSizeY / 2;
396396
stats.reset();
397397

398-
geos::unique_ptr polyGeos( poly.exportToGeos() );
398+
geos::unique_ptr polyGeos( QgsGeos::asGeos( poly ) );
399399
if ( !polyGeos )
400400
{
401401
return;
402402
}
403403

404-
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
404+
GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();
405405
geos::prepared_unique_ptr polyGeosPrepared( GEOSPrepare_r( geosctxt, polyGeos.get() ) );
406406
if ( !polyGeosPrepared )
407407
{

src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
185185
#include "qgsfieldformatter.h"
186186
#include "qgsfieldformatterregistry.h"
187187
#include "qgsformannotation.h"
188+
#include "qgsgeos.h"
188189
#include "qgsguiutils.h"
189190
#include "qgshtmlannotation.h"
190191
#include "qgsprojectionselectiondialog.h"

src/core/geometry/qgsgeometry.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,6 @@ void QgsGeometry::fromWkb( const QByteArray &wkb )
304304
reset( QgsGeometryFactory::geomFromWkb( ptr ) );
305305
}
306306

307-
GEOSGeometry *QgsGeometry::exportToGeos( double precision ) const
308-
{
309-
if ( !d->geometry )
310-
{
311-
return nullptr;
312-
}
313-
314-
return QgsGeos::asGeos( d->geometry.get(), precision ).release();
315-
}
316-
317-
318307
QgsWkbTypes::Type QgsGeometry::wkbType() const
319308
{
320309
if ( !d->geometry )
@@ -356,12 +345,6 @@ bool QgsGeometry::isMultipart() const
356345
return QgsWkbTypes::isMultiType( d->geometry->wkbType() );
357346
}
358347

359-
void QgsGeometry::fromGeos( GEOSGeometry *geos )
360-
{
361-
reset( QgsGeos::fromGeos( geos ) );
362-
GEOSGeom_destroy_r( QgsGeos::getGEOSHandler(), geos );
363-
}
364-
365348
QgsPointXY QgsGeometry::closestVertex( const QgsPointXY &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist ) const
366349
{
367350
if ( !d->geometry )
@@ -765,23 +748,6 @@ QgsGeometry QgsGeometry::removeInteriorRings( double minimumRingArea ) const
765748
}
766749
}
767750

768-
QgsGeometry::OperationResult QgsGeometry::addPart( GEOSGeometry *newPart )
769-
{
770-
if ( !d->geometry )
771-
{
772-
return QgsGeometry::InvalidBaseGeometry;
773-
}
774-
if ( !newPart )
775-
{
776-
return QgsGeometry::AddPartNotMultiGeometry;
777-
}
778-
779-
detach();
780-
781-
std::unique_ptr< QgsAbstractGeometry > geom = QgsGeos::fromGeos( newPart );
782-
return QgsGeometryEditUtils::addPart( d->geometry.get(), std::move( geom ) );
783-
}
784-
785751
QgsGeometry::OperationResult QgsGeometry::translate( double dx, double dy, double dz, double dm )
786752
{
787753
if ( !d->geometry )
@@ -2646,11 +2612,6 @@ void QgsGeometry::convertPolygon( const QgsPolygon &input, QgsPolygonXY &output
26462612
}
26472613
}
26482614

2649-
GEOSContextHandle_t QgsGeometry::getGEOSHandler()
2650-
{
2651-
return QgsGeos::getGEOSHandler();
2652-
}
2653-
26542615
QgsGeometry QgsGeometry::fromQPointF( QPointF point )
26552616
{
26562617
return QgsGeometry( qgis::make_unique< QgsPoint >( point.x(), point.y() ) );

src/core/geometry/qgsgeometry.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,13 @@ email : morb at ozemail dot com dot au
2121
#include <QString>
2222
#include <QVector>
2323

24-
#include <geos_c.h>
2524
#include <climits>
2625
#include <limits>
2726
#include <memory>
2827

2928
#include "qgis_core.h"
3029
#include "qgis.h"
3130

32-
33-
#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
34-
#define GEOSGeometry struct GEOSGeom_t
35-
#define GEOSCoordSequence struct GEOSCoordSeq_t
36-
#endif
37-
3831
#include "qgsabstractgeometry.h"
3932
#include "qgsfeature.h"
4033
#include "qgspointxy.h"
@@ -274,13 +267,6 @@ class CORE_EXPORT QgsGeometry
274267
static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth,
275268
double outerRadius, double innerRadius = 0 );
276269

277-
/**
278-
* Set the geometry, feeding in a geometry in GEOS format.
279-
* This class will take ownership of the buffer.
280-
* \note not available in Python bindings
281-
*/
282-
void fromGeos( GEOSGeometry *geos ) SIP_SKIP;
283-
284270
/**
285271
* Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
286272
* This class will take ownership of the buffer.
@@ -294,14 +280,6 @@ class CORE_EXPORT QgsGeometry
294280
*/
295281
void fromWkb( const QByteArray &wkb );
296282

297-
/**
298-
* Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)
299-
* \param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
300-
* \since QGIS 3.0
301-
* \note not available in Python bindings
302-
*/
303-
GEOSGeometry *exportToGeos( double precision = 0 ) const SIP_SKIP;
304-
305283
/**
306284
* Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
307285
* \see type
@@ -647,14 +625,6 @@ class CORE_EXPORT QgsGeometry
647625
*/
648626
OperationResult addPart( QgsAbstractGeometry *part SIP_TRANSFER, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
649627

650-
/**
651-
* Adds a new island polygon to a multipolygon feature
652-
* \param newPart part to add. Ownership is NOT transferred.
653-
* \returns OperationResult a result code: success or reason of failure
654-
* \note not available in python bindings
655-
*/
656-
OperationResult addPart( GEOSGeometry *newPart ) SIP_SKIP;
657-
658628
/**
659629
* Adds a new island polygon to a multipolygon feature
660630
* \returns OperationResult a result code: success or reason of failure
@@ -1517,13 +1487,6 @@ class CORE_EXPORT QgsGeometry
15171487
*/
15181488
QString lastError() const;
15191489

1520-
/**
1521-
* Return GEOS context handle
1522-
* \since QGIS 2.6
1523-
* \note not available in Python
1524-
*/
1525-
static GEOSContextHandle_t getGEOSHandler() SIP_SKIP;
1526-
15271490
/**
15281491
* Construct geometry from a QPointF
15291492
* \param point source QPointF
@@ -1821,7 +1784,6 @@ class CORE_EXPORT QgsGeometry
18211784
std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, const unsigned int iterations = 1, const double offset = 0.25,
18221785
double minimumDistance = -1, double maxAngle = 180.0 ) const;
18231786

1824-
18251787
}; // class QgsGeometry
18261788

18271789
Q_DECLARE_METATYPE( QgsGeometry )

src/core/geometry/qgsgeos.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ email : marco.hugentobler at sourcepole dot com
2525
#include "qgsmultipolygon.h"
2626
#include "qgslogger.h"
2727
#include "qgspolygon.h"
28+
#include "qgsgeometryeditutils.h"
2829
#include <limits>
2930
#include <cstdio>
3031

@@ -133,6 +134,44 @@ QgsGeos::QgsGeos( const QgsAbstractGeometry *geometry, double precision )
133134
cacheGeos();
134135
}
135136

137+
QgsGeometry QgsGeos::geometryFromGeos( GEOSGeometry *geos )
138+
{
139+
QgsGeometry g( QgsGeos::fromGeos( geos ) );
140+
GEOSGeom_destroy_r( QgsGeos::getGEOSHandler(), geos );
141+
return g;
142+
}
143+
144+
QgsGeometry QgsGeos::geometryFromGeos( geos::unique_ptr geos )
145+
{
146+
QgsGeometry g( QgsGeos::fromGeos( geos.get() ) );
147+
return g;
148+
}
149+
150+
geos::unique_ptr QgsGeos::asGeos( const QgsGeometry &geometry, double precision )
151+
{
152+
if ( geometry.isNull() )
153+
{
154+
return nullptr;
155+
}
156+
157+
return asGeos( geometry.constGet(), precision );
158+
}
159+
160+
QgsGeometry::OperationResult QgsGeos::addPart( QgsGeometry &geometry, GEOSGeometry *newPart )
161+
{
162+
if ( geometry.isNull() )
163+
{
164+
return QgsGeometry::InvalidBaseGeometry;
165+
}
166+
if ( !newPart )
167+
{
168+
return QgsGeometry::AddPartNotMultiGeometry;
169+
}
170+
171+
std::unique_ptr< QgsAbstractGeometry > geom = fromGeos( newPart );
172+
return QgsGeometryEditUtils::addPart( geometry.get(), std::move( geom ) );
173+
}
174+
136175
void QgsGeos::geometryChanged()
137176
{
138177
mGeos.reset();

src/core/geometry/qgsgeos.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ email : marco.hugentobler at sourcepole dot com
2323
#include "qgsgeometry.h"
2424
#include <geos_c.h>
2525

26+
#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
27+
#define GEOSGeometry struct GEOSGeom_t
28+
#define GEOSCoordSequence struct GEOSCoordSeq_t
29+
#endif
30+
2631
class QgsLineString;
2732
class QgsPolygon;
2833
class QgsGeometry;
@@ -106,6 +111,24 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
106111
*/
107112
QgsGeos( const QgsAbstractGeometry *geometry, double precision = 0 );
108113

114+
/**
115+
* Creates a new QgsGeometry object, feeding in a geometry in GEOS format.
116+
* This class will take ownership of the buffer.
117+
*/
118+
static QgsGeometry geometryFromGeos( GEOSGeometry *geos );
119+
120+
/**
121+
* Creates a new QgsGeometry object, feeding in a geometry in GEOS format.
122+
*/
123+
static QgsGeometry geometryFromGeos( geos::unique_ptr geos );
124+
125+
/**
126+
* Adds a new island polygon to a multipolygon feature
127+
* \param newPart part to add. Ownership is NOT transferred.
128+
* \returns OperationResult a result code: success or reason of failure
129+
*/
130+
static QgsGeometry::OperationResult addPart( QgsGeometry &geometry, GEOSGeometry *newPart );
131+
109132
void geometryChanged() override;
110133
void prepareGeometry() override;
111134

@@ -315,6 +338,18 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
315338
*/
316339
static std::unique_ptr< QgsAbstractGeometry > fromGeos( const GEOSGeometry *geos );
317340
static std::unique_ptr< QgsPolygon > fromGeosPolygon( const GEOSGeometry *geos );
341+
342+
343+
/**
344+
* Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)
345+
* \param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
346+
*/
347+
static geos::unique_ptr asGeos( const QgsGeometry &geometry, double precision = 0 );
348+
349+
/**
350+
* Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)
351+
* \param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
352+
*/
318353
static geos::unique_ptr asGeos( const QgsAbstractGeometry *geom, double precision = 0 );
319354
static QgsPoint coordSeqPoint( const GEOSCoordSequence *cs, int i, bool hasZ, bool hasM );
320355

src/core/pal/feature.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ FeaturePart::~FeaturePart()
8585
void FeaturePart::extractCoords( const GEOSGeometry *geom )
8686
{
8787
const GEOSCoordSequence *coordSeq = nullptr;
88-
GEOSContextHandle_t geosctxt = geosContext();
88+
GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();
8989

9090
type = GEOSGeomTypeId_r( geosctxt, geom );
9191

@@ -1602,7 +1602,7 @@ void FeaturePart::addSizePenalty( int nbp, QList< LabelPosition * > &lPos, doubl
16021602
if ( !mGeos )
16031603
createGeosGeom();
16041604

1605-
GEOSContextHandle_t ctxt = geosContext();
1605+
GEOSContextHandle_t ctxt = QgsGeos::getGEOSHandler();
16061606
int geomType = GEOSGeomTypeId_r( ctxt, mGeos );
16071607

16081608
double sizeCost = 0;
@@ -1661,7 +1661,7 @@ bool FeaturePart::isConnected( FeaturePart *p2 )
16611661

16621662
try
16631663
{
1664-
return ( GEOSPreparedTouches_r( geosContext(), preparedGeom(), p2->mGeos ) == 1 );
1664+
return ( GEOSPreparedTouches_r( QgsGeos::getGEOSHandler(), preparedGeom(), p2->mGeos ) == 1 );
16651665
}
16661666
catch ( GEOSException &e )
16671667
{
@@ -1677,7 +1677,7 @@ bool FeaturePart::mergeWithFeaturePart( FeaturePart *other )
16771677
if ( !other->mGeos )
16781678
other->createGeosGeom();
16791679

1680-
GEOSContextHandle_t ctxt = geosContext();
1680+
GEOSContextHandle_t ctxt = QgsGeos::getGEOSHandler();
16811681
try
16821682
{
16831683
GEOSGeometry *g1 = GEOSGeom_clone_r( ctxt, mGeos );

src/core/pal/geomfunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ bool GeomFunction::containsCandidate( const GEOSPreparedGeometry *geom, double x
322322
if ( !geom )
323323
return false;
324324

325-
GEOSContextHandle_t geosctxt = geosContext();
325+
GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();
326326
GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, 5, 2 );
327327

328328
GEOSCoordSeq_setX_r( geosctxt, coord, 0, x );

0 commit comments

Comments
 (0)