Skip to content
Permalink
Browse files
#10195: avoid calculate the GeometryType in offsetline
  • Loading branch information
ahuarte47 committed Jun 11, 2014
1 parent 3ca5706 commit 17a8e3810810e1a8da42eaabc967be3f9d6e1c3d
Showing with 23 additions and 11 deletions.
  1. +2 −2 src/core/symbology-ng/qgslinesymbollayerv2.cpp
  2. +18 −7 src/core/symbology-ng/qgssymbollayerv2utils.cpp
  3. +3 −2 src/core/symbology-ng/qgssymbollayerv2utils.h
@@ -273,7 +273,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
else
{
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale );
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset, context.feature() ? context.feature()->geometry()->type() : QGis::Line );
for ( int part = 0; part < mline.count(); ++part )
p->drawPolyline( mline[ part ] );
}
@@ -765,7 +765,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
}
else
{
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ), context.feature() ? context.feature()->geometry()->type() : QGis::Line );

for ( int part = 0; part < mline.count(); ++part )
{
@@ -682,8 +682,7 @@ static QList<QPolygonF> makeOffsetGeometry( const QgsPolygon& polygon )
}
#endif


QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType )
{
QList<QPolygonF> resultLine;

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

if ( offsetGeom )
{
@@ -803,6 +799,21 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )

#endif
}
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
{
QGis::GeometryType geometryType = QGis::Point;
int pointCount = polyline.count();

if ( pointCount > 3 && polyline[ 0 ].x() == polyline[ pointCount - 1 ].x() && polyline[ 0 ].y() == polyline[ pointCount - 1 ].y() )
{
geometryType = QGis::Polygon;
}
else if ( pointCount > 1 )
{
geometryType = QGis::Line;
}
return offsetLine( polyline, dist, geometryType );
}

/////

@@ -312,9 +312,10 @@ class CORE_EXPORT QgsSymbolLayerV2Utils

class QPolygonF;

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

//! calculate geometry shifted by a specified distance
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType geometryType );

#endif

0 comments on commit 17a8e38

Please sign in to comment.