Skip to content

Commit 7b40c2b

Browse files
author
homann
committedDec 9, 2007
Merged all track segments into one line. Possibly, a MultiLine should be used instead. Fixes bug #696
git-svn-id: http://svn.osgeo.org/qgis/trunk@7752 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 072e2ee commit 7b40c2b

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed
 

‎src/providers/gpx/qgsgpxprovider.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature)
125125

126126
QgsAttributeList::const_iterator iter;
127127

128+
QgsDebugMsg("*** GPX ***");
128129
if (mFeatureType == WaypointType)
129130
{
130131
// go through the list of waypoints and return the first one that is in
@@ -269,10 +270,19 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature)
269270
const Track* trk;
270271
trk = &(*mTrkIter);
271272

273+
QgsLogger::debug("GPX feature track segments: ", trk->segments.size(), __FILE__, __FUNCTION__, __LINE__);
272274
if (trk->segments.size() == 0)
273275
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)
275284
continue;
285+
QgsDebugMsg("GPX feature track total points: " + QString::number(totalPoints));
276286
const QgsRect& b(*mSelectionRectangle);
277287
if ((trk->xMax >= b.xMin()) && (trk->xMin <= b.xMax()) &&
278288
(trk->yMax >= b.yMin()) && (trk->yMin <= b.yMax())) {
@@ -282,18 +292,29 @@ bool QgsGPXProvider::getNextFeature(QgsFeature& feature)
282292
// some wkb voodoo
283293
if(mFetchGeom)
284294
{
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);
288302
geo[0] = QgsApplication::endian();
289303
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)
292311
{
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++;
295315
}
296-
feature.setGeometryAndOwnership((unsigned char *)geo, 9 + 16 * nPoints);
316+
}
317+
feature.setGeometryAndOwnership((unsigned char *)geo, 9 + 16 * totalPoints);
297318
}
298319
feature.setValid(true);
299320

0 commit comments

Comments
 (0)
Please sign in to comment.