Skip to content

Commit

Permalink
Fix dxf export ignores multisurface geometry types
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 23, 2019
1 parent 94e1328 commit 11f6ba8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 );
Expand Down
37 changes: 37 additions & 0 deletions tests/src/core/testqgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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" ) ) );
Expand Down

0 comments on commit 11f6ba8

Please sign in to comment.