Skip to content
Permalink
Browse files

Fix a crash when asJson is called on an empty PolygonGeometry

  • Loading branch information
lbartoletti committed Mar 29, 2019
1 parent 61409c3 commit 2e791d0a0e3de1e93b45359188b2d098ceca30c4
Showing with 18 additions and 15 deletions.
  1. +18 −15 src/core/geometry/qgscurvepolygon.cpp
@@ -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;

0 comments on commit 2e791d0

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