Add heuristic to not simplify geometries for nothing

Tested with a release binary and Swiss OSM roads in PostGIS at several zoom
levels (the higher, the less features), values in ms (average over at
least 100 queries):

Level | Before | After | % improvement
-------------------------------------------
7     |  37    |  36   | 2.7
6     |  41    |  38   | 7.32
5     |  48    |  46   | 4.17
4     |  70    |  64   | 8.57
3     | 114    | 109   | 4.39

Not much improvement (I'm quite dispointed, here), but not much change in
the code.
This commit is contained in:
Patrick Valsecchi 2016-07-19 15:41:06 +02:00
parent cd4bc8887b
commit 5ee97adc16
10 changed files with 8 additions and 2 deletions

View File

@ -547,9 +547,15 @@ bool QgsMapToPixelSimplifier::simplifyPoints( QgsWkbTypes::Type wkbType, QgsCons
if ( numPoints <= ( isaLinearRing ? 6 : 3 ) )
return false;
QgsRectangle envelope = calculateBoundingBox( singleType, QgsConstWkbPtr( sourceWkbPtr ), numPoints );
sourceWkbPtr -= sizeof( int );
const QgsRectangle envelope = calculateBoundingBox( singleType, QgsConstWkbPtr( sourceWkbPtr ), numPoints );
if ( qMax( envelope.width(), envelope.height() ) / numPoints > tolerance * 2.0 )
{
//points are in average too far appart to lead to any significant simplification
return false;
}
sourceWkbPtr -= sizeof( int );
int targetWkbSize = 5 + sizeof( int ) + numPoints * ( 2 * sizeof( double ) );
unsigned char* targetWkb = new unsigned char[ targetWkbSize ];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 MiB

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 3.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB