Skip to content

Commit

Permalink
Remove geos include from qgsgeometry.h
Browse files Browse the repository at this point in the history
Avoids the need to include geos from some build targets
  • Loading branch information
nyalldawson committed Apr 26, 2018
1 parent 3e2694a commit d5626d9
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 191 deletions.
6 changes: 0 additions & 6 deletions python/core/geometry/qgsgeometry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@





typedef QVector<QgsPointXY> QgsPolylineXY;

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



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

.. versionadded:: 3.0
%End


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


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


static QgsGeometry fromQPointF( QPointF point );
%Docstring
Construct geometry from a QPointF
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgszonalstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( const QgsGeometry &poly,
cellCenterY = rasterBBox.yMaximum() - pixelOffsetY * cellSizeY - cellSizeY / 2;
stats.reset();

geos::unique_ptr polyGeos( poly.exportToGeos() );
geos::unique_ptr polyGeos( QgsGeos::asGeos( poly ) );
if ( !polyGeos )
{
return;
}

GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();
geos::prepared_unique_ptr polyGeosPrepared( GEOSPrepare_r( geosctxt, polyGeos.get() ) );
if ( !polyGeosPrepared )
{
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsfieldformatter.h"
#include "qgsfieldformatterregistry.h"
#include "qgsformannotation.h"
#include "qgsgeos.h"
#include "qgsguiutils.h"
#include "qgshtmlannotation.h"
#include "qgsprojectionselectiondialog.h"
Expand Down
39 changes: 0 additions & 39 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,6 @@ void QgsGeometry::fromWkb( const QByteArray &wkb )
reset( QgsGeometryFactory::geomFromWkb( ptr ) );
}

GEOSGeometry *QgsGeometry::exportToGeos( double precision ) const
{
if ( !d->geometry )
{
return nullptr;
}

return QgsGeos::asGeos( d->geometry.get(), precision ).release();
}


QgsWkbTypes::Type QgsGeometry::wkbType() const
{
if ( !d->geometry )
Expand Down Expand Up @@ -356,12 +345,6 @@ bool QgsGeometry::isMultipart() const
return QgsWkbTypes::isMultiType( d->geometry->wkbType() );
}

void QgsGeometry::fromGeos( GEOSGeometry *geos )
{
reset( QgsGeos::fromGeos( geos ) );
GEOSGeom_destroy_r( QgsGeos::getGEOSHandler(), geos );
}

QgsPointXY QgsGeometry::closestVertex( const QgsPointXY &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist ) const
{
if ( !d->geometry )
Expand Down Expand Up @@ -765,23 +748,6 @@ QgsGeometry QgsGeometry::removeInteriorRings( double minimumRingArea ) const
}
}

QgsGeometry::OperationResult QgsGeometry::addPart( GEOSGeometry *newPart )
{
if ( !d->geometry )
{
return QgsGeometry::InvalidBaseGeometry;
}
if ( !newPart )
{
return QgsGeometry::AddPartNotMultiGeometry;
}

detach();

std::unique_ptr< QgsAbstractGeometry > geom = QgsGeos::fromGeos( newPart );
return QgsGeometryEditUtils::addPart( d->geometry.get(), std::move( geom ) );
}

QgsGeometry::OperationResult QgsGeometry::translate( double dx, double dy, double dz, double dm )
{
if ( !d->geometry )
Expand Down Expand Up @@ -2646,11 +2612,6 @@ void QgsGeometry::convertPolygon( const QgsPolygon &input, QgsPolygonXY &output
}
}

GEOSContextHandle_t QgsGeometry::getGEOSHandler()
{
return QgsGeos::getGEOSHandler();
}

