@@ -103,41 +103,53 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
103
103
QgsFeature feature;
104
104
while ( vl->nextFeature ( feature ) )
105
105
{
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 )
111
108
{
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 )
114
122
{
115
- int i = 0 ;
116
- for ( i = 0 ; i != additionalPoints. size (); ++i )
123
+ pt2 = builder-> addVertex ( ct. transform ( *pointIt ) ) ;
124
+ if ( !isFirstPoint )
117
125
{
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 )
129
128
{
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;
133
144
134
- pointLengthMap[ i ] = info;
135
- tiedPoint[ i ] = info.mTiedPoint ;
145
+ pointLengthMap[ i ] = info;
146
+ tiedPoint[ i ] = info.mTiedPoint ;
147
+ }
136
148
}
137
149
}
150
+ pt1 = pt2;
151
+ isFirstPoint = false ;
138
152
}
139
- pt1 = pt2;
140
- isFirstPoint = false ;
141
153
}
142
154
emit buildProgress ( ++step, featureCount );
143
155
}
@@ -198,57 +210,67 @@ void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVecto
198
210
}
199
211
200
212
// 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 )
207
223
{
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 ) );
209
230
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;
213
234
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 )
217
236
{
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
+ }
220
242
}
221
- }
222
243
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 )
230
245
{
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 )
233
251
{
234
- double cost = da.measureLine ( pt1, pt2 );
235
- if ( directionType == 1 ||
236
- directionType == 3 )
252
+ pt2 = pointsIt->second ;
253
+ if ( !isFirstPoint )
237
254
{
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
+ }
244
266
}
267
+ pt1 = pt2;
268
+ isFirstPoint = false ;
245
269
}
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
+ }
252
274
} // for (it = pl.begin(); it != pl.end(); ++it)
253
275
emit buildProgress ( ++step, featureCount );
254
276
} // while( vl->nextFeature(feature) )
0 commit comments