Skip to content

Commit

Permalink
fix network-analysis API and export function in RoadGraph plugin (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 2, 2011
1 parent a0e39e6 commit b8305a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
10 changes: 0 additions & 10 deletions src/analysis/network/qgsgraph.cpp
Expand Up @@ -107,16 +107,6 @@ int QgsGraphArc::outVertex() const
return mOut;
}

int QgsGraphArc::in() const
{
return mIn;
}

int QgsGraphArc::out() const
{
return mOut;
}

QgsGraphVertex::QgsGraphVertex( const QgsPoint& point )
: mCoordinate( point )
{
Expand Down
2 changes: 0 additions & 2 deletions src/analysis/network/qgsgraph.h
Expand Up @@ -60,13 +60,11 @@ class ANALYSIS_EXPORT QgsGraphArc
/**
* return index of outgoing vertex
*/
int out() const;
int outVertex() const;

/**
* return index of incoming vertex
*/
int in() const;
int inVertex() const;

private:
Expand Down
8 changes: 4 additions & 4 deletions src/analysis/network/qgsgraphanalyzer.cpp
Expand Up @@ -63,10 +63,10 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
const QgsGraphArc& arc = source->arc( *arcIt );
double cost = arc.property( criterionNum ).toDouble() + curCost;

if ( cost < result[ arc.in()].first )
if ( cost < result[ arc.inVertex() ].first )
{
result[ arc.in()] = QPair< double, int >( cost, *arcIt );
not_begin.insert( cost, arc.in() );
result[ arc.inVertex() ] = QPair< double, int >( cost, *arcIt );
not_begin.insert( cost, arc.inVertex() );
}
}
}
Expand All @@ -90,7 +90,7 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
{
const QgsGraphArc& arc = source->arc( result[i].second );

treeResult->addArc( source2result[ arc.out()], source2result[ i ],
treeResult->addArc( source2result[ arc.outVertex() ], source2result[ i ],
arc.properties() );
}
}
Expand Down
63 changes: 34 additions & 29 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Expand Up @@ -324,9 +324,9 @@ void RgShortestPathWidget::findingPath()
cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();

p.push_front( path.vertex( e.in() ).point() );
p.push_front( path.vertex( e.inVertex() ).point() );

stopVertexIdx = e.out();
stopVertexIdx = e.outVertex();
}
p.push_front( p1 );
QList< QgsPoint>::iterator it;
Expand Down Expand Up @@ -357,39 +357,44 @@ void RgShortestPathWidget::clear()

void RgShortestPathWidget::exportPath()
{
/* RgExportDlg dlg( this );
if ( !dlg.exec() )
return;
RgExportDlg dlg( this );
if ( !dlg.exec() )
return;

QgsPoint p1, p2;
QgsGraph path;
if ( !getPath( path, p1, p2 ) )
return;
QgsPoint p1, p2;
QgsGraph path;
if ( !getPath( &path, p1, p2 ) )
return;

QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;
QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;

QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
vl->crs() );

int startVertexIdx = path.findVertex( p1 );
int stopVertexIdx = path.findVertex( p2 );

QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
QgsGraphArcIdList l = path.vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path.arc( l.front() );
p.push_front( path.vertex( e.inVertex() ).point() );
stopVertexIdx = e.outVertex();
}
p.push_front( p1 );

while ( it != path.end() )
{
AdjacencyMatrixString::iterator it2 = it->second.begin();
if ( it2 == it->second.end() )
break;
points.append( ct.transform( it2->first ) );
it = path.find( it2->first );
}
vl->startEditing();
QgsFeature f;
f.setGeometry( QgsGeometry::fromPolyline( points ) );
vl->addFeature( f );
vl->updateExtents();
vl->startEditing();
QgsFeature f;
f.setGeometry( QgsGeometry::fromPolyline( p ) );
vl->addFeature( f );
vl->updateExtents();

mPlugin->iface()->mapCanvas()->update();
*/
mPlugin->iface()->mapCanvas()->update();
}

void RgShortestPathWidget::helpRequested()
Expand Down

0 comments on commit b8305a7

Please sign in to comment.