Skip to content

Commit

Permalink
#9485: OffsetLine uses GEOSOffsetCurve (#if-#else-#endif) option
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Feb 26, 2014
1 parent 8176c1c commit 540685a
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,47 +648,48 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )

QPolygonF offsetLine( QPolygonF polyline, double dist )
{
QPolygonF newLine;

if ( polyline.count() < 2 )
return newLine;
return polyline;

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)))

if ( polyline.count() > 2 )
{
unsigned int i, pointCount = polyline.count();
unsigned int i, pointCount = polyline.count();

QgsPolyline tempPolyline( pointCount );
QPointF* tempPtr = polyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr++ ) tempPolyline[i] = QgsPoint( tempPtr->rx(), tempPtr->ry() );
QgsPolyline tempPolyline( pointCount );
QPointF* tempPtr = polyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr++ ) tempPolyline[i] = QgsPoint( tempPtr->rx(), tempPtr->ry() );

QgsGeometry* tempGeometry = QgsGeometry::fromPolyline( tempPolyline );
if ( tempGeometry )
{
const GEOSGeometry* geosGeom = tempGeometry->asGeos();
GEOSGeometry* offsetGeom = GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
QgsGeometry* tempGeometry = QgsGeometry::fromPolyline( tempPolyline );
if ( tempGeometry )
{
const GEOSGeometry* geosGeom = tempGeometry->asGeos();
GEOSGeometry* offsetGeom = GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );

if ( offsetGeom )
{
tempGeometry->fromGeos( offsetGeom );
tempPolyline = tempGeometry->asPolyline();
if ( offsetGeom )
{
tempGeometry->fromGeos( offsetGeom );
tempPolyline = tempGeometry->asPolyline();

pointCount = tempPolyline.count();
newLine.resize( pointCount );
pointCount = tempPolyline.count();
newLine.resize( pointCount );

QgsPoint* tempPtr2 = tempPolyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
QgsPoint* tempPtr2 = tempPolyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );

delete tempGeometry;
return newLine;
}
delete tempGeometry;
return newLine;
}
delete tempGeometry;
}
#endif

// returns original polyline when 'GEOSOffsetCurve' fails!
return polyline;

#else

double angle = 0.0, t_new, t_old = 0;
QPointF pt_old, pt_new;
Expand Down Expand Up @@ -724,8 +725,9 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
// last line segment:
pt_new = offsetPoint( p2, angle + M_PI / 2, dist );
newLine.append( pt_new );

return newLine;

#endif
}

/////
Expand Down

0 comments on commit 540685a

Please sign in to comment.