Skip to content

Commit

Permalink
Vector tile writer: skip geometries too short/small (fixes #36939)
Browse files Browse the repository at this point in the history
The tile encoder would include even linestrings/polygons that
were shorter that 1px / smaller that 1px^2. Now we skip those,
greatly reducing tile size on lower zoom levels.

(actually the resolution of each tile is normally set as 4096x4096,
so 1px in fact is much smaller than "true" pixel on a screen)
  • Loading branch information
wonder-sk authored and nyalldawson committed Jun 7, 2020
1 parent 404187d commit 2f74596
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/vectortile/qgsvectortilemvtencoder.cpp
Expand Up @@ -233,6 +233,21 @@ void QgsVectorTileMVTEncoder::addLayer( QgsVectorLayer *layer, QgsFeedback *feed

void QgsVectorTileMVTEncoder::addFeature( vector_tile::Tile_Layer *tileLayer, const QgsFeature &f )
{
QgsGeometry g = f.geometry();
QgsWkbTypes::GeometryType geomType = g.type();
double onePixel = mTileExtent.width() / mResolution;

if ( geomType == QgsWkbTypes::LineGeometry )
{
if ( g.length() < onePixel )
return; // too short
}
else if ( geomType == QgsWkbTypes::PolygonGeometry )
{
if ( g.area() < onePixel * onePixel )
return; // too small
}

vector_tile::Tile_Feature *feature = tileLayer->add_features();

feature->set_id( static_cast<quint64>( f.id() ) );
Expand Down Expand Up @@ -277,8 +292,6 @@ void QgsVectorTileMVTEncoder::addFeature( vector_tile::Tile_Layer *tileLayer, co
// encode geometry
//

QgsGeometry g = f.geometry();
QgsWkbTypes::GeometryType geomType = g.type();
vector_tile::Tile_GeomType mvtGeomType = vector_tile::Tile_GeomType_UNKNOWN;
if ( geomType == QgsWkbTypes::PointGeometry )
mvtGeomType = vector_tile::Tile_GeomType_POINT;
Expand Down

0 comments on commit 2f74596

Please sign in to comment.