Skip to content

Commit

Permalink
#9861: Fix offsetline-GEOSOffsetCurve for multigeometries
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed May 6, 2014
1 parent 4efa70d commit ddecf7e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
23 changes: 15 additions & 8 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -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 ] );
}
}

Expand Down Expand Up @@ -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 );
}
}
}

Expand Down
56 changes: 45 additions & 11 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -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;

Expand All @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -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.