Skip to content

Commit a9cec38

Browse files
lbartolettinyalldawson
authored andcommitted
Fix a crash when asJson is called on an empty PolygonGeometry
1 parent 658d35d commit a9cec38

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/core/geometry/qgscurvepolygon.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -402,22 +402,25 @@ QString QgsCurvePolygon::asJson( int precision ) const
402402
// GeoJSON does not support curves
403403
QString json = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [" );
404404

405-
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
406-
QgsPointSequence exteriorPts;
407-
exteriorLineString->points( exteriorPts );
408-
json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", ";
409-
410-
std::unique_ptr< QgsLineString > interiorLineString;
411-
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
412-
{
413-
interiorLineString.reset( interiorRing( i )->curveToLine() );
414-
QgsPointSequence interiorPts;
415-
interiorLineString->points( interiorPts );
416-
json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", ";
417-
}
418-
if ( json.endsWith( QLatin1String( ", " ) ) )
405+
if ( exteriorRing() )
419406
{
420-
json.chop( 2 ); // Remove last ", "
407+
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
408+
QgsPointSequence exteriorPts;
409+
exteriorLineString->points( exteriorPts );
410+
json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + QLatin1String( ", " );
411+
412+
std::unique_ptr< QgsLineString > interiorLineString;
413+
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
414+
{
415+
interiorLineString.reset( interiorRing( i )->curveToLine() );
416+
QgsPointSequence interiorPts;
417+
interiorLineString->points( interiorPts );
418+
json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + QLatin1String( ", " );
419+
}
420+
if ( json.endsWith( QLatin1String( ", " ) ) )
421+
{
422+
json.chop( 2 ); // Remove last ", "
423+
}
421424
}
422425
json += QLatin1String( "] }" );
423426
return json;

0 commit comments

Comments
 (0)