Skip to content
Permalink
Browse files

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 336647cd7052edadc82dc39f767cbf038f02f983
Showing with 51 additions and 15 deletions.
  1. +18 −15 src/core/geometry/qgscurvepolygon.cpp
  2. +33 −0 tests/src/core/testqgsgeometry.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;
@@ -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 );
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.
You can’t perform that action at this time.