Skip to content

Commit

Permalink
Remove GEOS C++ lib dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 7, 2015
1 parent bf9fe7c commit 643eb10
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 179 deletions.
1 change: 0 additions & 1 deletion ci/travis/linux/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sudo apt-get install --force-yes --no-install-recommends --no-install-suggests \
libexpat1-dev \
libfcgi-dev \
libgdal1-dev \
libgeos++-dev \
libgeos-dev \
libgsl0-dev \
libpq-dev \
Expand Down
14 changes: 1 addition & 13 deletions cmake/FindGEOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ 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_c_i geos_c PATHS
"$ENV{LIB_DIR}/lib"
$ENV{LIB}
)
FIND_LIBRARY(GEOS_CPP_LIBRARY NAMES geos PATHS
FIND_LIBRARY(GEOS_LIBRARY NAMES geos geos_c_i geos_c PATHS
"$ENV{LIB_DIR}/lib"
$ENV{LIB}
)
Expand Down Expand Up @@ -72,7 +67,6 @@ 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)
Expand Down Expand Up @@ -138,16 +132,12 @@ 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)
Expand All @@ -156,11 +146,9 @@ 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}")

Expand Down
14 changes: 2 additions & 12 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ STRING(REPLACE "\)" "\\)" JSON_HELP_FILES "${JSON_HELP_FILES}")
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/qgsexpression_texts.cpp
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/process_function_template.py ${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp.temp
COMMAND ${CMAKE_COMMAND} -DSRC=${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp.temp -DDST=${CMAKE_CURRENT_SOURCE_DIR}/qgsexpression_texts.cpp -P ${CMAKE_SOURCE_DIR}/cmake/CopyIfChanged.cmake
DEPENDS ${JSON_HELP_FILES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${JSON_HELP_FILES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

IF(ENABLE_MODELTEST)
Expand Down Expand Up @@ -756,12 +756,6 @@ 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
Expand Down Expand Up @@ -885,10 +879,6 @@ TARGET_LINK_LIBRARIES(qgis_core
${SPATIALITE_LIBRARY}
)
IF(GEOS_CPP_LIBRARY)
TARGET_LINK_LIBRARIES(qgis_core ${GEOS_CPP_LIBRARY})
ENDIF(GEOS_CPP_LIBRARY)
IF (Qt5Positioning_FOUND)
TARGET_LINK_LIBRARIES(qgis_core
Qt5::Positioning
Expand Down
44 changes: 5 additions & 39 deletions src/core/geometry/qgsgeos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,11 @@ class GEOSGeomScopedPtr

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

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

inline GEOSGeometry* QgsGeos::getReducedGeometry( GEOSGeometry* geom ) const
{
#if defined(HAVE_GEOS_CPP) || defined(HAVE_GEOS_CAPI_PRECISION_MODEL)
//reduce precision
GEOSGeometry* reduced = GEOSGeometryPrecisionReducer_reduce( mPrecisionReducer, geom );
GEOSGeom_destroy_r( geosinit.ctxt, geom );
return reduced;
#else
return geom;
#endif
}

void QgsGeos::geometryChanged()
Expand Down Expand Up @@ -174,16 +149,7 @@ void QgsGeos::cacheGeos() const
return;
}

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

QgsAbstractGeometryV2* QgsGeos::intersection( const QgsAbstractGeometryV2& geom, QString* errorMsg ) const
Expand All @@ -208,7 +174,7 @@ QgsAbstractGeometryV2* QgsGeos::combine( const QList< const QgsAbstractGeometryV
geosGeometries.resize( geomList.size() );
for ( int i = 0; i < geomList.size(); ++i )
{
geosGeometries[i] = getReducedGeometry( asGeos( geomList.at( i ) ) );
geosGeometries[i] = asGeos( geomList.at( i ) );
}

GEOSGeometry* geomUnion = 0;
Expand Down Expand Up @@ -1065,7 +1031,7 @@ QgsAbstractGeometryV2* QgsGeos::overlay( const QgsAbstractGeometryV2& geom, Over
return 0;
}

GEOSGeomScopedPtr geosGeom( getReducedGeometry( asGeos( &geom ) ) );
GEOSGeomScopedPtr geosGeom( asGeos( &geom ) );
if ( !geosGeom )
{
return 0;
Expand Down Expand Up @@ -1125,7 +1091,7 @@ bool QgsGeos::relation( const QgsAbstractGeometryV2& geom, Relation r, QString*
return false;
}

GEOSGeomScopedPtr geosGeom( getReducedGeometry( asGeos( &geom ) ) );
GEOSGeomScopedPtr geosGeom( asGeos( &geom ) );
if ( !geosGeom )
{
return false;
Expand Down Expand Up @@ -1382,7 +1348,7 @@ bool QgsGeos::isEqual( const QgsAbstractGeometryV2& geom, QString* errorMsg ) co

try
{
GEOSGeomScopedPtr geosGeom( getReducedGeometry( asGeos( &geom ) ) );
GEOSGeomScopedPtr geosGeom( asGeos( &geom ) );
if ( !geosGeom )
{
return false;
Expand Down
11 changes: 0 additions & 11 deletions src/core/geometry/qgsgeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ email : marco.hugentobler at sourcepole dot com
#include "qgsgeometryengine.h"
#include "qgspointv2.h"
#include <geos_c.h>
#if defined(HAVE_GEOS_CPP) && !defined(HAVE_GEOS_CAPI_PRECISION_MODEL)
#include "geosextra/geos_c_extra.h"
#endif

class QgsLineStringV2;
class QgsPolygonV2;
Expand Down Expand Up @@ -92,11 +89,6 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
private:
mutable GEOSGeometry* mGeos;
const GEOSPreparedGeometry* mGeosPrepared;
#if defined(HAVE_GEOS_CPP) || defined(HAVE_GEOS_CAPI_PRECISION_MODEL)
//precision reducer
GEOSPrecisionModel* mPrecisionModel;
GEOSGeometryPrecisionReducer* mPrecisionReducer;
#endif

enum Overlay
{
Expand Down Expand Up @@ -144,9 +136,6 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
static int lineContainedInLine( const GEOSGeometry* line1, const GEOSGeometry* line2 );
static int pointContainedInLine( const GEOSGeometry* point, const GEOSGeometry* line );
static int geomDigits( const GEOSGeometry* geom );

private:
inline GEOSGeometry *getReducedGeometry( GEOSGeometry* geom ) const;
};

/// @cond
Expand Down
60 changes: 0 additions & 60 deletions src/core/geosextra/geos_c_extra.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions src/core/geosextra/geos_c_extra.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/plugins/geometry_checker/checks/qgsgeometrycheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "geometry/qgsgeometry.h"
#include "../utils/qgsgeomutils.h"
#include "geos_c.h"
#if defined(HAVE_GEOS_CPP) || !defined(HAVE_GEOS_CAPI_PRECISION_MODEL)
#include <geosextra/geos_c_extra.h>
#endif
#include <QApplication>

class QgsGeometryCheckError;
Expand Down

0 comments on commit 643eb10

Please sign in to comment.