Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bdbca5a

Browse files
committedMay 23, 2019
Fix dxf export ignores multisurface geometry types
Fixes #21779
1 parent f9810a4 commit bdbca5a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
 

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3857,6 +3857,11 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
38573857
break;
38583858
}
38593859

3860+
case QgsWkbTypes::MultiSurface:
3861+
tempGeom = geom->segmentize();
3862+
if ( !tempGeom )
3863+
break;
3864+
FALLTHROUGH
38603865
case QgsWkbTypes::MultiPolygon:
38613866
{
38623867
if ( !qgsDoubleNear( offset, 0.0 ) )
@@ -3900,9 +3905,14 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
39003905
writePolygon( tempGeom->coordinateSequence().at( 0 ), layer, QStringLiteral( "SOLID" ), brushColor );
39013906
break;
39023907

3908+
case QgsWkbTypes::MultiSurface:
3909+
tempGeom = tempGeom->segmentize();
3910+
if ( !tempGeom )
3911+
break;
3912+
FALLTHROUGH
39033913
case QgsWkbTypes::MultiPolygon:
39043914
{
3905-
const QgsCoordinateSequence &cs = geom->coordinateSequence();
3915+
const QgsCoordinateSequence &cs = tempGeom->coordinateSequence();
39063916
for ( int i = 0; i < cs.size(); i++ )
39073917
{
39083918
writePolygon( cs.at( i ), layer, QStringLiteral( "SOLID" ), brushColor );

‎tests/src/core/testqgsdxfexport.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TestQgsDxfExport : public QObject
4444
void testPoints();
4545
void testLines();
4646
void testPolygons();
47+
void testMultiSurface();
4748
void testMtext();
4849
void testMTextNoSymbology(); //tests if label export works if layer has vector renderer type 'no symbols'
4950
void testMTextEscapeSpaces();
@@ -216,6 +217,42 @@ void TestQgsDxfExport::testPolygons()
216217
QCOMPARE( result->wkbType(), QgsWkbTypes::LineString );
217218
}
218219

220+
void TestQgsDxfExport::testMultiSurface()
221+
{
222+
QgsDxfExport d;
223+
std::unique_ptr< QgsVectorLayer > vl = qgis::make_unique< QgsVectorLayer >( QStringLiteral( "MultiSurface" ), QString(), QStringLiteral( "memory" ) );
224+
QgsGeometry g = QgsGeometry::fromWkt( "MultiSurface (Polygon ((0 0, 0 1, 1 1, 0 0)))" );
225+
QgsFeature f;
226+
f.setGeometry( g );
227+
vl->dataProvider()->addFeatures( QgsFeatureList() << f );
228+
d.addLayers( QList< QgsDxfExport::DxfLayer >() << QgsDxfExport::DxfLayer( vl.get() ) );
229+
230+
QgsMapSettings mapSettings;
231+
QSize size( 640, 480 );
232+
mapSettings.setOutputSize( size );
233+
mapSettings.setExtent( vl->extent() );
234+
mapSettings.setLayers( QList<QgsMapLayer *>() << vl.get() );
235+
mapSettings.setOutputDpi( 96 );
236+
mapSettings.setDestinationCrs( vl->crs() );
237+
238+
d.setMapSettings( mapSettings );
239+
d.setSymbologyScale( 1000 );
240+
241+
QString file = getTempFileName( "multisurface_dxf" );
242+
QFile dxfFile( file );
243+
QCOMPARE( d.writeToFile( &dxfFile, QStringLiteral( "CP1252" ) ), 0 );
244+
dxfFile.close();
245+
246+
// reload and compare
247+
std::unique_ptr< QgsVectorLayer > result = qgis::make_unique< QgsVectorLayer >( file, "dxf" );
248+
QVERIFY( result->isValid() );
249+
QCOMPARE( result->featureCount(), 1L );
250+
QCOMPARE( result->wkbType(), QgsWkbTypes::LineString );
251+
QgsFeature f2;
252+
result->getFeatures().nextFeature( f2 );
253+
QCOMPARE( f2.geometry().asWkt(), QStringLiteral( "LineString (0 0, 0 1, 1 1, 0 0)" ) );
254+
}
255+
219256
void TestQgsDxfExport::testMtext()
220257
{
221258
QVERIFY( testMtext( mPointLayer, QStringLiteral( "mtext_dxf" ) ) );

0 commit comments

Comments
 (0)
Please sign in to comment.