Skip to content
Permalink
Browse files

#9861: Fix offsetline-GEOSOffsetCurve for multigeometries

  • Loading branch information
ahuarte47 committed May 6, 2014
1 parent 4efa70d commit ddecf7e94ef5762a0475ddb66e8ccafeaf95ab29
@@ -250,7 +250,8 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
else
{
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
for ( int part = 0; part < mline.count(); ++part ) p->drawPolyline( mline[ part ] );
}
}

@@ -721,13 +722,19 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
}
else
{
QPolygonF points2 = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
if ( placement == Interval )
renderPolylineInterval( points2, context );
else if ( placement == CentralPoint )
renderPolylineCentral( points2, context );
else
renderPolylineVertex( points2, context, placement );
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );

for ( int part = 0; part < mline.count(); ++part )
{
QPolygonF points2 = mline[ part ];

if ( placement == Interval )
renderPolylineInterval( points2, context );
else if ( placement == CentralPoint )
renderPolylineCentral( points2, context );
else
renderPolylineVertex( points2, context, placement );
}
}
}

@@ -649,10 +649,15 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )
#endif


QPolygonF offsetLine( QPolygonF polyline, double dist )
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
{
QList<QPolygonF> resultLine;

if ( polyline.count() < 2 )
return polyline;
{
resultLine.append( polyline );
return resultLine;
}

QPolygonF newLine;

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

pointCount = tempPolyline.count();
newLine.resize( pointCount );
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString )
{
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() );
resultLine.append( newLine );

delete tempGeometry;
return resultLine;
}
else
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBMultiLineString )
{
QgsMultiPolyline tempMPolyline = tempGeometry->asMultiPolyline();

for ( int part = 0; part < tempMPolyline.count(); ++part )
{
tempPolyline = tempMPolyline[ part ];

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() );
resultLine.append( newLine );

delete tempGeometry;
return newLine;
newLine = QPolygonF();
}
delete tempGeometry;
return resultLine;
}
}
delete tempGeometry;
}

// returns original polyline when 'GEOSOffsetCurve' fails!
return polyline;
resultLine.append( polyline );
return resultLine;

#else

@@ -728,7 +760,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;

resultLine.append( newLine );
return resultLine;

#endif
}
@@ -287,7 +287,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
class QPolygonF;

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


#endif

0 comments on commit ddecf7e

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