Skip to content
Permalink
Browse files
Avoid unnecessary detach of QgsFeature when renderering non-curved
geometries
  • Loading branch information
nyalldawson committed May 28, 2015
1 parent 225362d commit e7219050a16da3b4dbeb1cae9e1ca5438ac34f2f
Showing with 36 additions and 3 deletions.
  1. +7 −0 python/core/geometry/qgsgeometry.sip
  2. +13 −1 src/core/geometry/qgsgeometry.cpp
  3. +7 −0 src/core/geometry/qgsgeometry.h
  4. +9 −2 src/core/symbology-ng/qgsrendererv2.cpp
@@ -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
@@ -1479,7 +1479,7 @@ QgsGeometry *QgsGeometry::unaryUnion( const QList<QgsGeometry*> &geometryList )

void QgsGeometry::convertToStraightSegment()
{
if ( !d || !d->geometry )
if ( !d || !d->geometry || !requiresConversionToStraightSegments() )
{
return;
}
@@ -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 )
@@ -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;
@@ -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() )
{

0 comments on commit e721905

Please sign in to comment.