Skip to content
Permalink
Browse files

Fix dxf export ignores multisurface geometry types

Fixes #21779
  • Loading branch information
nyalldawson committed May 23, 2019
1 parent f9810a4 commit bdbca5aa17a8ba4d4e3148712a4a5192c667b38c
Showing with 48 additions and 1 deletion.
  1. +11 −1 src/core/dxf/qgsdxfexport.cpp
  2. +37 −0 tests/src/core/testqgsdxfexport.cpp
@@ -3857,6 +3857,11 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
break;
}

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

case QgsWkbTypes::MultiSurface:
tempGeom = tempGeom->segmentize();
if ( !tempGeom )
break;
FALLTHROUGH
case QgsWkbTypes::MultiPolygon:
{
const QgsCoordinateSequence &cs = geom->coordinateSequence();
const QgsCoordinateSequence &cs = tempGeom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
{
writePolygon( cs.at( i ), layer, QStringLiteral( "SOLID" ), brushColor );
@@ -44,6 +44,7 @@ class TestQgsDxfExport : public QObject
void testPoints();
void testLines();
void testPolygons();
void testMultiSurface();
void testMtext();
void testMTextNoSymbology(); //tests if label export works if layer has vector renderer type 'no symbols'
void testMTextEscapeSpaces();
@@ -216,6 +217,42 @@ void TestQgsDxfExport::testPolygons()
QCOMPARE( result->wkbType(), QgsWkbTypes::LineString );
}

void TestQgsDxfExport::testMultiSurface()
{
QgsDxfExport d;
std::unique_ptr< QgsVectorLayer > vl = qgis::make_unique< QgsVectorLayer >( QStringLiteral( "MultiSurface" ), QString(), QStringLiteral( "memory" ) );
QgsGeometry g = QgsGeometry::fromWkt( "MultiSurface (Polygon ((0 0, 0 1, 1 1, 0 0)))" );
QgsFeature f;
f.setGeometry( g );
vl->dataProvider()->addFeatures( QgsFeatureList() << f );
d.addLayers( QList< QgsDxfExport::DxfLayer >() << QgsDxfExport::DxfLayer( vl.get() ) );

QgsMapSettings mapSettings;
QSize size( 640, 480 );
mapSettings.setOutputSize( size );
mapSettings.setExtent( vl->extent() );
mapSettings.setLayers( QList<QgsMapLayer *>() << vl.get() );
mapSettings.setOutputDpi( 96 );
mapSettings.setDestinationCrs( vl->crs() );

d.setMapSettings( mapSettings );
d.setSymbologyScale( 1000 );

QString file = getTempFileName( "multisurface_dxf" );
QFile dxfFile( file );
QCOMPARE( d.writeToFile( &dxfFile, QStringLiteral( "CP1252" ) ), 0 );
dxfFile.close();

// reload and compare
std::unique_ptr< QgsVectorLayer > result = qgis::make_unique< QgsVectorLayer >( file, "dxf" );
QVERIFY( result->isValid() );
QCOMPARE( result->featureCount(), 1L );
QCOMPARE( result->wkbType(), QgsWkbTypes::LineString );
QgsFeature f2;
result->getFeatures().nextFeature( f2 );
QCOMPARE( f2.geometry().asWkt(), QStringLiteral( "LineString (0 0, 0 1, 1 1, 0 0)" ) );
}

void TestQgsDxfExport::testMtext()
{
QVERIFY( testMtext( mPointLayer, QStringLiteral( "mtext_dxf" ) ) );

0 comments on commit bdbca5a

Please sign in to comment.
You can’t perform that action at this time.