Skip to content

Commit 8ecf02e

Browse files
committedJun 10, 2011
Merge branch 'master' of github.com:qgis/Quantum-GIS
2 parents d967b71 + efb462b commit 8ecf02e

File tree

1 file changed

+89
-67
lines changed

1 file changed

+89
-67
lines changed
 

‎src/plugins/roadgraph/linevectorlayerdirector.cpp

Lines changed: 89 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -103,41 +103,53 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
103103
QgsFeature feature;
104104
while ( vl->nextFeature( feature ) )
105105
{
106-
QgsPoint pt1, pt2;
107-
bool isFirstPoint = true;
108-
QgsPolyline pl = feature.geometry()->asPolyline();
109-
QgsPolyline::iterator pointIt;
110-
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
106+
QgsMultiPolyline mpl;
107+
if ( feature.geometry()->wkbType() == QGis::WKBLineString )
111108
{
112-
pt2 = builder->addVertex( ct.transform( *pointIt ) );
113-
if ( !isFirstPoint )
109+
mpl.push_back( feature.geometry()->asPolyline() );
110+
}else if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
111+
{
112+
mpl = feature.geometry()->asMultiPolyline();
113+
}
114+
115+
QgsMultiPolyline::iterator mplIt;
116+
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
117+
{
118+
QgsPoint pt1, pt2;
119+
bool isFirstPoint = true;
120+
QgsPolyline::iterator pointIt;
121+
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
114122
{
115-
int i = 0;
116-
for ( i = 0; i != additionalPoints.size(); ++i )
123+
pt2 = builder->addVertex( ct.transform( *pointIt ) );
124+
if ( !isFirstPoint )
117125
{
118-
TiePointInfo info;
119-
if ( pt1 == pt2 )
120-
{
121-
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
122-
info.mTiedPoint = pt1;
123-
}
124-
else
125-
{
126-
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
127-
}
128-
if ( pointLengthMap[ i ].mLength > info.mLength )
126+
int i = 0;
127+
for ( i = 0; i != additionalPoints.size(); ++i )
129128
{
130-
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
131-
info.mFirstPoint = pt1;
132-
info.mLastPoint = pt2;
129+
TiePointInfo info;
130+
if ( pt1 == pt2 )
131+
{
132+
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
133+
info.mTiedPoint = pt1;
134+
}
135+
else
136+
{
137+
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
138+
}
139+
if ( pointLengthMap[ i ].mLength > info.mLength )
140+
{
141+
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
142+
info.mFirstPoint = pt1;
143+
info.mLastPoint = pt2;
133144

134-
pointLengthMap[ i ] = info;
135-
tiedPoint[ i ] = info.mTiedPoint;
145+
pointLengthMap[ i ] = info;
146+
tiedPoint[ i ] = info.mTiedPoint;
147+
}
136148
}
137149
}
150+
pt1 = pt2;
151+
isFirstPoint = false;
138152
}
139-
pt1 = pt2;
140-
isFirstPoint = false;
141153
}
142154
emit buildProgress( ++step, featureCount );
143155
}
@@ -198,57 +210,67 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
198210
}
199211

