Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Jun 10, 2011
2 parents d967b71 + efb462b commit 8ecf02e
Showing 1 changed file with 89 additions and 67 deletions.
156 changes: 89 additions & 67 deletions src/plugins/roadgraph/linevectorlayerdirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,41 +103,53 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
QgsFeature feature;
while ( vl->nextFeature( feature ) )
{
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline pl = feature.geometry()->asPolyline();
QgsPolyline::iterator pointIt;
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBLineString )
{
pt2 = builder->addVertex( ct.transform( *pointIt ) );
if ( !isFirstPoint )
mpl.push_back( feature.geometry()->asPolyline() );
}else if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
{
mpl = feature.geometry()->asMultiPolyline();
}

QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline::iterator pointIt;
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
pt2 = builder->addVertex( ct.transform( *pointIt ) );
if ( !isFirstPoint )
{
TiePointInfo info;
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
}
if ( pointLengthMap[ i ].mLength > info.mLength )
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;
TiePointInfo info;
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
}
if ( pointLengthMap[ i ].mLength > info.mLength )
{
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;

pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
}
}
}
pt1 = pt2;
isFirstPoint = false;
}
pt1 = pt2;
isFirstPoint = false;
}
emit buildProgress( ++step, featureCount );
}
Expand Down Expand Up @@ -198,57 +210,67 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
}

// begin features segments and add arc to the Graph;
QgsPoint pt1, pt2;

bool isFirstPoint = true;
QgsPolyline pl = feature.geometry()->asPolyline();
QgsPolyline::iterator pointIt;
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBLineString )
{
mpl.push_back( feature.geometry()->asPolyline() );
}else if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
{
mpl = feature.geometry()->asMultiPolyline();
}
QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
pt2 = builder->addVertex( ct.transform( *pointIt ) );
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline::iterator pointIt;
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
pt2 = builder->addVertex( ct.transform( *pointIt ) );

std::map< double, QgsPoint > pointsOnArc;
pointsOnArc[ 0.0 ] = pt1;
pointsOnArc[ pt1.sqrDist( pt2 )] = pt2;
std::map< double, QgsPoint > pointsOnArc;
pointsOnArc[ 0.0 ] = pt1;
pointsOnArc[ pt1.sqrDist( pt2 )] = pt2;

for ( pointLengthIt = pointLengthMap.begin(); pointLengthIt != pointLengthMap.end(); ++pointLengthIt )
{
if ( pointLengthIt->mFirstPoint == pt1 && pointLengthIt->mLastPoint == pt2 )
for ( pointLengthIt = pointLengthMap.begin(); pointLengthIt != pointLengthMap.end(); ++pointLengthIt )
{
QgsPoint tiedPoint = pointLengthIt->mTiedPoint;
pointsOnArc[ pt1.sqrDist( tiedPoint )] = tiedPoint;
if ( pointLengthIt->mFirstPoint == pt1 && pointLengthIt->mLastPoint == pt2 )
{
QgsPoint tiedPoint = pointLengthIt->mTiedPoint;
pointsOnArc[ pt1.sqrDist( tiedPoint )] = tiedPoint;
}
}
}

if ( !isFirstPoint )
{
std::map< double, QgsPoint >::iterator pointsIt;
QgsPoint pt1;
QgsPoint pt2;
bool isFirstPoint = true;
for ( pointsIt = pointsOnArc.begin(); pointsIt != pointsOnArc.end(); ++pointsIt )
if ( !isFirstPoint )
{
pt2 = pointsIt->second;
if ( !isFirstPoint )
std::map< double, QgsPoint >::iterator pointsIt;
QgsPoint pt1;
QgsPoint pt2;
bool isFirstPoint = true;
for ( pointsIt = pointsOnArc.begin(); pointsIt != pointsOnArc.end(); ++pointsIt )
{
double cost = da.measureLine( pt1, pt2 );
if ( directionType == 1 ||
directionType == 3 )
pt2 = pointsIt->second;
if ( !isFirstPoint )
{
builder->addArc( pt1, pt2, cost, speed*su.multipler(), feature.id() );
}
if ( directionType == 2 ||
directionType == 3 )
{
builder->addArc( pt2, pt1, cost, speed*su.multipler(), feature.id() );
double cost = da.measureLine( pt1, pt2 );
if ( directionType == 1 ||
directionType == 3 )
{
builder->addArc( pt1, pt2, cost, speed*su.multipler(), feature.id() );
}
if ( directionType == 2 ||
directionType == 3 )
{
builder->addArc( pt2, pt1, cost, speed*su.multipler(), feature.id() );
}
}
pt1 = pt2;
isFirstPoint = false;
}
pt1 = pt2;
isFirstPoint = false;
}
} // if ( !isFirstPoint )
pt1 = pt2;
isFirstPoint = false;
} // if ( !isFirstPoint )
pt1 = pt2;
isFirstPoint = false;
}
} // for (it = pl.begin(); it != pl.end(); ++it)
emit buildProgress( ++step, featureCount );
} // while( vl->nextFeature(feature) )
Expand Down

0 comments on commit 8ecf02e

Please sign in to comment.