Skip to content

Commit f48e74f

Browse files
committedApr 29, 2016
[BUGFIX] QgsGeometry exportToGeoJSON return 'null' for null Geometry
1 parent abfd774 commit f48e74f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ QString QgsGeometry::exportToGeoJSON( int precision ) const
928928
{
929929
if ( !d->geometry )
930930
{
931-
return QString();
931+
return QString( "null" );
932932
}
933933
return d->geometry->asJSON( precision );
934934
}

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,6 +3311,12 @@ void TestQgsGeometry::exportToGeoJSON()
33113311
obtained = geom->exportToGeoJSON();
33123312
geojson = "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]], [[ [2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]]] }";
33133313
QCOMPARE( obtained, geojson );
3314+
3315+
// no geometry
3316+
QgsGeometry nullGeom( nullptr );
3317+
obtained = nullGeom.exportToGeoJSON();
3318+
geojson = "null";
3319+
QCOMPARE( obtained, geojson );
33143320
}
33153321

33163322
bool TestQgsGeometry::renderCheck( const QString& theTestName, const QString& theComment, int mismatchCount )

0 commit comments

Comments
 (0)
Please sign in to comment.