Skip to content

Commit

Permalink
Speed up map to pixel simplification by directly accessing x/y vertex…
Browse files Browse the repository at this point in the history
… data
  • Loading branch information
nyalldawson committed May 26, 2018
1 parent e6a0d52 commit 80e44c1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/core/geometry/qgslinestring.cpp
Expand Up @@ -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() )
Expand Down
16 changes: 16 additions & 0 deletions src/core/geometry/qgslinestring.h
Expand Up @@ -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
Expand Down
40 changes: 36 additions & 4 deletions src/core/qgsmaptopixelgeometrysimplifier.cpp
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 80e44c1

Please sign in to comment.