Skip to content

Commit

Permalink
Road graph plugin: don't crash with 25D input layers
Browse files Browse the repository at this point in the history
Fix #9174
  • Loading branch information
m-kuhn committed Dec 9, 2013
1 parent c610f37 commit 758f5e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Expand Up @@ -166,9 +166,11 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
while ( fit.nextFeature( feature ) )
{
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString
|| feature.geometry()->wkbType() == QGis::WKBMultiLineString25D )
mpl = feature.geometry()->asMultiPolyline();
else if ( feature.geometry()->wkbType() == QGis::WKBLineString )
else if ( feature.geometry()->wkbType() == QGis::WKBLineString
|| feature.geometry()->wkbType() == QGis::WKBLineString25D )
mpl.push_back( feature.geometry()->asPolyline() );

QgsMultiPolyline::iterator mplIt;
Expand Down
19 changes: 15 additions & 4 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Expand Up @@ -37,6 +37,7 @@
#include <qgsfeature.h>
#include <qgsapplication.h>
#include <qgsvectorlayer.h>
#include <qgsmessagebar.h>

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

QgsGraph *graph = builder.graph();

QVector< int > pointIdx( 0, 0 );
QVector< double > pointCost( 0, 0.0 );

int startVertexIdx = graph->findVertex( p1 );

int criterionNum = 0;
if ( mCriterionName->currentIndex() > 0 )
criterionNum = 1;

QgsGraph* shortestpathTree = QgsGraphAnalyzer::shortestTree( graph, startVertexIdx, criterionNum );
if ( graph->vertexCount() == 0 )
{
mPlugin->iface()->messageBar()->pushMessage(
tr( "Cannot calculate path" ),
tr( "The graph is empty. Does the layer have a supported geometry type?" ),
QgsMessageBar::WARNING,
mPlugin->iface()->messageTimeout()
);

delete graph;
return NULL;
}


QgsGraph* shortestpathTree = QgsGraphAnalyzer::shortestTree( graph, startVertexIdx, criterionNum );
delete graph;

if ( shortestpathTree->findVertex( p2 ) == -1 )
Expand Down

0 comments on commit 758f5e5

Please sign in to comment.