Skip to content
Permalink
Browse files

Make GEOS CPP optional

  • Loading branch information
manisandro committed Sep 21, 2015
1 parent e9e638f commit 9fef5a16aebd0f826898a7caacf64d36e9d12893
Showing with 46 additions and 7 deletions.
  1. +0 −1 CMakeLists.txt
  2. +13 −1 cmake/FindGEOS.cmake
  3. +6 −2 src/core/CMakeLists.txt
  4. +22 −2 src/core/geometry/qgsgeos.cpp
  5. +5 −1 src/core/geometry/qgsgeos.h
@@ -191,7 +191,6 @@ ENDIF(NOT WIN32 AND NOT ANDROID)
# required
FIND_PACKAGE(Proj)
FIND_PACKAGE(GEOS)
SET(GEOS_CPP_LIBRARY -lgeos CACHE STRING "Path to the geos CPP library")
FIND_PACKAGE(GDAL)
FIND_PACKAGE(Expat REQUIRED)
FIND_PACKAGE(Spatialindex REQUIRED)
@@ -23,11 +23,16 @@ IF(WIN32)
IF (MINGW)
FIND_PATH(GEOS_INCLUDE_DIR geos_c.h /usr/local/include /usr/include c:/msys/local/include)
FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS /usr/local/lib /usr/lib c:/msys/local/lib)
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS /usr/local/lib /usr/lib c:/msys/local/lib)
ENDIF (MINGW)

IF (MSVC)
FIND_PATH(GEOS_INCLUDE_DIR geos_c.h $ENV{LIB_DIR}/include $ENV{INCLUDE})
FIND_LIBRARY(GEOS_LIBRARY NAMES geos geos_c_i geos_c PATHS
FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c_i geos_c PATHS
"$ENV{LIB_DIR}/lib"
$ENV{LIB}
)
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS
"$ENV{LIB_DIR}/lib"
$ENV{LIB}
)
@@ -67,6 +72,7 @@ ELSE(WIN32)

IF(CYGWIN)
FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS /usr/lib /usr/local/lib)
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS /usr/lib /usr/local/lib)
ENDIF(CYGWIN)

IF (NOT GEOS_INCLUDE_DIR OR NOT GEOS_LIBRARY OR NOT GEOS_CONFIG)
@@ -132,12 +138,16 @@ ELSE(WIN32)
#MESSAGE("DBG GEOS_CONFIG_LIBS=${GEOS_CONFIG_LIBS}")
#MESSAGE("DBG GEOS_LIB_NAME_WITH_PREFIX=${GEOS_LIB_NAME_WITH_PREFIX}")
SET(GEOS_LIB_NAME_WITH_PREFIX -lgeos_c CACHE STRING INTERNAL)
SET(GEOS_CPP_LIB_NAME_WITH_PREFIX -lgeos CACHE STRING INTERNAL)

## remove prefix -l because we need the pure name

IF (GEOS_LIB_NAME_WITH_PREFIX)
STRING(REGEX REPLACE "[-][l]" "" GEOS_LIB_NAME ${GEOS_LIB_NAME_WITH_PREFIX} )
ENDIF (GEOS_LIB_NAME_WITH_PREFIX)
IF (GEOS_CPP_LIB_NAME_WITH_PREFIX)
STRING(REGEX REPLACE "[-][l]" "" GEOS_CPP_LIB_NAME ${GEOS_CPP_LIB_NAME_WITH_PREFIX} )
ENDIF (GEOS_CPP_LIB_NAME_WITH_PREFIX)
#MESSAGE("DBG GEOS_LIB_NAME=${GEOS_LIB_NAME}")

IF (APPLE)
@@ -146,9 +156,11 @@ ELSE(WIN32)
# while still preserving user setting if given
# ***FIXME*** need to improve framework check so below not needed
SET(GEOS_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_LIB_NAME}.dylib CACHE STRING INTERNAL FORCE)
SET(GEOS_CPP_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_CPP_LIB_NAME}.dylib CACHE STRING INTERNAL FORCE)
ENDIF (NOT GEOS_LIBRARY)
ELSE (APPLE)
SET(GEOS_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_LIB_NAME}.so CACHE STRING INTERNAL)
SET(GEOS_CPP_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_CPP_LIB_NAME}.so CACHE STRING INTERNAL)
ENDIF (APPLE)
#MESSAGE("DBG GEOS_LIBRARY=${GEOS_LIBRARY}")