200212
// begin features segments and add arc to the Graph;
201-
QgsPoint pt1, pt2;
202-
203-
bool isFirstPoint = true;
204-
QgsPolyline pl = feature.geometry()->asPolyline();
205-
QgsPolyline::iterator pointIt;
206-
for ( pointIt = pl.begin(); pointIt != pl.end(); ++pointIt )
213+
QgsMultiPolyline mpl;
214+
if ( feature.geometry()->wkbType() == QGis::WKBLineString )
215+
{
216+
mpl.push_back( feature.geometry()->asPolyline() );
217+
}else if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
218+
{
219+
mpl = feature.geometry()->asMultiPolyline();
220+
}
221+
QgsMultiPolyline::iterator mplIt;
222+
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
207223
{
208-
pt2 = builder->addVertex( ct.transform( *pointIt ) );
224+
QgsPoint pt1, pt2;
225+
bool isFirstPoint = true;
226+
QgsPolyline::iterator pointIt;
227+
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
228+
{
229+
pt2 = builder->addVertex( ct.transform( *pointIt ) );
209230

210-
std::map< double, QgsPoint > pointsOnArc;
211-
pointsOnArc[ 0.0 ] = pt1;
212-
pointsOnArc[ pt1.sqrDist( pt2 )] = pt2;
231+
std::map< double, QgsPoint > pointsOnArc;
232+
pointsOnArc[ 0.0 ] = pt1;
233+
pointsOnArc[ pt1.sqrDist( pt2 )] = pt2;
213234

214-
for ( pointLengthIt = pointLengthMap.begin(); pointLengthIt != pointLengthMap.end(); ++pointLengthIt )
215-
{
216-
if ( pointLengthIt->mFirstPoint == pt1 && pointLengthIt->mLastPoint == pt2 )
235+
for ( pointLengthIt = pointLengthMap.begin(); pointLengthIt != pointLengthMap.end(); ++pointLengthIt )
217236
{
218-
QgsPoint tiedPoint = pointLengthIt->mTiedPoint;
219-
pointsOnArc[ pt1.sqrDist( tiedPoint )] = tiedPoint;
237+
if ( pointLengthIt->mFirstPoint == pt1 && pointLengthIt->mLastPoint == pt2 )
238+
{
239+
QgsPoint tiedPoint = pointLengthIt->mTiedPoint;
240+
pointsOnArc[ pt1.sqrDist( tiedPoint )] = tiedPoint;
241+
}
220242
}
221-
}
222243

223-
if ( !isFirstPoint )
224-
{
225-
std::map< double, QgsPoint >::iterator pointsIt;
226-
QgsPoint pt1;
227-
QgsPoint pt2;
228-
bool isFirstPoint = true;
229-
for ( pointsIt = pointsOnArc.begin(); pointsIt != pointsOnArc.end(); ++pointsIt )
244+
if ( !isFirstPoint )
230245
{
231-
pt2 = pointsIt->second;
232-
if ( !isFirstPoint )
246+
std::map< double, QgsPoint >::iterator pointsIt;
247+
QgsPoint pt1;
248+
QgsPoint pt2;
249+
bool isFirstPoint = true;
250+
for ( pointsIt = pointsOnArc.begin(); pointsIt != pointsOnArc.end(); ++pointsIt )
233251
{
234-
double cost = da.measureLine( pt1, pt2 );
235-
if ( directionType == 1 ||
236-
directionType == 3 )
252+
pt2 = pointsIt->second;
253+
if ( !isFirstPoint )
237254
{
238-
builder->addArc( pt1, pt2, cost, speed*su.multipler(), feature.id() );
239-
}
240-
if ( directionType == 2 ||
241-
directionType == 3 )
242-
{
243-
builder->addArc( pt2, pt1, cost, speed*su.multipler(), feature.id() );
255+
double cost = da.measureLine( pt1, pt2 );
256+
if ( directionType == 1 ||
257+
directionType == 3 )
258+
{
259+
builder->addArc( pt1, pt2, cost, speed*su.multipler(), feature.id() );
260+
}
261+
if ( directionType == 2 ||
262+
directionType == 3 )
263+
{
264+
builder->addArc( pt2, pt1, cost, speed*su.multipler(), feature.id() );
265+
}
244266
}
267+
pt1 = pt2;
268+
isFirstPoint = false;
245269
}
246-
pt1 = pt2;
247-
isFirstPoint = false;
248-
}
249-
} // if ( !isFirstPoint )
250-
pt1 = pt2;
251-
isFirstPoint = false;
270+
} // if ( !isFirstPoint )
271+
pt1 = pt2;
272+
isFirstPoint = false;
273+
}
252274
} // for (it = pl.begin(); it != pl.end(); ++it)
253275
emit buildProgress( ++step, featureCount );
254276
} // while( vl->nextFeature(feature) )

0 commit comments

Comments
 (0)
Please sign in to comment.