Skip to content

Commit

Permalink
QgsArcGisRestUtils::parseCompoundCurve(): fix crash on CircularString…
Browse files Browse the repository at this point in the history
… / "c"

Spotted by cppcheck

Independently of this fix, it looks like the geometry building when
mixing linestrings and circularstrings would need some more love...
  • Loading branch information
rouault authored and nyalldawson committed May 19, 2020
1 parent 996d812 commit 7762168
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/providers/arcgisrest/qgsarcgisrestutils.cpp
Expand Up @@ -171,12 +171,13 @@ std::unique_ptr< QgsCompoundCurve > QgsArcGisRestUtils::parseCompoundCurve( cons
if ( compoundCurve->curveAt( compoundCurve->nCurves() - 1 )->nCoordinates() < 2 )
compoundCurve->removeCurve( compoundCurve->nCurves() - 1 );

const QgsPoint endPointCircularString = circularString->endPoint();
compoundCurve->addCurve( circularString.release() );

// Prepare a new line string
lineString = new QgsLineString;
compoundCurve->addCurve( lineString );
lineString->addVertex( circularString->endPoint() );
lineString->addVertex( endPointCircularString );
}
}
return compoundCurve;
Expand Down
10 changes: 10 additions & 0 deletions tests/src/providers/testqgsarcgisrestutils.cpp
Expand Up @@ -54,6 +54,7 @@ class TestQgsArcGisRestUtils : public QObject
void testParseRendererSimple();
void testParseRendererCategorized();
void testParseLabeling();
void testParseCompoundCurve();

private:

Expand Down Expand Up @@ -607,5 +608,14 @@ QVariantMap TestQgsArcGisRestUtils::jsonStringToMap( const QString &string ) con
return doc.object().toVariantMap();
}

void TestQgsArcGisRestUtils::testParseCompoundCurve()
{
QVariantMap map = jsonStringToMap( "{\"curvePaths\": [[[6,3],[5,3],{\"c\": [[3,3],[1,4]]}]]}" );
std::unique_ptr< QgsMultiCurve > curve( QgsArcGisRestUtils::parseEsriGeometryPolyline( map, QgsWkbTypes::Point ) );
QVERIFY( curve );
// FIXME: the final linestring with one single point (1 4) is wrong !
QCOMPARE( curve->asWkt(), QStringLiteral( "MultiCurve (CompoundCurve ((6 3, 5 3),CircularString (5 3, 3 3, 1 4),(1 4)))" ) );
}

QGSTEST_MAIN( TestQgsArcGisRestUtils )
#include "testqgsarcgisrestutils.moc"

0 comments on commit 7762168

Please sign in to comment.