Skip to content

Commit

Permalink
#10195: Fix offsetline when the geometry is a polygon
Browse files Browse the repository at this point in the history
Use GEOSBuffer in offsetline when the geometry is a polygon
  • Loading branch information
ahuarte47 committed Jun 11, 2014
1 parent f46053d commit 3ca5706
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -659,6 +659,27 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )
y = p1.y() + t1 * ( x - p1.x() );
return QPointF( x, y );
}
#else
static QPolygonF makeOffsetGeometry( const QgsPolyline& polyline )
{
int i, pointCount = polyline.count();

QPolygonF resultLine;
resultLine.resize( pointCount );

const QgsPoint* tempPtr = polyline.data();

for ( i = 0; i < pointCount; ++i, tempPtr++ )
resultLine[i] = QPointF( tempPtr->x(), tempPtr->y() );

return resultLine;
}
static QList<QPolygonF> makeOffsetGeometry( const QgsPolygon& polygon )
{
QList<QPolygonF> resultGeom;
for ( int ring = 0; ring < polygon.size(); ++ring ) resultGeom.append( makeOffsetGeometry( polygon[ ring ] ) );
return resultGeom;
}
#endif


Expand All @@ -680,33 +701,33 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )

unsigned int i, pointCount = polyline.count();

bool isaLinearRing = false;
if ( polyline[0].x() == polyline[ pointCount - 1 ].x() && polyline[0].y() == polyline[ pointCount - 1 ].y() ) isaLinearRing = true;

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 );
QgsGeometry* tempGeometry = isaLinearRing ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
if ( tempGeometry )
{
const GEOSGeometry* geosGeom = tempGeometry->asGeos();
GEOSGeometry* offsetGeom = GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
GEOSGeometry* offsetGeom = isaLinearRing ? GEOSBuffer( geosGeom, -dist, 8 /*quadSegments*/ ) : GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );

if ( offsetGeom )
{
tempGeometry->fromGeos( offsetGeom );

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

resultLine.append( makeOffsetGeometry( tempGeometry->asPolyline() ) );
delete tempGeometry;
return resultLine;
}
else if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBPolygon )
{
resultLine.append( makeOffsetGeometry( tempGeometry->asPolygon() ) );
delete tempGeometry;
return resultLine;
}
Expand All @@ -716,17 +737,18 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )

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() );
resultLine.append( newLine );
resultLine.append( makeOffsetGeometry( tempMPolyline[ part ] ) );
}
delete tempGeometry;
return resultLine;
}
else if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBMultiPolygon )
{
QgsMultiPolygon tempMPolygon = tempGeometry->asMultiPolygon();

newLine = QPolygonF();
for ( int part = 0; part < tempMPolygon.count(); ++part )
{
resultLine.append( makeOffsetGeometry( tempMPolygon[ part ] ) );
}
delete tempGeometry;
return resultLine;
Expand Down

0 comments on commit 3ca5706

Please sign in to comment.