Skip to content

Commit

Permalink
Fix a crash when asJson is called on an empty PolygonGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Apr 8, 2019
1 parent 658d35d commit a9cec38
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -402,22 +402,25 @@ QString QgsCurvePolygon::asJson( int precision ) const
// GeoJSON does not support curves
QString json = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [" );

std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
QgsPointSequence exteriorPts;
exteriorLineString->points( exteriorPts );
json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", ";

std::unique_ptr< QgsLineString > interiorLineString;
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
interiorLineString.reset( interiorRing( i )->curveToLine() );
QgsPointSequence interiorPts;
interiorLineString->points( interiorPts );
json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", ";
}
if ( json.endsWith( QLatin1String( ", " ) ) )
if ( exteriorRing() )
{
json.chop( 2 ); // Remove last ", "
std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
QgsPointSequence exteriorPts;
exteriorLineString->points( exteriorPts );
json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + QLatin1String( ", " );

std::unique_ptr< QgsLineString > interiorLineString;
for ( int i = 0, n = numInteriorRings(); i < n; ++i )
{
interiorLineString.reset( interiorRing( i )->curveToLine() );
QgsPointSequence interiorPts;
interiorLineString->points( interiorPts );
json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + QLatin1String( ", " );
}
if ( json.endsWith( QLatin1String( ", " ) ) )
{
json.chop( 2 ); // Remove last ", "
}
}
json += QLatin1String( "] }" );
return json;
Expand Down

0 comments on commit a9cec38

Please sign in to comment.