Skip to content

Commit 758f5e5

Browse files
committed
Road graph plugin: don't crash with 25D input layers
Fix #9174
1 parent c610f37 commit 758f5e5

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/analysis/network/qgslinevectorlayerdirector.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
166166
while ( fit.nextFeature( feature ) )
167167
{
168168
QgsMultiPolyline mpl;
169-
if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
169+
if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString
170+
|| feature.geometry()->wkbType() == QGis::WKBMultiLineString25D )
170171
mpl = feature.geometry()->asMultiPolyline();
171-
else if ( feature.geometry()->wkbType() == QGis::WKBLineString )
172+
else if ( feature.geometry()->wkbType() == QGis::WKBLineString
173+
|| feature.geometry()->wkbType() == QGis::WKBLineString25D )
172174
mpl.push_back( feature.geometry()->asPolyline() );
173175

174176
QgsMultiPolyline::iterator mplIt;

src/plugins/roadgraph/shortestpathwidget.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <qgsfeature.h>
3838
#include <qgsapplication.h>
3939
#include <qgsvectorlayer.h>
40+
#include <qgsmessagebar.h>
4041

4142
#include <qgsgraphdirector.h>
4243
#include <qgsgraphbuilder.h>
@@ -278,17 +279,27 @@ QgsGraph* RgShortestPathWidget::getPath( QgsPoint& p1, QgsPoint& p2 )
278279

279280
QgsGraph *graph = builder.graph();
280281

281-
QVector< int > pointIdx( 0, 0 );
282-
QVector< double > pointCost( 0, 0.0 );
283-
284282
int startVertexIdx = graph->findVertex( p1 );
285283

286284
int criterionNum = 0;
287285
if ( mCriterionName->currentIndex() > 0 )
288286
criterionNum = 1;
289287

290-
QgsGraph* shortestpathTree = QgsGraphAnalyzer::shortestTree( graph, startVertexIdx, criterionNum );
288+
if ( graph->vertexCount() == 0 )
289+
{
290+
mPlugin->iface()->messageBar()->pushMessage(
291+
tr( "Cannot calculate path" ),
292+
tr( "The graph is empty. Does the layer have a supported geometry type?" ),
293+
QgsMessageBar::WARNING,
294+
mPlugin->iface()->messageTimeout()
295+
);
296+
297+
delete graph;
298+
return NULL;
299+
}
300+
291301

302+
QgsGraph* shortestpathTree = QgsGraphAnalyzer::shortestTree( graph, startVertexIdx, criterionNum );
292303
delete graph;
293304

294305
if ( shortestpathTree->findVertex( p2 ) == -1 )

0 commit comments

Comments
 (0)