Skip to content

Commit

Permalink
[BUGFIX] QgsGeometry exportToGeoJSON return 'null' for null Geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Apr 29, 2016
1 parent abfd774 commit f48e74f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -928,7 +928,7 @@ QString QgsGeometry::exportToGeoJSON( int precision ) const
{
if ( !d->geometry )
{
return QString();
return QString( "null" );
}
return d->geometry->asJSON( precision );
}
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -3311,6 +3311,12 @@ void TestQgsGeometry::exportToGeoJSON()
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"MultiPolygon\", \"coordinates\": [[[ [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]], [[ [2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]]] }";
QCOMPARE( obtained, geojson );

// no geometry
QgsGeometry nullGeom( nullptr );
obtained = nullGeom.exportToGeoJSON();
geojson = "null";
QCOMPARE( obtained, geojson );
}

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

0 comments on commit f48e74f

Please sign in to comment.