Skip to content
Permalink
Browse files

Speed up map to pixel simplification by directly accessing x/y vertex…

… data
  • Loading branch information
nyalldawson committed May 25, 2018
1 parent e6a0d52 commit 80e44c136415bd206eb14f2907fe2955fda52720
@@ -87,6 +87,8 @@ Returns the specified point from inside the line string.
virtual double yAt( int index ) const;




double zAt( int index ) const;
%Docstring
Returns the z-coordinate of the specified node in the line string.
@@ -535,6 +535,16 @@ double QgsLineString::yAt( int index ) const
return 0.0;
}

const double *QgsLineString::xData() const
{
return mX.constData();
}

const double *QgsLineString::yData() const
{
return mY.constData();
}

double QgsLineString::zAt( int index ) const
{
if ( index >= 0 && index < mZ.size() )
@@ -96,6 +96,22 @@ class CORE_EXPORT QgsLineString: public QgsCurve
double xAt( int index ) const override;
double yAt( int index ) const override;

/**
* Returns a const pointer to the x vertex data.
* \since QGIS 3.2
* \note Not available in Python bindings
* \see yData()
*/
const double *xData() const SIP_SKIP;

/**
* Returns a const pointer to the y vertex data.
* \since QGIS 3.2
* \note Not available in Python bindings
* \see xData()
*/
const double *yData() const SIP_SKIP;

/**
* Returns the z-coordinate of the specified node in the line string.
* \param index index of node, where the first node in the line is 0
@@ -189,10 +189,26 @@ std::unique_ptr< QgsAbstractGeometry > QgsMapToPixelSimplifier::simplifyGeometry
// Use a factor for the maximum displacement distance for simplification, similar as GeoServer does
float gridInverseSizeXY = map2pixelTol != 0 ? ( float )( 1.0f / ( 0.8 * map2pixelTol ) ) : 0.0f;

const double *xData = nullptr;
const double *yData = nullptr;
if ( flatType == QgsWkbTypes::LineString )
{
xData = static_cast< const QgsLineString * >( &srcCurve )->xData();
yData = static_cast< const QgsLineString * >( &srcCurve )->yData();
}

for ( int i = 0; i < numPoints; ++i )
{
x = srcCurve.xAt( i );
y = srcCurve.yAt( i );
if ( xData && yData )
{
x = *xData++;
y = *yData++;
}
else
{
x = srcCurve.xAt( i );
y = srcCurve.yAt( i );
}

if ( i == 0 ||
!isGeneralizable ||
@@ -244,10 +260,26 @@ std::unique_ptr< QgsAbstractGeometry > QgsMapToPixelSimplifier::simplifyGeometry
{
map2pixelTol *= map2pixelTol; //-> Use mappixelTol for 'LengthSquare' calculations.

const double *xData = nullptr;
const double *yData = nullptr;
if ( flatType == QgsWkbTypes::LineString )
{
xData = static_cast< const QgsLineString * >( &srcCurve )->xData();
yData = static_cast< const QgsLineString * >( &srcCurve )->yData();
}

for ( int i = 0; i < numPoints; ++i )
{
x = srcCurve.xAt( i );
y = srcCurve.yAt( i );
if ( xData && yData )
{
x = *xData++;
y = *yData++;
}
else
{
x = srcCurve.xAt( i );
y = srcCurve.yAt( i );
}

isLongSegment = false;

0 comments on commit 80e44c1

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