Skip to content
Permalink
Browse files

Vector tile writer: skip geometries too short/small (fixes #36939)

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 2f7459608fcefce1ea68d41823c613bf40b86bc6
Showing with 15 additions and 2 deletions.
  1. +15 −2 src/core/vectortile/qgsvectortilemvtencoder.cpp
@@ -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() ) );
@@ -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;

0 comments on commit 2f74596

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