QgsGeometry QgsGeometry::fromQPointF( QPointF point )
{
return QgsGeometry( qgis::make_unique< QgsPoint >( point.x(), point.y() ) );
Expand Down
38 changes: 0 additions & 38 deletions src/core/geometry/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@ email : morb at ozemail dot com dot au
#include <QString>
#include <QVector>

#include <geos_c.h>
#include <climits>
#include <limits>
#include <memory>

#include "qgis_core.h"
#include "qgis.h"


#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
#define GEOSGeometry struct GEOSGeom_t
#define GEOSCoordSequence struct GEOSCoordSeq_t
#endif

#include "qgsabstractgeometry.h"
#include "qgsfeature.h"
#include "qgspointxy.h"
Expand Down Expand Up @@ -274,13 +267,6 @@ class CORE_EXPORT QgsGeometry
static QgsGeometry createWedgeBuffer( const QgsPoint &center, double azimuth, double angularWidth,
double outerRadius, double innerRadius = 0 );

/**
* Set the geometry, feeding in a geometry in GEOS format.
* This class will take ownership of the buffer.
* \note not available in Python bindings
*/
void fromGeos( GEOSGeometry *geos ) SIP_SKIP;

/**
* Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
* This class will take ownership of the buffer.
Expand All @@ -294,14 +280,6 @@ class CORE_EXPORT QgsGeometry
*/
void fromWkb( const QByteArray &wkb );

/**
* Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)
* \param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
* \since QGIS 3.0
* \note not available in Python bindings
*/
GEOSGeometry *exportToGeos( double precision = 0 ) const SIP_SKIP;

/**
* Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
* \see type
Expand Down Expand Up @@ -647,14 +625,6 @@ class CORE_EXPORT QgsGeometry
*/
OperationResult addPart( QgsAbstractGeometry *part SIP_TRANSFER, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );

/**
* Adds a new island polygon to a multipolygon feature
* \param newPart part to add. Ownership is NOT transferred.
* \returns OperationResult a result code: success or reason of failure
* \note not available in python bindings
*/
OperationResult addPart( GEOSGeometry *newPart ) SIP_SKIP;

/**
* Adds a new island polygon to a multipolygon feature
* \returns OperationResult a result code: success or reason of failure
Expand Down Expand Up @@ -1517,13 +1487,6 @@ class CORE_EXPORT QgsGeometry
*/
QString lastError() const;

/**
* Return GEOS context handle
* \since QGIS 2.6
* \note not available in Python
*/
static GEOSContextHandle_t getGEOSHandler() SIP_SKIP;

/**
* Construct geometry from a QPointF
* \param point source QPointF
Expand Down Expand Up @@ -1821,7 +1784,6 @@ class CORE_EXPORT QgsGeometry
std::unique_ptr< QgsPolygon > smoothPolygon( const QgsPolygon &polygon, const unsigned int iterations = 1, const double offset = 0.25,
double minimumDistance = -1, double maxAngle = 180.0 ) const;


}; // class QgsGeometry

Q_DECLARE_METATYPE( QgsGeometry )
Expand Down
39 changes: 39 additions & 0 deletions src/core/geometry/qgsgeos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ email : marco.hugentobler at sourcepole dot com
#include "qgsmultipolygon.h"
#include "qgslogger.h"
#include "qgspolygon.h"
#include "qgsgeometryeditutils.h"
#include <limits>
#include <cstdio>

Expand Down Expand Up @@ -133,6 +134,44 @@ QgsGeos::QgsGeos( const QgsAbstractGeometry *geometry, double precision )
cacheGeos();
}

QgsGeometry QgsGeos::geometryFromGeos( GEOSGeometry *geos )
{
QgsGeometry g( QgsGeos::fromGeos( geos ) );
GEOSGeom_destroy_r( QgsGeos::getGEOSHandler(), geos );
return g;
}

QgsGeometry QgsGeos::geometryFromGeos( geos::unique_ptr geos )
{
QgsGeometry g( QgsGeos::fromGeos( geos.get() ) );
return g;
}

geos::unique_ptr QgsGeos::asGeos( const QgsGeometry &geometry, double precision )
{
if ( geometry.isNull() )
{
return nullptr;
}

return asGeos( geometry.constGet(), precision );
}

QgsGeometry::OperationResult QgsGeos::addPart( QgsGeometry &geometry, GEOSGeometry *newPart )
{
if ( geometry.isNull() )
{
return QgsGeometry::InvalidBaseGeometry;
}
if ( !newPart )
{
return QgsGeometry::AddPartNotMultiGeometry;
}

std::unique_ptr< QgsAbstractGeometry > geom = fromGeos( newPart );
return QgsGeometryEditUtils::addPart( geometry.get(), std::move( geom ) );
}

void QgsGeos::geometryChanged()
{
mGeos.reset();
Expand Down
35 changes: 35 additions & 0 deletions src/core/geometry/qgsgeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ email : marco.hugentobler at sourcepole dot com
#include "qgsgeometry.h"
#include <geos_c.h>

#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
#define GEOSGeometry struct GEOSGeom_t
#define GEOSCoordSequence struct GEOSCoordSeq_t
#endif

class QgsLineString;
class QgsPolygon;
class QgsGeometry;
Expand Down Expand Up @@ -106,6 +111,24 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
*/
QgsGeos( const QgsAbstractGeometry *geometry, double precision = 0 );

/**
* Creates a new QgsGeometry object, feeding in a geometry in GEOS format.
* This class will take ownership of the buffer.
*/
static QgsGeometry geometryFromGeos( GEOSGeometry *geos );

/**
* Creates a new QgsGeometry object, feeding in a geometry in GEOS format.
*/
static QgsGeometry geometryFromGeos( geos::unique_ptr geos );

/**
* Adds a new island polygon to a multipolygon feature
* \param newPart part to add. Ownership is NOT transferred.
* \returns OperationResult a result code: success or reason of failure
*/
static QgsGeometry::OperationResult addPart( QgsGeometry &geometry, GEOSGeometry *newPart );

void geometryChanged() override;
void prepareGeometry() override;

Expand Down Expand Up @@ -315,6 +338,18 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
*/
static std::unique_ptr< QgsAbstractGeometry > fromGeos( const GEOSGeometry *geos );
static std::unique_ptr< QgsPolygon > fromGeosPolygon( const GEOSGeometry *geos );


/**
* Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)
* \param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
*/
static geos::unique_ptr asGeos( const QgsGeometry &geometry, double precision = 0 );

/**
* Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)
* \param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
*/
static geos::unique_ptr asGeos( const QgsAbstractGeometry *geom, double precision = 0 );
static QgsPoint coordSeqPoint( const GEOSCoordSequence *cs, int i, bool hasZ, bool hasM );

Expand Down
8 changes: 4 additions & 4 deletions src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ FeaturePart::~FeaturePart()
void FeaturePart::extractCoords( const GEOSGeometry *geom )
{
const GEOSCoordSequence *coordSeq = nullptr;
GEOSContextHandle_t geosctxt = geosContext();
GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();

type = GEOSGeomTypeId_r( geosctxt, geom );

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

GEOSContextHandle_t ctxt = geosContext();
GEOSContextHandle_t ctxt = QgsGeos::getGEOSHandler();
int geomType = GEOSGeomTypeId_r( ctxt, mGeos );

double sizeCost = 0;
Expand Down Expand Up @@ -1661,7 +1661,7 @@ bool FeaturePart::isConnected( FeaturePart *p2 )

try
{
return ( GEOSPreparedTouches_r( geosContext(), preparedGeom(), p2->mGeos ) == 1 );
return ( GEOSPreparedTouches_r( QgsGeos::getGEOSHandler(), preparedGeom(), p2->mGeos ) == 1 );
}
catch ( GEOSException &e )
{
Expand All @@ -1677,7 +1677,7 @@ bool FeaturePart::mergeWithFeaturePart( FeaturePart *other )
if ( !other->mGeos )
other->createGeosGeom();

GEOSContextHandle_t ctxt = geosContext();
GEOSContextHandle_t ctxt = QgsGeos::getGEOSHandler();
try
{
GEOSGeometry *g1 = GEOSGeom_clone_r( ctxt, mGeos );
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/geomfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool GeomFunction::containsCandidate( const GEOSPreparedGeometry *geom, double x
if ( !geom )
return false;

GEOSContextHandle_t geosctxt = geosContext();
GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();
GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, 5, 2 );

GEOSCoordSeq_setX_r( geosctxt, coord, 0, x );
Expand Down

0 comments on commit d5626d9

Please sign in to comment.