Skip to content

Commit

Permalink
Bump minimum GEOS version to 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 16, 2016
1 parent 40b70a3 commit 616a80f
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 154 deletions.
6 changes: 3 additions & 3 deletions cmake/FindGEOS.cmake
Expand Up @@ -87,9 +87,9 @@ ELSE(WIN32)
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GEOS_VERSION_MAJOR "${GEOS_VERSION}")
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GEOS_VERSION_MINOR "${GEOS_VERSION}")

IF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 1) )
MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.1.0 or higher.")
ENDIF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 1) )
IF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 3) )
MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.3.0 or higher.")
ENDIF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 3) )

# set INCLUDE_DIR to prefix+include
EXEC_PROGRAM(${GEOS_CONFIG}
Expand Down
6 changes: 0 additions & 6 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Expand Up @@ -1063,9 +1063,6 @@ QgsGeometry QgsGeometryAnalyzer::createOffsetGeometry( const QgsGeometry& geom,
{
if ( geom.type() == QgsWkbTypes::LineGeometry )
{
//geos 3.3 needed for line offsets
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
GEOSGeometry* offsetGeom = GEOSOffsetCurve_r( geosctxt, ( *inputGeomIt ).asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
if ( !offsetGeom || !GEOSisValid_r( geosctxt, offsetGeom ) )
{
Expand All @@ -1077,9 +1074,6 @@ QgsGeometry QgsGeometryAnalyzer::createOffsetGeometry( const QgsGeometry& geom,
return QgsGeometry();
}
outputGeomList.push_back( offsetGeom );
#else
outputGeomList.push_back( GEOSGeom_clone_r( geosctxt, ( *inputGeomIt )->asGeos() ) );
#endif
}
else if ( geom.type() == QgsWkbTypes::PointGeometry )
{
Expand Down
11 changes: 0 additions & 11 deletions src/app/qgisapp.cpp
Expand Up @@ -1823,10 +1823,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionCircularStringRadius );
mMapToolGroup->addAction( mActionMoveFeature );
mMapToolGroup->addAction( mActionRotateFeature );
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
mMapToolGroup->addAction( mActionOffsetCurve );
#endif
mMapToolGroup->addAction( mActionReshapeFeatures );
mMapToolGroup->addAction( mActionSplitFeatures );
mMapToolGroup->addAction( mActionSplitParts );
Expand Down Expand Up @@ -2805,16 +2802,8 @@ void QgisApp::createCanvasTools()
mMapTools.mMoveFeature->setAction( mActionMoveFeature );
mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas );
mMapTools.mRotateFeature->setAction( mActionRotateFeature );
//need at least geos 3.3 for OffsetCurve tool
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
mMapTools.mOffsetCurve = new QgsMapToolOffsetCurve( mMapCanvas );
mMapTools.mOffsetCurve->setAction( mActionOffsetCurve );
#else
mAdvancedDigitizeToolBar->removeAction( mActionOffsetCurve );
mEditMenu->removeAction( mActionOffsetCurve );
mMapTools.mOffsetCurve = 0;
#endif //GEOS_VERSION
mMapTools.mReshapeFeatures = new QgsMapToolReshape( mMapCanvas );
mMapTools.mReshapeFeatures->setAction( mActionReshapeFeatures );
mMapTools.mSplitFeatures = new QgsMapToolSplitFeatures( mMapCanvas );
Expand Down
6 changes: 0 additions & 6 deletions src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -359,9 +359,6 @@ void QgsMapToolOffsetCurve::deleteRubberBandAndGeometry()

void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
{
// need at least geos 3.3 for OffsetCurve tool
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
if ( !mRubberBand || mOriginalGeometry.isEmpty() )
{
return;
Expand Down Expand Up @@ -402,9 +399,6 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
mRubberBand->setToGeometry( mModifiedGeometry, sourceLayer );
}
}
#else //GEOS_VERSION>=3.3
Q_UNUSED( offset );
#endif //GEOS_VERSION>=3.3
}

QgsGeometry QgsMapToolOffsetCurve::linestringFromPolygon( const QgsGeometry& featureGeom, int vertex )
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgsoptions.cpp
Expand Up @@ -889,10 +889,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
mValidateGeometries->clear();
mValidateGeometries->addItem( tr( "Off" ) );
mValidateGeometries->addItem( tr( "QGIS" ) );
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
( (GEOS_VERSION_MAJOR==3 && GEOS_VERSION_MINOR>=3) || GEOS_VERSION_MAJOR>3)
mValidateGeometries->addItem( tr( "GEOS" ) );
#endif

QString markerStyle = mSettings->value( "/qgis/digitizing/marker_style", "Cross" ).toString();
if ( markerStyle == "SemiTransparentCircle" )
Expand Down
6 changes: 0 additions & 6 deletions src/core/geometry/qgsgeos.cpp
Expand Up @@ -1296,19 +1296,13 @@ QgsAbstractGeometry *QgsGeos::buffer( double distance, int segments, int endCapS
return nullptr;
}

#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))

GEOSGeomScopedPtr geos;
try
{
geos.reset( GEOSBufferWithStyle_r( geosinit.ctxt, mGeos, distance, segments, endCapStyle, joinStyle, mitreLimit ) );
}
CATCH_GEOS_WITH_ERRMSG( nullptr );
return fromGeos( geos.get() );
#else
return 0;
#endif //0
}

QgsAbstractGeometry* QgsGeos::simplify( double tolerance, QString* errorMsg ) const
Expand Down
3 changes: 0 additions & 3 deletions src/core/qgsgeometryvalidator.cpp
Expand Up @@ -196,8 +196,6 @@ void QgsGeometryValidator::validatePolygon( int idx, const QgsPolygon &polygon )
void QgsGeometryValidator::run()
{
mErrorCount = 0;
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
( (GEOS_VERSION_MAJOR==3 && GEOS_VERSION_MINOR>=3) || GEOS_VERSION_MAJOR>3)
QSettings settings;
if ( settings.value( "/qgis/digitizing/validate_geometries", 1 ).toInt() == 2 )
{
Expand Down Expand Up @@ -241,7 +239,6 @@ void QgsGeometryValidator::run()

return;
}
#endif

QgsDebugMsg( "validation thread started." );

Expand Down
116 changes: 0 additions & 116 deletions src/core/symbology-ng/qgssymbollayerutils.cpp
Expand Up @@ -671,73 +671,6 @@ void QgsSymbolLayerUtils::drawStippledBackground( QPainter* painter, QRect rect
#include <cmath>
#include <cfloat>


#if !defined(GEOS_VERSION_MAJOR) || !defined(GEOS_VERSION_MINOR) || \
((GEOS_VERSION_MAJOR<3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR<3)))
// calculate line's angle and tangent
static bool lineInfo( QPointF p1, QPointF p2, double& angle, double& t )
{
double x1 = p1.x(), y1 = p1.y(), x2 = p2.x(), y2 = p2.y();

if ( x1 == x2 && y1 == y2 )
return false;

// tangent
t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );

// angle
if ( t == DBL_MAX )
angle = ( y2 > y1 ? M_PI / 2 : M_PI * 3 / 2 ); // angle is 90 or 270
else if ( t == 0 )
angle = ( x2 > x1 ? 0 : M_PI ); // angle is 0 or 180
else if ( t >= 0 )
angle = ( y2 > y1 ? atan( t ) : M_PI + atan( t ) );
else // t < 0
angle = ( y2 > y1 ? M_PI + atan( t ) : atan( t ) );

return true;
}

// offset a point with an angle and distance
static QPointF offsetPoint( QPointF pt, double angle, double dist )
{
return QPointF( pt.x() + dist * cos( angle ), pt.y() + dist * sin( angle ) );
}

// calc intersection of two (infinite) lines defined by one point and tangent
static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )
{
// parallel lines? (or the difference between angles is less than appr. 10 degree)
if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
return QPointF();

double x, y;
if ( t1 == DBL_MAX || t2 == DBL_MAX )
{
// in case one line is with angle 90 resp. 270 degrees (tangent undefined)
// swap them so that line 2 is with undefined tangent
if ( t1 == DBL_MAX )
{
QPointF pSwp = p1;
p1 = p2;
p2 = pSwp;
double tSwp = t1;
t1 = t2;
t2 = tSwp;
}

x = p2.x();
}
else
{
// usual case
x = (( p1.y() - p2.y() ) + t2 * p2.x() - t1 * p1.x() ) / ( t2 - t1 );
}

y = p1.y() + t1 * ( x - p1.x() );
return QPointF( x, y );
}
#else
static QPolygonF makeOffsetGeometry( const QgsPolyline& polyline )
{
int i, pointCount = polyline.count();
Expand All @@ -760,7 +693,6 @@ static QList<QPolygonF> makeOffsetGeometry( const QgsPolygon& polygon )
resultGeom.append( makeOffsetGeometry( polygon[ ring ] ) );
return resultGeom;
}
#endif

QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QgsWkbTypes::GeometryType geometryType )
{
Expand All @@ -772,12 +704,6 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QgsWkbTypes::Geome
return resultLine;
}

