Skip to content
Permalink
Browse files
Improve performance of vector reprojection by transforming the coordi…
…nates of a feature together
  • Loading branch information
mhugent committed Feb 7, 2013
1 parent bb0b978 commit 863da7d03c13308488080fff02459bf37ab84d37
Showing with 50 additions and 20 deletions.
  1. +36 −0 src/core/qgscoordinatetransform.cpp
  2. +3 −0 src/core/qgscoordinatetransform.h
  3. +11 −20 src/core/symbology-ng/qgsrendererv2.cpp
@@ -23,6 +23,7 @@
#include <QDomNode>
#include <QDomElement>
#include <QApplication>
#include <QPolygonF>
#include <QVector>

extern "C"
@@ -318,6 +319,41 @@ void QgsCoordinateTransform::transformInPlace( double& x, double& y, double& z,
}
}

void QgsCoordinateTransform::transformPolygon( QPolygonF& poly, TransformDirection direction ) const
{
//create x, y arrays
int nVertices = poly.size();
qreal x[nVertices];
qreal y[nVertices];
qreal z[nVertices];

for ( int i = 0; i < nVertices; ++i )
{
const QPointF& pt = poly.at( i );
x[i] = pt.x();
y[i] = pt.y();
z[i] = 0;
}

try
{
transformCoords( nVertices, x, y, z, direction );
}
catch ( QgsCsException &cse )
{
// rethrow the exception
QgsDebugMsg( "rethrowing exception" );
throw cse;
}

for ( int i = 0; i < nVertices; ++i )
{
QPointF& pt = poly[i];
pt.rx() = x[i];
pt.ry() = y[i];
}
}

void QgsCoordinateTransform::transformInPlace(
QVector<double>& x, QVector<double>& y, QVector<double>& z,
TransformDirection direction ) const
@@ -27,6 +27,7 @@
#include "qgscoordinatereferencesystem.h"
class QDomNode;
class QDomDocument;
class QPolygonF;

//non qt includes
#include <iostream>
@@ -158,6 +159,8 @@ class CORE_EXPORT QgsCoordinateTransform : public QObject
void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
TransformDirection direction = ForwardTransform ) const;

void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const;

#ifdef ANDROID
void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;

@@ -68,11 +68,6 @@ unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderCo

bool hasZValue = ( wkbType == QGis::WKBLineString25D );
double x, y;
#ifdef ANDROID
qreal z;
#else
double z;
#endif //ANDROID
const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();

@@ -104,14 +99,14 @@ unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderCo
}

//transform the QPolygonF to screen coordinates
if ( ct )
{
ct->transformPolygon( pts );
}

QPointF* ptr = pts.data();
for ( int i = 0; i < pts.size(); ++i, ++ptr )
{
if ( ct )
{
z = 0;
ct->transformInPlace( ptr->rx(), ptr->ry(), z );
}
mtp.transformInPlace( ptr->rx(), ptr->ry() );
}

@@ -136,11 +131,6 @@ unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygon

const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();
#ifdef ANDROID
qreal z = 0; // dummy variable for coordiante transform
#else
double z = 0; // dummy variable for coordiante transform
#endif
const QgsRectangle& e = context.extent();
double cw = e.width() / 10; double ch = e.height() / 10;
QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
@@ -172,14 +162,15 @@ unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygon
QgsClipper::trimPolygon( poly, clipRect );

//transform the QPolygonF to screen coordinates
if ( ct )
{
ct->transformPolygon( poly );
}


ptr = poly.data();
for ( int i = 0; i < poly.size(); ++i, ++ptr )
{
if ( ct )
{
z = 0;
ct->transformInPlace( ptr->rx(), ptr->ry(), z );
}
mtp.transformInPlace( ptr->rx(), ptr->ry() );
}

0 comments on commit 863da7d

Please sign in to comment.