@@ -41,6 +41,7 @@ class TestQgsNetworkAnalysis : public QObject
41
41
void testBuild ();
42
42
void testBuildTolerance ();
43
43
void dijkkjkjkskkjsktra ();
44
+ void testRouteFail ();
44
45
45
46
private:
46
47
std::unique_ptr< QgsVectorLayer > buildNetwork ();
@@ -462,6 +463,60 @@ void TestQgsNetworkAnalysis::dijkkjkjkskkjsktra()
462
463
QCOMPARE ( graph->edge ( resultTree.at ( point_0_0_idx ) ).toVertex (), point_0_0_idx );
463
464
}
464
465
466
+ void TestQgsNetworkAnalysis::testRouteFail ()
467
+ {
468
+ std::unique_ptr< QgsVectorLayer > network = qgis::make_unique< QgsVectorLayer >( QStringLiteral ( " LineString?crs=epsg:28355&field=cost:int" ), QStringLiteral ( " x" ), QStringLiteral ( " memory" ) );
469
+
470
+ QStringList lines = QStringList () << QStringLiteral ( " LineString (302081.71116495534079149 5753475.15082756895571947, 302140.54234686412382871 5753417.70564490929245949, 302143.24717211339157075 5753412.57312887348234653, 302143.17789465241366997 5753406.77192200440913439, 302140.35127420048229396 5753401.70546196680516005, 302078.46200818457873538 5753338.31098813004791737, 302038.17299743194598705 5753309.50200006738305092)" )
471
+ << QStringLiteral ( " LineString (302081.70763194985920563 5753475.1403581602498889, 301978.24500802176771685 5753368.03299263771623373)" )
472
+ << QStringLiteral ( " LineString (302181.69117977644782513 5753576.27856593858450651, 302081.71834095334634185 5753475.14562766999006271)" );
473
+ QgsFeatureList flist;
474
+ for ( const QString &line : lines )
475
+ {
476
+ QgsFeature ff ( 0 );
477
+ QgsGeometry refGeom = QgsGeometry::fromWkt ( line );
478
+ ff.setGeometry ( refGeom );
479
+ ff.setAttributes ( QgsAttributes () << 1 );
480
+ flist << ff;
481
+ }
482
+ network->dataProvider ()->addFeatures ( flist );
483
+
484
+ // build graph
485
+ std::unique_ptr< QgsVectorLayerDirector > director = qgis::make_unique< QgsVectorLayerDirector > ( network.get (),
486
+ -1 , QString (), QString (), QString (), QgsVectorLayerDirector::DirectionBoth );
487
+ std::unique_ptr< QgsNetworkStrategy > strategy = qgis::make_unique< TestNetworkStrategy >();
488
+ director->addStrategy ( strategy.release () );
489
+ std::unique_ptr< QgsGraphBuilder > builder = qgis::make_unique< QgsGraphBuilder > ( network->sourceCrs (), true , 1 );
490
+
491
+ QgsPointXY start ( 302131.1053754404 , 5753392.757948928 );
492
+ QgsPointXY end ( 302148.1636281528 , 5753541.408436851 );
493
+
494
+ QVector<QgsPointXY > snapped;
495
+ director->makeGraph ( builder.get (), QVector<QgsPointXY>() << start << end, snapped );
496
+ std::unique_ptr< QgsGraph > graph ( builder->graph () );
497
+
498
+ QgsPointXY snappedStart = snapped.at ( 0 );
499
+ QGSCOMPARENEAR ( snappedStart.x (), 302131.3 , 0.1 );
500
+ QGSCOMPARENEAR ( snappedStart.y (), 5753392.5 , 0.1 );
501
+ int startVertexIdx = graph->findVertex ( snappedStart );
502
+ QVERIFY ( startVertexIdx != -1 );
503
+ QgsPointXY snappedEnd = snapped.at ( 1 );
504
+ QGSCOMPARENEAR ( snappedEnd.x (), 302147.68 , 0.1 );
505
+ QGSCOMPARENEAR ( snappedEnd.y (), 5753541.88 , 0.1 );
506
+ int endVertexIdx = graph->findVertex ( snappedEnd );
507
+ QVERIFY ( endVertexIdx != -1 );
508
+
509
+ // both directions
510
+ QVector<int > resultTree;
511
+ QVector<double > resultCost;
512
+ QgsGraphAnalyzer::dijkstra ( graph.get (), startVertexIdx, 0 , &resultTree, &resultCost );
513
+
514
+ QCOMPARE ( resultTree.at ( startVertexIdx ), -1 );
515
+ QCOMPARE ( resultCost.at ( startVertexIdx ), 0.0 );
516
+ QVERIFY ( resultTree.at ( endVertexIdx ) != -1 );
517
+ QCOMPARE ( resultCost.at ( endVertexIdx ), 6.0 );
518
+ }
519
+
465
520
466
521
467
522
QGSTEST_MAIN ( TestQgsNetworkAnalysis )
0 commit comments