Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9758 from lbartoletti/backport-9651-on-release-3_6
Backport #9651 on release 3 6
  • Loading branch information
m-kuhn committed Apr 12, 2019
2 parents 717501d + a15fb5c commit 336647c
Show file tree
Hide file tree
Showing 2 changed files with 51 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
33 changes: 33 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -158,6 +158,8 @@ class TestQgsGeometry : public QObject

void convertGeometryCollectionToSubclass();

void emptyJson();

private:
//! A helper method to do a render check to see if the geometry op is as expected
bool renderCheck( const QString &testName, const QString &comment = QString(), int mismatchCount = 0 );
Expand Down Expand Up @@ -17469,5 +17471,36 @@ void TestQgsGeometry::convertGeometryCollectionToSubclass()
QVERIFY( !wrong.convertGeometryCollectionToSubclass( QgsWkbTypes::PolygonGeometry ) );
}

void TestQgsGeometry::emptyJson()
{
QString expected;
// TODO: harmonize Json output. Should be ... [] }
expected = QStringLiteral( "{\"type\": \"LineString\", \"coordinates\": [ ]}" );
QCOMPARE( QgsCircularString().asJson(), expected );
QCOMPARE( QgsCompoundCurve().asJson(), expected );
QCOMPARE( QgsLineString().asJson(), expected );

expected = QStringLiteral( "{\"type\": \"GeometryCollection\", \"geometries\": [] }" );
QCOMPARE( QgsGeometryCollection().asJson(), expected );

expected = QStringLiteral( "{\"type\": \"MultiLineString\", \"coordinates\": [] }" );
QCOMPARE( QgsMultiCurve().asJson(), expected );
QCOMPARE( QgsMultiLineString().asJson(), expected );

expected = QStringLiteral( "{\"type\": \"MultiPoint\", \"coordinates\": [ ] }" );
QCOMPARE( QgsMultiPoint().asJson(), expected );

expected = QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [] }" );
QCOMPARE( QgsMultiSurface().asJson(), expected );

expected = QStringLiteral( "{\"type\": \"Point\", \"coordinates\": [0, 0]}" ); // should be []
QCOMPARE( QgsPoint().asJson(), expected );

expected = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [] }" );
QCOMPARE( QgsCurvePolygon().asJson(), expected );
QCOMPARE( QgsPolygon().asJson(), expected );
QCOMPARE( QgsTriangle().asJson(), expected );
}

QGSTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"

0 comments on commit 336647c

Please sign in to comment.