mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
[geometry] Handle exporting of empty interior ring as WKT in a manner that will allow for re-creating geometries afterwards (#58616)
* [geometry] Handle exporting of empty interior ring as WKT in a manner that will allow for re-creating geometries afterwards * Address review
This commit is contained in:
parent
774399c3ea
commit
eaa39c4a14
@ -305,13 +305,16 @@ QString QgsCurvePolygon::asWkt( int precision ) const
|
||||
}
|
||||
for ( const QgsCurve *curve : mInteriorRings )
|
||||
{
|
||||
QString childWkt = curve->asWkt( precision );
|
||||
if ( qgsgeometry_cast<const QgsLineString *>( curve ) )
|
||||
if ( !curve->isEmpty() )
|
||||
{
|
||||
// Type names of linear geometries are omitted
|
||||
childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
|
||||
QString childWkt = curve->asWkt( precision );
|
||||
if ( qgsgeometry_cast<const QgsLineString *>( curve ) )
|
||||
{
|
||||
// Type names of linear geometries are omitted
|
||||
childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
|
||||
}
|
||||
wkt += childWkt + ',';
|
||||
}
|
||||
wkt += childWkt + ',';
|
||||
}
|
||||
if ( wkt.endsWith( ',' ) )
|
||||
{
|
||||
|
@ -206,19 +206,22 @@ QString QgsPolygon::asWkt( int precision ) const
|
||||
}
|
||||
for ( const QgsCurve *curve : mInteriorRings )
|
||||
{
|
||||
QString childWkt;
|
||||
if ( ! qgsgeometry_cast<QgsLineString *>( curve ) )
|
||||
if ( !curve->isEmpty() )
|
||||
{
|
||||
std::unique_ptr<QgsLineString> line( curve->curveToLine() );
|
||||
childWkt = line->asWkt( precision );
|
||||
QString childWkt;
|
||||
if ( ! qgsgeometry_cast<QgsLineString *>( curve ) )
|
||||
{
|
||||
std::unique_ptr<QgsLineString> line( curve->curveToLine() );
|
||||
childWkt = line->asWkt( precision );
|
||||
}
|
||||
else
|
||||
{
|
||||
childWkt = curve->asWkt( precision );
|
||||
}
|
||||
// Type names of linear geometries are omitted
|
||||
childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
|
||||
wkt += childWkt + ',';
|
||||
}
|
||||
else
|
||||
{
|
||||
childWkt = curve->asWkt( precision );
|
||||
}
|
||||
// Type names of linear geometries are omitted
|
||||
childWkt = childWkt.mid( childWkt.indexOf( '(' ) );
|
||||
wkt += childWkt + ',';
|
||||
}
|
||||
if ( wkt.endsWith( ',' ) )
|
||||
{
|
||||
|
@ -1731,6 +1731,17 @@ void TestQgsCurvePolygon::testWKT()
|
||||
QVERIFY( !poly2.is3D() );
|
||||
QVERIFY( !poly2.isMeasure() );
|
||||
QCOMPARE( poly2.wkbType(), Qgis::WkbType::CurvePolygon );
|
||||
|
||||
// Test WKT export with empty interior ring
|
||||
QgsCurvePolygon poly3;
|
||||
QgsCircularString *ext2 = new QgsCircularString();
|
||||
ext2->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 10, 1 )
|
||||
<< QgsPoint( Qgis::WkbType::PointZM, 10, 0, 11, 2 ) << QgsPoint( Qgis::WkbType::PointZM, 10, 10, 12, 3 )
|
||||
<< QgsPoint( Qgis::WkbType::PointZM, 0, 10, 13, 4 ) << QgsPoint( Qgis::WkbType::PointZM, 0, 0, 10, 1 ) );
|
||||
poly3.setExteriorRing( ext2 );
|
||||
poly3.addInteriorRing( new QgsCircularString() );
|
||||
wkt = poly3.asWkt();
|
||||
QCOMPARE( wkt, QStringLiteral( "CurvePolygonZM (CircularStringZM (0 0 10 1, 10 0 11 2, 10 10 12 3, 0 10 13 4, 0 0 10 1))" ) );
|
||||
}
|
||||
|
||||
void TestQgsCurvePolygon::testExport()
|
||||
|
@ -2854,6 +2854,19 @@ void TestQgsPolygon::toFromWKT()
|
||||
pl3.addInteriorRing( compound );
|
||||
wkt = pl3.asWkt();
|
||||
QCOMPARE( wkt, QStringLiteral( "Polygon ((0 0, 0 10, 10 10, 10 0, 0 0),(1 1, 1 9, 9 9, 9 1, 1 1))" ) );
|
||||
|
||||
// Test WKT export with empty interior ring
|
||||
QgsPolygon pl4;
|
||||
QgsLineString *ext4 = new QgsLineString();
|
||||
ext4->setPoints( QgsPointSequence() << QgsPoint( Qgis::WkbType::Point, 0, 0 )
|
||||
<< QgsPoint( Qgis::WkbType::Point, 0, 10 )
|
||||
<< QgsPoint( Qgis::WkbType::Point, 10, 10 )
|
||||
<< QgsPoint( Qgis::WkbType::Point, 10, 0 )
|
||||
<< QgsPoint( Qgis::WkbType::Point, 0, 0 ) );
|
||||
pl4.setExteriorRing( ext4 );
|
||||
pl4.addInteriorRing( new QgsLineString() );
|
||||
wkt = pl4.asWkt();
|
||||
QCOMPARE( wkt, QStringLiteral( "Polygon ((0 0, 0 10, 10 10, 10 0, 0 0))" ) );
|
||||
}
|
||||
|
||||
void TestQgsPolygon::exportImport()
|
||||
|
Loading…
x
Reference in New Issue
Block a user