Skip to content

Commit d131b7a

Browse files
committed
Support multilines / polygons / multipolygons (as closed linestrings for now)
1 parent eee9a49 commit d131b7a

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

src/core/qgsdxfexport.cpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ void QgsDxfExport::writeEntities( QTextStream& stream )
459459
QgsFeature fet;
460460
while ( featureIt.nextFeature( fet ) )
461461
{
462-
if ( mSymbologyExport == NoSymbology )
462+
if ( 0 /*mSymbologyExport == NoSymbology*/ )
463463
{
464464
addFeature( fet, stream, vl->name(), 0 ); //no symbology at all
465465
}
@@ -522,7 +522,7 @@ void QgsDxfExport::endSection( QTextStream& stream )
522522
}
523523

524524
void QgsDxfExport::writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, int color,
525-
double width, bool closed )
525+
double width, bool polygon )
526526
{
527527
stream << " 0\n";
528528
stream << "POLYLINE\n";
@@ -535,7 +535,7 @@ void QgsDxfExport::writePolyline( QTextStream& stream, const QgsPolyline& line,
535535
stream << " 66\n";
536536
stream << "1\n";
537537
stream << " 70\n";
538-
int type = closed ? 32 : 0;
538+
int type = polygon ? 49 : 0;
539539
stream << type << "\n";
540540
stream << " 40\n";
541541
stream << width << "\n";
@@ -592,11 +592,54 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, QTextStream& stream, const
592592
QgsGeometry* geom = fet.geometry();
593593
if ( geom )
594594
{
595-
//get color from symbollayer
596595
int c = colorFromSymbolLayer( symbolLayer );
597-
//get width from symbollayer
598596
double width = widthFromSymbolLayer( symbolLayer );
599-
writePolyline( stream, geom->asPolyline(), layer, c, width );
597+
598+
//todo: write point symbols as blocks
599+
600+
QGis::WkbType geometryType = geom->wkbType();
601+
//single line
602+
if ( geometryType == QGis::WKBLineString || geometryType == QGis::WKBLineString25D )
603+
{
604+
writePolyline( stream, geom->asPolyline(), layer, c, width, false );
605+
}
606+
607+
//multiline
608+
if ( geometryType == QGis::WKBMultiLineString || geometryType == QGis::WKBMultiLineString25D )
609+
{
610+
QgsMultiPolyline multiLine = geom->asMultiPolyline();
611+
QgsMultiPolyline::const_iterator lIt = multiLine.constBegin();
612+
for ( ; lIt != multiLine.constEnd(); ++lIt )
613+
{
614+
writePolyline( stream, *lIt, layer, c, width, false );
615+
}
616+
}
617+
618+
//polygon
619+
if ( geometryType == QGis::WKBPolygon || geometryType == QGis::WKBPolygon25D )
620+
{
621+
QgsPolygon polygon = geom->asPolygon();
622+
QgsPolygon::const_iterator polyIt = polygon.constBegin();
623+
for ( ; polyIt != polygon.constEnd(); ++polyIt ) //iterate over rings
624+
{
625+
writePolyline( stream, *polyIt, layer, c, width, true );
626+
}
627+
}
628+
629+
//multipolygon or polygon
630+
if ( geometryType == QGis::WKBMultiPolygon || geometryType == QGis::WKBMultiPolygon25D )
631+
{
632+
QgsMultiPolygon mp = geom->asMultiPolygon();
633+
QgsMultiPolygon::const_iterator mpIt = mp.constBegin();
634+
for ( ; mpIt != mp.constEnd(); ++mpIt )
635+
{
636+
QgsPolygon::const_iterator polyIt = mpIt->constBegin();
637+
for ( ; polyIt != mpIt->constEnd(); ++polyIt )
638+
{
639+
writePolyline( stream, *polyIt, layer, c, width, true );
640+
}
641+
}
642+
}
600643
}
601644
}
602645

src/core/qgsdxfexport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class QgsDxfExport
7070
void endSection( QTextStream& stream );
7171

7272
void writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, int color,
73-
double width = -1, bool closed = false );
73+
double width = -1, bool polygon = false );
7474
void writeVertex( QTextStream& stream, const QgsPoint& pt, const QString& layer );
7575

7676
QgsRectangle dxfExtent() const;

0 commit comments

Comments
 (0)