Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix 3D polygon symbol to work with geometry collection
Some data sources report their geometry type as multi-surface
(a collection of polygons and curve-polygons) and so we should handle
them as well.
  • Loading branch information
wonder-sk committed Mar 10, 2019
1 parent 75d64ee commit 4a554d2
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/3d/symbols/qgspolygon3dsymbol_p.cpp
Expand Up @@ -54,6 +54,7 @@ class QgsPolygon3DSymbolHandler : public QgsFeature3DHandler
QList<float> extrusionHeightPerPolygon; // will stay empty if not needed per polygon
};

void processPolygon( QgsPolygon *polyClone, QgsFeatureId fid, float height, bool hasDDExtrusion, float extrusionHeight, const Qgs3DRenderContext &context, PolygonData &out );
void makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PolygonData &out, bool selected );
Qt3DExtras::QPhongMaterial *material( const QgsPolygon3DSymbol &symbol ) const;

Expand All @@ -75,6 +76,15 @@ bool QgsPolygon3DSymbolHandler::prepare( const Qgs3DRenderContext &context, QSet
return true;
}

void QgsPolygon3DSymbolHandler::processPolygon( QgsPolygon *polyClone, QgsFeatureId fid, float height, bool hasDDExtrusion, float extrusionHeight, const Qgs3DRenderContext &context, PolygonData &out )
{
Qgs3DUtils::clampAltitudes( polyClone, mSymbol.altitudeClamping(), mSymbol.altitudeBinding(), height, context.map() );
out.polygons.append( polyClone );
out.fids.append( fid );
if ( hasDDExtrusion )
out.extrusionHeightPerPolygon.append( extrusionHeight );
}

void QgsPolygon3DSymbolHandler::processFeature( QgsFeature &f, const Qgs3DRenderContext &context )
{
if ( f.geometry().isNull() )
Expand Down Expand Up @@ -104,11 +114,7 @@ void QgsPolygon3DSymbolHandler::processFeature( QgsFeature &f, const Qgs3DRender
if ( const QgsPolygon *poly = qgsgeometry_cast< const QgsPolygon *>( g ) )
{
QgsPolygon *polyClone = poly->clone();
Qgs3DUtils::clampAltitudes( polyClone, mSymbol.altitudeClamping(), mSymbol.altitudeBinding(), height, context.map() );
out.polygons.append( polyClone );
out.fids.append( f.id() );
if ( hasDDExtrusion )
out.extrusionHeightPerPolygon.append( extrusionHeight );
processPolygon( polyClone, f.id(), height, hasDDExtrusion, extrusionHeight, context, out );
}
else if ( const QgsMultiPolygon *mpoly = qgsgeometry_cast< const QgsMultiPolygon *>( g ) )
{
Expand All @@ -117,11 +123,19 @@ void QgsPolygon3DSymbolHandler::processFeature( QgsFeature &f, const Qgs3DRender
const QgsAbstractGeometry *g2 = mpoly->geometryN( i );
Q_ASSERT( QgsWkbTypes::flatType( g2->wkbType() ) == QgsWkbTypes::Polygon );
QgsPolygon *polyClone = static_cast< const QgsPolygon *>( g2 )->clone();
Qgs3DUtils::clampAltitudes( polyClone, mSymbol.altitudeClamping(), mSymbol.altitudeBinding(), height, context.map() );
out.polygons.append( polyClone );
out.fids.append( f.id() );
if ( hasDDExtrusion )
out.extrusionHeightPerPolygon.append( extrusionHeight );
processPolygon( polyClone, f.id(), height, hasDDExtrusion, extrusionHeight, context, out );
}
}
else if ( const QgsGeometryCollection *gc = qgsgeometry_cast< const QgsGeometryCollection *>( g ) )
{
for ( int i = 0; i < gc->numGeometries(); ++i )
{
const QgsAbstractGeometry *g2 = gc->geometryN( i );
if ( QgsWkbTypes::flatType( g2->wkbType() ) == QgsWkbTypes::Polygon )
{
QgsPolygon *polyClone = static_cast< const QgsPolygon *>( g2 )->clone();
processPolygon( polyClone, f.id(), height, hasDDExtrusion, extrusionHeight, context, out );
}
}
}
else
Expand Down

0 comments on commit 4a554d2

Please sign in to comment.