@@ -523,8 +523,6 @@ SET(QGIS_CORE_HDRS
${CMAKE_BINARY_DIR}/qgsconfig.h
../plugins/qgisplugin.h

geosextra/geos_c_extra.h

qgis.h
qgsattributeaction.h
qgscachedfeatureiterator.h
@@ -737,6 +735,12 @@ SET(QGIS_CORE_HDRS
geometry/qgspointv2.h
)

IF(GEOS_CPP_LIBRARY)
SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS} geosextra/geos_c_extra.cpp)
SET(QGIS_CORE_HDRS ${QGIS_CORE_HDRS} geosextra/geos_c_extra.h)
ADD_DEFINITIONS("-DHAVE_GEOS_CPP")
ENDIF(GEOS_CPP_LIBRARY)

IF (QT_MOBILITY_LOCATION_FOUND OR Qt5Positioning_FOUND)
SET(QGIS_CORE_HDRS ${QGIS_CORE_HDRS}
gps/qgsqtlocationconnection.h
@@ -117,18 +117,24 @@ class GEOSGeomScopedPtr

QgsGeos::QgsGeos( const QgsAbstractGeometryV2* geometry, int precision ): QgsGeometryEngine( geometry ), mGeos( 0 ), mGeosPrepared( 0 )
{
#ifdef HAVE_GEOS_CPP
double prec = qPow( 10, -precision );
mPrecisionModel = GEOSPrecisionModel_createFixed( 1.f / prec );
mPrecisionReducer = GEOSGeometryPrecisionReducer_create( mPrecisionModel );
#else
Q_UNUSED( precision )
#endif
cacheGeos();
}

QgsGeos::~QgsGeos()
{
#ifdef HAVE_GEOS_CPP
GEOSGeom_destroy_r( geosinit.ctxt, mGeos );
GEOSPreparedGeom_destroy_r( geosinit.ctxt, mGeosPrepared );
GEOSGeometryPrecisionReducer_destroy( mPrecisionReducer );
GEOSPrecisionModel_destroy( mPrecisionModel );
#endif
}

void QgsGeos::geometryChanged()
@@ -158,11 +164,15 @@ void QgsGeos::cacheGeos() const
}

GEOSGeometry* g = asGeos( mGeometry );
#ifdef HAVE_GEOS_CPP
if ( g )
{
mGeos = GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, g );
GEOSGeom_destroy_r( geosinit.ctxt, g );
}
#else
mGeos = g;
#endif
}

QgsAbstractGeometryV2* QgsGeos::intersection( const QgsAbstractGeometryV2& geom, QString* errorMsg ) const
@@ -1047,12 +1057,18 @@ QgsAbstractGeometryV2* QgsGeos::overlay( const QgsAbstractGeometryV2& geom, Over
{
return 0;
}

#ifdef HAVE_GEOS_CPP
GEOSGeomScopedPtr geosGeom;
geosGeom.reset( gG );

//reduce precision
GEOSGeomScopedPtr pg2;
pg2.reset( GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, geosGeom.get() ) );
#else
GEOSGeomScopedPtr pg2;
pg2.reset( gG );
#endif

try
{
@@ -1099,14 +1115,18 @@ bool QgsGeos::relation( const QgsAbstractGeometryV2& geom, Relation r, QString*
{
return false;
}
#ifdef HAVE_GEOS_CPP
GEOSGeomScopedPtr geosGeom;
geosGeom.reset( gG );

bool result = false;

GEOSGeomScopedPtr pg2;
pg2.reset( GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, geosGeom.get() ) );
#else
GEOSGeomScopedPtr pg2;
pg2.reset( gG );
#endif

bool result = false;
try
{
if ( mGeosPrepared ) //use faster version with prepared geometry
@@ -18,8 +18,10 @@ email : marco.hugentobler at sourcepole dot com

#include "qgsgeometryengine.h"
#include "qgspointv2.h"
#include "geosextra/geos_c_extra.h"
#include <geos_c.h>
#ifdef HAVE_GEOS_CPP
#include "geosextra/geos_c_extra.h"
#endif

class QgsLineStringV2;
class QgsPolygonV2;
@@ -89,9 +91,11 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
private:
mutable GEOSGeometry* mGeos;
const GEOSPreparedGeometry* mGeosPrepared;
#ifdef HAVE_GEOS_CPP
//precision reducer
GEOSPrecisionModel* mPrecisionModel;
GEOSGeometryPrecisionReducer* mPrecisionReducer;
#endif

enum Overlay
{

0 comments on commit 9fef5a1

Please sign in to comment.
You can’t perform that action at this time.