Skip to content
Permalink
Browse files

Support also curved geometries for tracing (fixes #15109)

  • Loading branch information
wonder-sk committed Jun 30, 2016
1 parent 5f66276 commit bf07d2bf58588d52feffea0b095964cdc8003c88
Showing with 49 additions and 0 deletions.
  1. +14 −0 src/core/qgstracer.cpp
  2. +35 −0 tests/src/core/testqgstracer.cpp
@@ -408,6 +408,20 @@ void resetGraph( QgsTracerGraph& g )

void extractLinework( const QgsGeometry* g, QgsMultiPolyline& mpl )
{
// segmentize curved geometries - we will use noding algorithm from GEOS
// to find all intersections a bit later (so we need them segmentized anyway)
QScopedPointer<QgsGeometry> segmentizedGeom;
if ( QgsWKBTypes::isCurvedType( g->geometry()->wkbType() ) )
{
QgsAbstractGeometryV2* segmentizedGeomV2 = g->geometry()->segmentize();
if ( !segmentizedGeomV2 )
return;

// temporarily replace the original geometry by our segmentized one
segmentizedGeom.reset( new QgsGeometry( segmentizedGeomV2 ) );
g = segmentizedGeom.data();
}

switch ( QgsWKBTypes::flatType( g->geometry()->wkbType() ) )
{
case QgsWKBTypes::LineString:
@@ -34,6 +34,7 @@ class TestQgsTracer : public QObject
void testLayerUpdates();
void testExtent();
void testReprojection();
void testCurved();

private:

@@ -319,6 +320,40 @@ void TestQgsTracer::testReprojection()
QCOMPARE( points1.count(), 2 );
}

void TestQgsTracer::testCurved()
{
QStringList wkts;
wkts << "CIRCULARSTRING(0 0, 10 10, 20 0)";

/* This shape - half of a circle (r = 10)
* 10,10 _
* / \
* 0,0 | | 20,0
*/

QgsVectorLayer* vl = make_layer( wkts );

QgsTracer tracer;
tracer.setLayers( QList<QgsVectorLayer*>() << vl );

QgsPolyline points1 = tracer.findShortestPath( QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) );

QVERIFY( points1.count() != 0 );

QgsGeometry* tmpG1 = QgsGeometry::fromPolyline( points1 );
double l = tmpG1->length();
delete tmpG1;

// fuzzy comparison of QCOMPARE is too strict for this case
double full_circle_length = 2 * M_PI * 10;
QVERIFY( qAbs( l - full_circle_length / 4 ) < 0.01 );

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Jun 30, 2016

Contributor

Better to use QGSCOMPARENEAR from qgstestutils.h here - it gives better outputs if the test fails

This comment has been minimized.

Copy link
@wonder-sk

wonder-sk Jul 5, 2016

Author Member

Thanks Nyall for the hint - updated in cdf82a2


QCOMPARE( points1[0], QgsPoint( 0, 0 ) );
QCOMPARE( points1[points1.count()-1], QgsPoint( 10, 10 ) );

delete vl;
}


QTEST_MAIN( TestQgsTracer )
#include "testqgstracer.moc"

0 comments on commit bf07d2b

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