QPolygonF newLine;

// need at least geos 3.3 for OffsetCurve tool
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))

unsigned int i, pointCount = polyline.count();

QgsPolyline tempPolyline( pointCount );
Expand Down Expand Up @@ -840,48 +766,6 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QgsWkbTypes::Geome
// returns original polyline when 'GEOSOffsetCurve' fails!
resultLine.append( polyline );
return resultLine;

#else

double angle = 0.0, t_new, t_old = 0;
QPointF pt_old, pt_new;
QPointF p1 = polyline[0], p2;
bool first_point = true;

for ( int i = 1; i < polyline.count(); i++ )
{
p2 = polyline[i];

if ( !lineInfo( p1, p2, angle, t_new ) )
continue; // not a line...

pt_new = offsetPoint( p1, angle + M_PI / 2, dist );

if ( ! first_point )
{
// if it's not the first line segment
// calc intersection with last line (with offset)
QPointF pt_tmp = linesIntersection( pt_old, t_old, pt_new, t_new );
if ( !pt_tmp.isNull() )
pt_new = pt_tmp;
}

newLine.append( pt_new );

pt_old = pt_new;
t_old = t_new;
p1 = p2;
first_point = false;
}

// last line segment:
pt_new = offsetPoint( p2, angle + M_PI / 2, dist );
newLine.append( pt_new );

resultLine.append( newLine );
return resultLine;

#endif
}

QList<QPolygonF> offsetLine( const QPolygonF& polyline, double dist )
Expand Down

0 comments on commit 616a80f

Please sign in to comment.