Skip to content
Permalink
Browse files

dxf export: segmentize curves

(forward ported from cc3a053)
  • Loading branch information
jef-n committed Sep 12, 2016
1 parent 074d22f commit 13e37d4b88c8b2668c72dc5e25c3fc505cc7a2f5
Showing with 101 additions and 79 deletions.
  1. +101 −79 src/core/dxf/qgsdxfexport.cpp
@@ -3781,110 +3781,132 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext& ctx, const QString& layer

if ( penStyle != Qt::NoPen )
{
// single line
if ( QgsWkbTypes::flatType( geometryType ) == QgsWkbTypes::LineString )
{
const QgsAbstractGeometry *offsetGeom = geom;
if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( geom );
offsetGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetGeom )
offsetGeom = geom;
}
const QgsAbstractGeometryV2 *tempGeom = geom;

writePolyline( offsetGeom->coordinateSequence().at( 0 ).at( 0 ), layer, lineStyleName, penColor, width );
switch ( QgsWkbTypes::flatType( geometryType ) )
{
case QgsWkbTypes::CircularString:
case QgsWkbypes::CompoundCurve:
tempGeom = geom->segmentize();
FALLTHROUGH;
case QgsWkbTypes::LineString:
if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( tempGeom );
if ( tempGeom != geom )
delete tempGeom;
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !tempGeom )
tempGeom = geom;
}

if ( offsetGeom != geom )
delete offsetGeom;
}
writePolyline( tempGeom->coordinateSequence().at( 0 ).at( 0 ), layer, lineStyleName, penColor, width );

// multiline
if ( QgsWkbTypes::flatType( geometryType ) == QgsWkbTypes::MultiLineString )
{
const QgsAbstractGeometry *offsetGeom = geom;
break;

if ( !qgsDoubleNear( offset, 0.0 ) )
case QgsWkbTypes::MultiCurve:
tempGeom = geom->segmentize();
FALLTHROUGH;
case QgsWkbTypes::MultiLineString:
{
QgsGeos geos( geom );
offsetGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetGeom )
offsetGeom = geom;
}
if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( tempGeom );
if ( tempGeom != geom )
delete tempGeom;
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !tempGeom )
tempGeom = geom;
}

const QgsCoordinateSequence &cs = offsetGeom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
{
writePolyline( cs.at( i ).at( 0 ), layer, lineStyleName, penColor, width );
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
{
writePolyline( cs.at( i ).at( 0 ), layer, lineStyleName, penColor, width );
}

break;
}

if ( offsetGeom != geom )
delete offsetGeom;
}
case QgsWkbTypes::CurvePolygon:
tempGeom = geom->segmentize();
FALLTHROUGH;
case QgsWkbTypes::Polygon:
{
if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( tempGeom );
if ( tempGeom != geom )
delete tempGeom;
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !tempGeom )
tempGeom = geom;
}

// polygon
if ( QgsWkbTypes::flatType( geometryType ) == QgsWkbTypes::Polygon )
{
const QgsAbstractGeometry *bufferGeom = geom;
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
for ( int i = 0; i < cs.at( 0 ).size(); i++ )
{
writePolyline( cs.at( 0 ).at( i ), layer, lineStyleName, penColor, width );
}

if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( geom );
bufferGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !bufferGeom )
bufferGeom = geom;
break;
}

const QgsCoordinateSequence &cs = bufferGeom->coordinateSequence();
for ( int i = 0; i < cs.at( 0 ).size(); i++ )
case QgsWkbTypes::MultiPolygon:
{
writePolyline( cs.at( 0 ).at( i ), layer, lineStyleName, penColor, width );
}

if ( bufferGeom != geom )
delete bufferGeom;
}
if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( tempGeom );
if ( tempGeom != geom )
delete tempGeom;
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !tempGeom )
tempGeom = geom;
}

// multipolygon or polygon
if ( QgsWkbTypes::flatType( geometryType ) == QgsWkbTypes::MultiPolygon )
{
const QgsAbstractGeometry *bufferGeom = geom;
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
for ( int j = 0; j < cs.at( i ).size(); j++ )
writePolyline( cs.at( i ).at( j ), layer, lineStyleName, penColor, width );

if ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( geom );
bufferGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !bufferGeom )
bufferGeom = geom;
break;
}

const QgsCoordinateSequence &cs = bufferGeom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
for ( int j = 0; j < cs.at( i ).size(); j++ )
writePolyline( cs.at( i ).at( j ), layer, lineStyleName, penColor, width );

if ( bufferGeom != geom )
delete bufferGeom;
default:
break;
}

if ( tempGeom != geom )
delete tempGeom;
}

if ( brushStyle != Qt::NoBrush )
{
// polygon
if ( QgsWkbTypes::flatType( geometryType ) == QgsWkbTypes::Polygon )
{
writePolygon( geom->coordinateSequence().at( 0 ), layer, "SOLID", brushColor );
}
const QgsAbstractGeometryV2 *tempGeom = geom;

// multipolygon or polygon
if ( QgsWkbTypes::flatType( geometryType ) == QgsWkbTypes::MultiPolygon )
switch ( QgsWkbTypes::flatType( geometryType ) )
{
const QgsCoordinateSequence &cs = geom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
{
writePolygon( cs.at( i ), layer, "SOLID", brushColor );
}
case QgsWkbTypes::CurvePolygon:
tempGeom = tempGeom->segmentize();
FALLTHROUGH;
case QgsWkbTypes::Polygon:
writePolygon( tempGeom->coordinateSequence().at( 0 ), layer, "SOLID", brushColor );
break;

case QgsWKBTypes::MultiPolygon:
const QgsCoordinateSequenceV2 &cs = geom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
{
writePolygon( cs.at( i ), layer, "SOLID", brushColor );
}

default:
break;

}

if ( tempGeom != geom )
delete tempGeom;
}
}

0 comments on commit 13e37d4

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