Skip to content
Permalink
Browse files
When creating simple vector tile rules, default to using a
  geometry_type($geometry)='Polygon' (or line, or marker)
filter rule

The vector tile specs don't mandate that a marker or line
is only used to render a point/line feature, and instead
convey that a marker should be rendered at the center
of a polygon and a line should be used for the outline
of a polygon.

So in order to restrict markers/lines to ONLY being rendered
for point/line features, we need to use an explicit filter
  • Loading branch information
nyalldawson authored and github-actions committed Jan 7, 2022
1 parent a9c699a commit 5bbeced1bd08e6be30fc5f2be2bd474efb52ce53
@@ -324,12 +324,15 @@ QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( QgsSymbolLayerList() << markerSymbolLayer );

QgsVectorTileBasicRendererStyle st1( QStringLiteral( "Polygons" ), QString(), QgsWkbTypes::PolygonGeometry );
st1.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
st1.setSymbol( fillSymbol );

QgsVectorTileBasicRendererStyle st2( QStringLiteral( "Lines" ), QString(), QgsWkbTypes::LineGeometry );
st2.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
st2.setSymbol( lineSymbol );

QgsVectorTileBasicRendererStyle st3( QStringLiteral( "Points" ), QString(), QgsWkbTypes::PointGeometry );
st3.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
st3.setSymbol( markerSymbol );

QList<QgsVectorTileBasicRendererStyle> lst;
@@ -380,6 +380,21 @@ void QgsVectorTileBasicLabelingWidget::addStyle( QgsWkbTypes::GeometryType geomT
{
QgsVectorTileBasicLabelingStyle style;
style.setGeometryType( geomType );
switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
break;
case QgsWkbTypes::LineGeometry:
style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
break;
case QgsWkbTypes::PolygonGeometry:
style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
break;
case QgsWkbTypes::UnknownGeometry:
case QgsWkbTypes::NullGeometry:
break;
}

const int rows = mModel->rowCount();
mModel->insertStyle( rows, style );
@@ -383,6 +383,22 @@ void QgsVectorTileBasicRendererWidget::addStyle( QgsWkbTypes::GeometryType geomT
QgsVectorTileBasicRendererStyle style( QString(), QString(), geomType );
style.setSymbol( QgsSymbol::defaultSymbol( geomType ) );

switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
break;
case QgsWkbTypes::LineGeometry:
style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
break;
case QgsWkbTypes::PolygonGeometry:
style.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
break;
case QgsWkbTypes::UnknownGeometry:
case QgsWkbTypes::NullGeometry:
break;
}

const int rows = mModel->rowCount();
mModel->insertStyle( rows, style );
viewStyles->selectionModel()->setCurrentIndex( mProxyModel->mapFromSource( mModel->index( rows, 0 ) ), QItemSelectionModel::ClearAndSelect );

0 comments on commit 5bbeced

Please sign in to comment.