Skip to content
Permalink
Browse files

Segmentize curved geometries for rendering, but keep the original geo…

…metry in the feature. Use the original geometry for drawing vertex markers
  • Loading branch information
mhugent committed Sep 1, 2015
1 parent d125e3f commit 5b97c03799fd3b0b7b4aeea877a10d1da8193748
Showing with 41 additions and 27 deletions.
  1. +41 −27 src/core/symbology-ng/qgsrendererv2.cpp
@@ -33,6 +33,7 @@
#include "qgseffectstack.h"
#include "qgspainteffectregistry.h"
#include "qgswkbptr.h"
#include "qgspointv2.h"

#include <QDomElement>
#include <QDomDocument>
@@ -278,12 +279,16 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
QgsSymbolV2::SymbolType symbolType = symbol->type();


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

const QgsGeometry* segmentizedGeometry = geom;
bool deleteSegmentizedGeometry = false;

//convert curve types to normal point/line/polygon ones
switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
{
@@ -298,14 +303,14 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
return;
}
feature.setGeometry( new QgsGeometry( g ) );
geom = feature.constGeometry();
segmentizedGeometry = new QgsGeometry( g );
deleteSegmentizedGeometry = true;
}
default:
break;
}

switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
{
case QgsWKBTypes::Point:
{
@@ -315,11 +320,8 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}
QPointF pt;
_getPoint( pt, context, geom->asWkb() );
_getPoint( pt, context, segmentizedGeometry->asWkb() );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );

//if ( drawVertexMarker )
// renderVertexMarker( pt, context );
}
break;
case QgsWKBTypes::LineString:
@@ -330,11 +332,8 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}
QPolygonF pts;
_getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
_getLineString( pts, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolyline( pts, context );
}
break;
case QgsWKBTypes::Polygon:
@@ -346,11 +345,8 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
}
QPolygonF pts;
QList<QPolygonF> holes;
_getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
}
break;

@@ -362,7 +358,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
@@ -372,9 +368,6 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );

//if ( drawVertexMarker )
// renderVertexMarker( pt, context );
}
}
break;
@@ -388,7 +381,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
@@ -398,9 +391,6 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolyline( pts, context );
}
}
break;
@@ -414,7 +404,7 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
break;
}

QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
@@ -425,15 +415,39 @@ void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymb
{
ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );

if ( drawVertexMarker )
renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
}
break;
}
default:
QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
}

if ( drawVertexMarker )
{
const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();

QgsPointV2 vertexPoint;
QgsVertexId vertexId;
double z;
QPointF mapPoint;
while ( geom->geometry()->nextVertex( vertexId, vertexPoint ) )
{
//transform
mapPoint.setX( vertexPoint.x() ); mapPoint.setY( vertexPoint.y() ); z = vertexPoint.z();
mtp.transformInPlace( mapPoint.rx(), mapPoint.ry() );
if ( ct )
{
ct->transformInPlace( mapPoint.rx(), mapPoint.ry(), z );
}
renderVertexMarker( mapPoint, context );
}
}

if ( deleteSegmentizedGeometry )
{
delete segmentizedGeometry;
}
}

QString QgsFeatureRendererV2::dump() const

0 comments on commit 5b97c03

Please sign in to comment.
You can’t perform that action at this time.