Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support also curved geometries for tracing (fixes #15109)
  • Loading branch information
wonder-sk committed Jun 30, 2016
1 parent 5f66276 commit bf07d2b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/core/qgstracer.cpp
Expand Up @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions tests/src/core/testqgstracer.cpp
Expand Up @@ -34,6 +34,7 @@ class TestQgsTracer : public QObject
void testLayerUpdates();
void testExtent();
void testReprojection();
void testCurved();

private:

Expand Down Expand Up @@ -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

Collaborator

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.