Skip to content

Commit b8305a7

Browse files
committed
fix network-analysis API and export function in RoadGraph plugin (fix #4341)
1 parent a0e39e6 commit b8305a7

File tree

4 files changed

+38
-45
lines changed

4 files changed

+38
-45
lines changed

src/analysis/network/qgsgraph.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,6 @@ int QgsGraphArc::outVertex() const
107107
return mOut;
108108
}
109109

110-
int QgsGraphArc::in() const
111-
{
112-
return mIn;
113-
}
114-
115-
int QgsGraphArc::out() const
116-
{
117-
return mOut;
118-
}
119-
120110
QgsGraphVertex::QgsGraphVertex( const QgsPoint& point )
121111
: mCoordinate( point )
122112
{

src/analysis/network/qgsgraph.h

-2
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ class ANALYSIS_EXPORT QgsGraphArc
6060
/**
6161
* return index of outgoing vertex
6262
*/
63-
int out() const;
6463
int outVertex() const;
6564

6665
/**
6766
* return index of incoming vertex
6867
*/
69-
int in() const;
7068
int inVertex() const;
7169

7270
private:

src/analysis/network/qgsgraphanalyzer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
6363
const QgsGraphArc& arc = source->arc( *arcIt );
6464
double cost = arc.property( criterionNum ).toDouble() + curCost;
6565

66-
if ( cost < result[ arc.in()].first )
66+
if ( cost < result[ arc.inVertex() ].first )
6767
{
68-
result[ arc.in()] = QPair< double, int >( cost, *arcIt );
69-
not_begin.insert( cost, arc.in() );
68+
result[ arc.inVertex() ] = QPair< double, int >( cost, *arcIt );
69+
not_begin.insert( cost, arc.inVertex() );
7070
}
7171
}
7272
}
@@ -90,7 +90,7 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
9090
{
9191
const QgsGraphArc& arc = source->arc( result[i].second );
9292

93-
treeResult->addArc( source2result[ arc.out()], source2result[ i ],
93+
treeResult->addArc( source2result[ arc.outVertex() ], source2result[ i ],
9494
arc.properties() );
9595
}
9696
}

src/plugins/roadgraph/shortestpathwidget.cpp

+34-29
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ void RgShortestPathWidget::findingPath()
324324
cost += e.property( 0 ).toDouble();
325325
time += e.property( 1 ).toDouble();
326326

327-
p.push_front( path.vertex( e.in() ).point() );
327+
p.push_front( path.vertex( e.inVertex() ).point() );
328328

329-
stopVertexIdx = e.out();
329+
stopVertexIdx = e.outVertex();
330330
}
331331
p.push_front( p1 );
332332
QList< QgsPoint>::iterator it;
@@ -357,39 +357,44 @@ void RgShortestPathWidget::clear()
357357

358358
void RgShortestPathWidget::exportPath()
359359
{
360-
/* RgExportDlg dlg( this );
361-
if ( !dlg.exec() )
362-
return;
360+
RgExportDlg dlg( this );
361+
if ( !dlg.exec() )
362+
return;
363363

364-
QgsPoint p1, p2;
365-
QgsGraph path;
366-
if ( !getPath( path, p1, p2 ) )
367-
return;
364+
QgsPoint p1, p2;
365+
QgsGraph path;
366+
if ( !getPath( &path, p1, p2 ) )
367+
return;
368368

369-
QgsVectorLayer *vl = dlg.mapLayer();
370-
if ( vl == NULL )
371-
return;
369+
QgsVectorLayer *vl = dlg.mapLayer();
370+
if ( vl == NULL )
371+
return;
372372

373-
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
373+
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
374374
vl->crs() );
375+
376+
int startVertexIdx = path.findVertex( p1 );
377+
int stopVertexIdx = path.findVertex( p2 );
378+
379+
QgsPolyline p;
380+
while ( startVertexIdx != stopVertexIdx )
381+
{
382+
QgsGraphArcIdList l = path.vertex( stopVertexIdx ).inArc();
383+
if ( l.empty() )
384+
break;
385+
const QgsGraphArc& e = path.arc( l.front() );
386+
p.push_front( path.vertex( e.inVertex() ).point() );
387+
stopVertexIdx = e.outVertex();
388+
}
389+
p.push_front( p1 );
375390

376-
while ( it != path.end() )
377-
{
378-
AdjacencyMatrixString::iterator it2 = it->second.begin();
379-
if ( it2 == it->second.end() )
380-
break;
381-
points.append( ct.transform( it2->first ) );
382-
it = path.find( it2->first );
383-
}
384-
385-
vl->startEditing();
386-
QgsFeature f;
387-
f.setGeometry( QgsGeometry::fromPolyline( points ) );
388-
vl->addFeature( f );
389-
vl->updateExtents();
391+
vl->startEditing();
392+
QgsFeature f;
393+
f.setGeometry( QgsGeometry::fromPolyline( p ) );
394+
vl->addFeature( f );
395+
vl->updateExtents();
390396

391-
mPlugin->iface()->mapCanvas()->update();
392-
*/
397+
mPlugin->iface()->mapCanvas()->update();
393398
}
394399

395400
void RgShortestPathWidget::helpRequested()

0 commit comments

Comments
 (0)