Skip to content
Permalink
Browse files

dxf export: segmentize curves

  • Loading branch information
jef-n committed Sep 11, 2016
1 parent 1cbb842 commit cc3a0537371d15ccd8bf79c74f6da040f32be89f
Showing with 95 additions and 80 deletions.
  1. +95 −80 src/core/dxf/qgsdxfexport.cpp
@@ -3778,110 +3778,125 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QString& lay

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

writePolyline( offsetGeom->coordinateSequence().at( 0 ).at( 0 ), layer, lineStyleName, penColor, width );

if ( offsetGeom != geom )
delete offsetGeom;
}
const QgsAbstractGeometryV2 *tempGeom = geom;

// multiline
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::MultiLineString )
switch ( QgsWKBTypes::flatType( geometryType ) )
{
const QgsAbstractGeometryV2 *offsetGeom = geom;
case QgsWKBTypes::CircularString:
case QgsWKBTypes::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 ( !qgsDoubleNear( offset, 0.0 ) )
{
QgsGeos geos( geom );
offsetGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetGeom )
offsetGeom = geom;
}
writePolyline( tempGeom->coordinateSequence().at( 0 ).at( 0 ), layer, lineStyleName, penColor, width );

const QgsCoordinateSequenceV2 &cs = offsetGeom->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::MultiCurve:
tempGeom = geom->segmentize();
FALLTHROUGH;
case QgsWKBTypes::MultiLineString:
{
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;
}

// polygon
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::Polygon )
{
const QgsAbstractGeometryV2 *bufferGeom = geom;
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
for ( int i = 0; i < cs.size(); i++ )
{
writePolyline( cs.at( i ).at( 0 ), 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 QgsCoordinateSequenceV2 &cs = bufferGeom->coordinateSequence();
for ( int i = 0; i < cs.at( 0 ).size(); i++ )
case QgsWKBTypes::CurvePolygon:
tempGeom = geom->segmentize();
FALLTHROUGH;
case QgsWKBTypes::Polygon:
{
writePolyline( cs.at( 0 ).at( i ), layer, lineStyleName, penColor, width );
}
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;
}

if ( bufferGeom != geom )
delete bufferGeom;
}
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 );
}

// multipolygon or polygon
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::MultiPolygon )
{
const QgsAbstractGeometryV2 *bufferGeom = geom;
break;
}

if ( !qgsDoubleNear( offset, 0.0 ) )
case QgsWKBTypes::MultiPolygon:
{
QgsGeos geos( geom );
bufferGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !bufferGeom )
bufferGeom = geom;
}
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;
}

const QgsCoordinateSequenceV2 &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 );
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 ( bufferGeom != geom )
delete bufferGeom;
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 QgsCoordinateSequenceV2 &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 );
}
}

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

0 comments on commit cc3a053

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