Skip to content

Commit 2f74596

Browse files
wonder-sknyalldawson
authored andcommittedJun 7, 2020
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)
1 parent 404187d commit 2f74596

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎src/core/vectortile/qgsvectortilemvtencoder.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,21 @@ void QgsVectorTileMVTEncoder::addLayer( QgsVectorLayer *layer, QgsFeedback *feed
233233

234234
void QgsVectorTileMVTEncoder::addFeature( vector_tile::Tile_Layer *tileLayer, const QgsFeature &f )
235235
{
236+
QgsGeometry g = f.geometry();
237+
QgsWkbTypes::GeometryType geomType = g.type();
238+
double onePixel = mTileExtent.width() / mResolution;
239+
240+
if ( geomType == QgsWkbTypes::LineGeometry )
241+
{
242+
if ( g.length() < onePixel )
243+
return; // too short
244+
}
245+
else if ( geomType == QgsWkbTypes::PolygonGeometry )
246+
{
247+
if ( g.area() < onePixel * onePixel )
248+
return; // too small
249+
}
250+
236251
vector_tile::Tile_Feature *feature = tileLayer->add_features();
237252

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

280-
QgsGeometry g = f.geometry();
281-
QgsWkbTypes::GeometryType geomType = g.type();
282295
vector_tile::Tile_GeomType mvtGeomType = vector_tile::Tile_GeomType_UNKNOWN;
283296
if ( geomType == QgsWkbTypes::PointGeometry )
284297
mvtGeomType = vector_tile::Tile_GeomType_POINT;

0 commit comments

Comments
 (0)
Please sign in to comment.