Skip to content
Permalink
Browse files

[BUGFIX] Multipoint asJSON

Fixes #13855
Multipoint asJSON made MultiPoint as Multilinestring with only 1 point by linestring.

This bugfix adds tests.

Conflicts:
	src/core/geometry/qgsmultipointv2.cpp
	tests/src/core/testqgsgeometry.cpp
  • Loading branch information
rldhont committed Nov 20, 2015
1 parent 4f4fe59 commit 8d313723f260b5c4b6be9c791800591a94c51c3c
Showing with 53 additions and 7 deletions.
  1. +6 −7 src/core/geometry/qgsmultipointv2.cpp
  2. +47 −0 tests/src/core/testqgsgeometry.cpp
@@ -63,20 +63,19 @@ QDomElement QgsMultiPointV2::asGML3( QDomDocument& doc, int precision, const QSt

QString QgsMultiPointV2::asJSON( int precision ) const
{
QString json = "{\"type\": \"MultiPoint\", \"coordinates\": [";
QString json = "{\"type\": \"MultiPoint\", \"coordinates\": ";

QList<QgsPointV2> pts;
foreach ( const QgsAbstractGeometryV2 *geom, mGeometries )
{
if ( dynamic_cast<const QgsPointV2*>( geom ) )
{
const QgsPointV2* point = static_cast<const QgsPointV2*>( geom );
json += QgsGeometryUtils::pointsToJSON( QList<QgsPointV2>() << *point, precision ) + ", ";
pts << *point;
}
}
if ( json.endsWith( ", " ) )
{
json.chop( 2 ); // Remove last ", "
}
json += "] }";
json += QgsGeometryUtils::pointsToJSON( pts, precision );
json += " }";
return json;
}

@@ -80,6 +80,8 @@ class TestQgsGeometry : public QObject
void bufferCheck();
void smoothCheck();

void exportToGeoJSON();

private:
/** A helper method to do a render check to see if the geometry op is as expected */
bool renderCheck( QString theTestName, QString theComment = "", int mismatchCount = 0 );
@@ -706,6 +708,51 @@ void TestQgsGeometry::smoothCheck()
QVERIFY( QgsGeometry::compare( multipoly, expectedMultiPoly ) );
}

void TestQgsGeometry::exportToGeoJSON()
{
//Point
QString wkt = "Point (40 50)";
QScopedPointer<QgsGeometry> geom( QgsGeometry::fromWkt( wkt ) );
QString obtained = geom->exportToGeoJSON();
QString geojson = "{\"type\": \"Point\", \"coordinates\": [40, 50]}";
QCOMPARE( obtained, geojson );

//MultiPoint
wkt = "MultiPoint (0 0, 10 0, 10 10, 20 10)";
geom.reset( QgsGeometry::fromWkt( wkt ) );
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"MultiPoint\", \"coordinates\": [ [0, 0], [10, 0], [10, 10], [20, 10]] }";
QCOMPARE( obtained, geojson );

//Linestring
wkt = "LineString(0 0, 10 0, 10 10, 20 10)";
geom.reset( QgsGeometry::fromWkt( wkt ) );
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"LineString\", \"coordinates\": [ [0, 0], [10, 0], [10, 10], [20, 10]]}";
QCOMPARE( obtained, geojson );

//MultiLineString
wkt = "MultiLineString ((0 0, 10 0, 10 10, 20 10),(30 30, 40 30, 40 40, 50 40))";
geom.reset( QgsGeometry::fromWkt( wkt ) );
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"MultiLineString\", \"coordinates\": [[ [0, 0], [10, 0], [10, 10], [20, 10]], [ [30, 30], [40, 30], [40, 40], [50, 40]]] }";
QCOMPARE( obtained, geojson );

//Polygon
wkt = "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ),(2 2, 4 2, 4 4, 2 4, 2 2))";
geom.reset( QgsGeometry::fromWkt( wkt ) );
obtained = geom->exportToGeoJSON();
geojson = "{\"type\": \"Polygon\", \"coordinates\": [[ [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]], [ [2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]] }";
QCOMPARE( obtained, geojson );

//MultiPolygon
wkt = "MultiPolygon (((0 0, 10 0, 10 10, 0 10, 0 0 )),((2 2, 4 2, 4 4, 2 4, 2 2)))";
geom.reset( QgsGeometry::fromWkt( wkt ) );
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 );
}

bool TestQgsGeometry::renderCheck( QString theTestName, QString theComment, int mismatchCount )
{
mReport += "<h2>" + theTestName + "</h2>\n";

4 comments on commit 8d31372

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Nov 26, 2015

This commit has broken travis for 2.10 https://travis-ci.org/qgis/QGIS/builds/92230210

There are no more bugfix releases officially planned.
But you still seem to be backporting, so in case you plan an additional release, keep this in mind.

@rldhont

This comment has been minimized.

Copy link
Contributor Author

@rldhont rldhont replied Nov 26, 2015

Thanks for pointing this issue.

I know that, there's no bugfix releases officialy planned.
But some customers can't update to release 2.12.
I'll fix it

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Nov 26, 2015

Tell them the 2.12 upgrade is a free one ;)

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Nov 26, 2015

These commits certainly are interesting as well. I did not backport them since they did not apply cleanly, but if you have customers that are bound to 2.10, you may want to look into it
436c30f 62591d9

Please sign in to comment.
You can’t perform that action at this time.