Skip to content

Commit

Permalink
Merge pull request #2353 from manisandro/geos_snap
Browse files Browse the repository at this point in the history
Replace GEOS C++ dependency with hand-rolled snap-to-grid implementation
  • Loading branch information
mhugent committed Oct 12, 2015
2 parents 4d35175 + c927073 commit c7b9fa6
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 251 deletions.
1 change: 0 additions & 1 deletion ci/travis/linux/before_install.sh
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
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
3 changes: 2 additions & 1 deletion python/core/geometry/qgsgeometry.sip
Expand Up @@ -123,10 +123,11 @@ class QgsGeometry
size_t wkbSize() const;

/** Returns a geos geometry. QgsGeometry retains ownership of the geometry, so the returned object should not be deleted.
@param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
@note this method was added in version 1.1
@note not available in python bindings
*/
// const GEOSGeometry* asGeos() const;
// const GEOSGeometry* asGeos( double precision = 0 ) const;

/** Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
* @see type
Expand Down
14 changes: 2 additions & 12 deletions src/core/CMakeLists.txt
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
4 changes: 2 additions & 2 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -294,7 +294,7 @@ size_t QgsGeometry::wkbSize() const
return d->mWkbSize;
}

const GEOSGeometry* QgsGeometry::asGeos() const
const GEOSGeometry* QgsGeometry::asGeos( double precision ) const
{
if ( !d || !d->geometry )
{
Expand All @@ -303,7 +303,7 @@ const GEOSGeometry* QgsGeometry::asGeos() const

if ( !d->mGeos )
{
d->mGeos = QgsGeos::asGeos( d->geometry );
d->mGeos = QgsGeos::asGeos( d->geometry, precision );
}
return d->mGeos;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -158,10 +158,11 @@ class CORE_EXPORT QgsGeometry
size_t wkbSize() const;

/** Returns a geos geometry. QgsGeometry retains ownership of the geometry, so the returned object should not be deleted.
@param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
@note this method was added in version 1.1
@note not available in python bindings
*/
const GEOSGeometry* asGeos() const;
const GEOSGeometry* asGeos( double precision = 0 ) const;

/** Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
* @see type
Expand Down

0 comments on commit c7b9fa6

Please sign in to comment.