[BUGFIX] QgsGeometry exportToGeoJSON return 'null' for null Geometry

This commit is contained in:
rldhont 2016-04-29 14:22:35 +02:00
parent abfd7740bd
commit f48e74f33c
2 changed files with 7 additions and 1 deletions

View File

@ -928,7 +928,7 @@ QString QgsGeometry::exportToGeoJSON( int precision ) const
{
if ( !d->geometry )
{
return QString();
return QString( "null" );
}
return d->geometry->asJSON( precision );
}

View File

@ -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 )