Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid unnecessary detach of QgsFeature when renderering non-curved
geometries
  • Loading branch information
nyalldawson committed May 28, 2015
1 parent 225362d commit e721905
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
7 changes: 7 additions & 0 deletions python/core/geometry/qgsgeometry.sip
Expand Up @@ -481,6 +481,13 @@ class QgsGeometry
*/
static QgsGeometry *unaryUnion( const QList<QgsGeometry*>& geometryList ) /Factory/;

/** Returns true if the geometry is a curved geometry type which requires conversion to
* display as straight line segments.
* @note added in QGIS 2.10
* @see convertToStraightSegment
*/
bool requiresConversionToStraightSegments() const;

/** Compares two polylines for equality within a specified tolerance.
* @param p1 first polyline
* @param p2 second polyline
Expand Down
14 changes: 13 additions & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1479,7 +1479,7 @@ QgsGeometry *QgsGeometry::unaryUnion( const QList<QgsGeometry*> &geometryList )

void QgsGeometry::convertToStraightSegment()
{
if ( !d || !d->geometry )
if ( !d || !d->geometry || !requiresConversionToStraightSegments() )
{
return;
}
Expand Down Expand Up @@ -1523,6 +1523,18 @@ void QgsGeometry::convertToStraightSegment()
mGeos = 0;
}

bool QgsGeometry::requiresConversionToStraightSegments() const
{
if ( !d || !d->geometry )
{
return false;
}

QgsWKBTypes::Type flatGeomType = QgsWKBTypes::flatType( d->geometry->wkbType() );
return ( flatGeomType == QgsWKBTypes::CompoundCurve || flatGeomType == QgsWKBTypes::CircularString
|| flatGeomType == QgsWKBTypes::CurvePolygon );
}

int QgsGeometry::transform( const QgsCoordinateTransform& ct )
{
if ( !d || !d->geometry )
Expand Down
7 changes: 7 additions & 0 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -566,6 +566,13 @@ class CORE_EXPORT QgsGeometry

void convertToStraightSegment();

/** Returns true if the geometry is a curved geometry type which requires conversion to
* display as straight line segments.
* @note added in QGIS 2.10
* @see convertToStraightSegment
*/
bool requiresConversionToStraightSegments() const;

void mapToPixel( const QgsMapToPixel& mtp );
void clip( const QgsRectangle& rect );
void draw( QPainter& p ) const;
Expand Down
11 changes: 9 additions & 2 deletions src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -245,12 +245,19 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
QgsSymbolV2::SymbolType symbolType = symbol->type();

QgsGeometry* geom = feature.geometry();
const QgsGeometry* geom = feature.constGeometry();
if ( !geom )
{
return;
}
geom->convertToStraightSegment();

if ( geom->requiresConversionToStraightSegments() )
{
//geometry requires conversion to straight segments
QgsGeometry* straightGeom = new QgsGeometry( *geom );
feature.setGeometry( straightGeom );
geom = feature.constGeometry();
}

switch ( geom->wkbType() )
{
Expand Down

0 comments on commit e721905

Please sign in to comment.