Skip to content
Permalink
Browse files

Merge pull request #1205 from ahuarte47/Issue_9485

Fix #9456 #9485: Line Offset in symbology generates artifacts
  • Loading branch information
wonder-sk committed Mar 3, 2014
2 parents 4a3ad4b + 540685a commit bb7cd4053a9aa676466ce3ea4212956e2a712537
Showing with 42 additions and 2 deletions.
  1. +42 −2 src/core/symbology-ng/qgssymbollayerv2utils.cpp
@@ -648,10 +648,48 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )

QPolygonF offsetLine( QPolygonF polyline, double dist )
{
if ( polyline.count() < 2 )
return polyline;

QPolygonF newLine;

if ( polyline.count() < 2 )
return 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 );
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*/ );

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

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

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

delete tempGeometry;
return newLine;
}
delete tempGeometry;
}

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

#else

double angle = 0.0, t_new, t_old = 0;
QPointF pt_old, pt_new;
@@ -688,6 +726,8 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
pt_new = offsetPoint( p2, angle + M_PI / 2, dist );
newLine.append( pt_new );
return newLine;

#endif
}

/////

0 comments on commit bb7cd40

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