Skip to content

Commit

Permalink
Fix 3D polygon symbol to work with geometry collection
Browse files Browse the repository at this point in the history
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 da2064d commit da9df41
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/3d/symbols/qgspolygon3dsymbol_p.cpp
Original file line number Diff line number Diff line change
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 da9df41

Please sign in to comment.