Skip to content

Commit ddecf7e

Browse files
committedMay 6, 2014
#9861: Fix offsetline-GEOSOffsetCurve for multigeometries
1 parent 4efa70d commit ddecf7e

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed
 

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
250250
else
251251
{
252252
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
253-
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
253+
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
254+
for ( int part = 0; part < mline.count(); ++part ) p->drawPolyline( mline[ part ] );
254255
}
255256
}
256257

@@ -721,13 +722,19 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
721722
}
722723
else
723724
{
724-
QPolygonF points2 = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
725-
if ( placement == Interval )
726-
renderPolylineInterval( points2, context );
727-
else if ( placement == CentralPoint )
728-
renderPolylineCentral( points2, context );
729-
else
730-
renderPolylineVertex( points2, context, placement );
725+
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
726+
727+
for ( int part = 0; part < mline.count(); ++part )
728+
{
729+
QPolygonF points2 = mline[ part ];
730+
731+
if ( placement == Interval )
732+
renderPolylineInterval( points2, context );
733+
else if ( placement == CentralPoint )
734+
renderPolylineCentral( points2, context );
735+
else
736+
renderPolylineVertex( points2, context, placement );
737+
}
731738
}
732739
}
733740

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,15 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )
649649
#endif
650650

651651

652-
QPolygonF offsetLine( QPolygonF polyline, double dist )
652+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
653653
{
654+
QList<QPolygonF> resultLine;
655+
654656
if ( polyline.count() < 2 )
655-
return polyline;
657+
{
658+
resultLine.append( polyline );
659+
return resultLine;
660+
}
656661

657662
QPolygonF newLine;
658663

@@ -675,22 +680,49 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
675680
if ( offsetGeom )
676681
{
677682
tempGeometry->fromGeos( offsetGeom );
678-
tempPolyline = tempGeometry->asPolyline();
679683

680-
pointCount = tempPolyline.count();
681-
newLine.resize( pointCount );
684+
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString )
685+
{
686+
tempPolyline = tempGeometry->asPolyline();
687+
688+
pointCount = tempPolyline.count();
689+
newLine.resize( pointCount );
690+
691+
QgsPoint* tempPtr2 = tempPolyline.data();
692+
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
693+
resultLine.append( newLine );
694+
695+
delete tempGeometry;
696+
return resultLine;
697+
}
698+
else
699+
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBMultiLineString )
700+
{
701+
QgsMultiPolyline tempMPolyline = tempGeometry->asMultiPolyline();
702+
703+
for ( int part = 0; part < tempMPolyline.count(); ++part )
704+
{
705+
tempPolyline = tempMPolyline[ part ];
706+
707+
pointCount = tempPolyline.count();
708+
newLine.resize( pointCount );
682709

683-
QgsPoint* tempPtr2 = tempPolyline.data();
684-
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
710+
QgsPoint* tempPtr2 = tempPolyline.data();
711+
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
712+
resultLine.append( newLine );
685713

686-
delete tempGeometry;
687-
return newLine;
714+
newLine = QPolygonF();
715+
}
716+
delete tempGeometry;
717+
return resultLine;
718+
}
688719
}
689720
delete tempGeometry;
690721
}
691722

692723
// returns original polyline when 'GEOSOffsetCurve' fails!
693-
return polyline;
724+
resultLine.append( polyline );
725+
return resultLine;
694726

695727
#else
696728

@@ -728,7 +760,9 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
728760
// last line segment:
729761
pt_new = offsetPoint( p2, angle + M_PI / 2, dist );
730762
newLine.append( pt_new );
731-
return newLine;
763+
764+
resultLine.append( newLine );
765+
return resultLine;
732766

733767
#endif
734768
}

‎src/core/symbology-ng/qgssymbollayerv2utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
287287
class QPolygonF;
288288

289289
//! calculate line shifted by a specified distance
290-
QPolygonF offsetLine( QPolygonF polyline, double dist );
290+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist );
291291

292292

293293
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.