@@ -125,6 +125,7 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature)
125
125
126
126
QgsAttributeList::const_iterator iter;
127
127
128
+ QgsDebugMsg (" *** GPX ***" );
128
129
if (mFeatureType == WaypointType)
129
130
{
130
131
// go through the list of waypoints and return the first one that is in
@@ -269,10 +270,19 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature)
269
270
const Track* trk;
270
271
trk = &(*mTrkIter );
271
272
273
+ QgsLogger::debug (" GPX feature track segments: " , trk->segments .size (), __FILE__, __FUNCTION__, __LINE__);
272
274
if (trk->segments .size () == 0 )
273
275
continue ;
274
- if (trk->segments [0 ].points .size () == 0 )
276
+
277
+ // A track consists of several segments. Add all those segments into one.
278
+ int totalPoints = 0 ;;
279
+ for (int i = 0 ; i < trk->segments .size (); i ++)
280
+ {
281
+ totalPoints += trk->segments [i].points .size ();
282
+ }
283
+ if (totalPoints == 0 )
275
284
continue ;
285
+ QgsDebugMsg (" GPX feature track total points: " + QString::number (totalPoints));
276
286
const QgsRect& b (*mSelectionRectangle );
277
287
if ((trk->xMax >= b.xMin ()) && (trk->xMin <= b.xMax ()) &&
278
288
(trk->yMax >= b.yMin ()) && (trk->yMin <= b.yMax ())) {
@@ -282,18 +292,29 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature)
282
292
// some wkb voodoo
283
293
if (mFetchGeom )
284
294
{
285
- int nPoints = trk->segments [0 ].points .size ();
286
- char * geo = new char [9 + 16 * nPoints];
287
- std::memset (geo, 0 , 9 + 16 * nPoints);
295
+ char * geo = new char [9 + 16 * totalPoints];
296
+ if (!geo)
297
+ {
298
+ QgsDebugMsg (" Too large track!!!" );
299
+ return false ;
300
+ }
301
+ std::memset (geo, 0 , 9 + 16 * totalPoints);
288
302
geo[0 ] = QgsApplication::endian ();
289
303
geo[geo[0 ] == QgsApplication::NDR ? 1 : 4 ] = QGis::WKBLineString;
290
- std::memcpy (geo + 5 , &nPoints, 4 );
291
- for (int i = 0 ; i < nPoints; ++i)
304
+ std::memcpy (geo + 5 , &totalPoints, 4 );
305
+
306
+ int thisPoint = 0 ;
307
+ for (int k = 0 ; k < trk->segments .size (); k++)
308
+ {
309
+ int nPoints = trk->segments [k].points .size ();
310
+ for (int i = 0 ; i < nPoints; ++i)
292
311
{
293
- std::memcpy (geo + 9 + 16 * i, &trk->segments [0 ].points [i].lon , sizeof (double ));
294
- std::memcpy (geo + 9 + 16 * i + 8 , &trk->segments [0 ].points [i].lat , sizeof (double ));
312
+ std::memcpy (geo + 9 + 16 * thisPoint, &trk->segments [k].points [i].lon , sizeof (double ));
313
+ std::memcpy (geo + 9 + 16 * thisPoint + 8 , &trk->segments [k].points [i].lat , sizeof (double ));
314
+ thisPoint++;
295
315
}
296
- feature.setGeometryAndOwnership ((unsigned char *)geo, 9 + 16 * nPoints);
316
+ }
317
+ feature.setGeometryAndOwnership ((unsigned char *)geo, 9 + 16 * totalPoints);
297
318
}
298
319
feature.setValid (true );
299
320
0 commit comments