Skip to content

Commit

Permalink
More optimizations for vector tile decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 14, 2020
1 parent 789eccb commit c35d8e5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/vectortile/qgsvectortilemvtdecoder.cpp
Expand Up @@ -193,6 +193,12 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
QgsDebugMsg( QStringLiteral( "Malformed geometry: invalid cmdCount" ) );
break;
}

if ( feature.type() == vector_tile::Tile_GeomType_POINT )
outputPoints.reserve( outputPoints.size() + cmdCount );
else
tmpPoints.reserve( tmpPoints.size() + cmdCount );

for ( unsigned j = 0; j < cmdCount; j++ )
{
unsigned v = feature.geometry( i + 1 );
Expand Down Expand Up @@ -231,6 +237,7 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
QgsDebugMsg( QStringLiteral( "Malformed geometry: invalid cmdCount" ) );
break;
}
tmpPoints.reserve( tmpPoints.size() + cmdCount );
for ( unsigned j = 0; j < cmdCount; j++ )
{
unsigned v = feature.geometry( i + 1 );
Expand Down Expand Up @@ -288,10 +295,11 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
{
geomType = QStringLiteral( "Point" );
if ( outputPoints.count() == 1 )
f.setGeometry( QgsGeometry( outputPoints[0] ) );
f.setGeometry( QgsGeometry( outputPoints.at( 0 ) ) );
else
{
QgsMultiPoint *mp = new QgsMultiPoint;
mp->reserve( outputPoints.count() );
for ( int k = 0; k < outputPoints.count(); ++k )
mp->addGeometry( outputPoints[k] );
f.setGeometry( QgsGeometry( mp ) );
Expand All @@ -305,10 +313,11 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
outputLinestrings.append( new QgsLineString( tmpPoints ) );

if ( outputLinestrings.count() == 1 )
f.setGeometry( QgsGeometry( outputLinestrings[0] ) );
f.setGeometry( QgsGeometry( outputLinestrings.at( 0 ) ) );
else
{
QgsMultiLineString *mls = new QgsMultiLineString;
mls->reserve( outputLinestrings.size() );
for ( int k = 0; k < outputLinestrings.count(); ++k )
mls->addGeometry( outputLinestrings[k] );
f.setGeometry( QgsGeometry( mls ) );
Expand All @@ -319,10 +328,11 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
geomType = QStringLiteral( "Polygon" );

if ( outputPolygons.count() == 1 )
f.setGeometry( QgsGeometry( outputPolygons[0] ) );
f.setGeometry( QgsGeometry( outputPolygons.at( 0 ) ) );
else
{
QgsMultiPolygon *mpl = new QgsMultiPolygon;
mpl->reserve( outputPolygons.size() );
for ( int k = 0; k < outputPolygons.count(); ++k )
mpl->addGeometry( outputPolygons[k] );
f.setGeometry( QgsGeometry( mpl ) );
Expand Down

0 comments on commit c35d8e5

Please sign in to comment.