Skip to content
Permalink
Browse files

fix network-analysis API and export function in RoadGraph plugin (fix #…

  • Loading branch information
alexbruy committed Oct 2, 2011
1 parent a0e39e6 commit b8305a7b951513fd93908306fbaa435d7a45d2d4
@@ -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 )
{
@@ -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:
@@ -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() );
}
}
}
@@ -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() );
}
}
@@ -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;
@@ -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()

0 comments on commit b8305a7

Please sign in to comment.
You can’t perform that action at this time.