MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / calcAveragePosition

Method calcAveragePosition

src/core/track.cpp:274–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274LatLon Track::calcAveragePosition() const
275{
276 double avg_latitude = 0;
277 double avg_longitude = 0;
278 int num_samples = 0;
279
280 int size = getNumWaypoints();
281 for (int i = 0; i < size; ++i)
282 {
283 const TrackPoint& point = getWaypoint(i);
284 avg_latitude += point.latlon.latitude();
285 avg_longitude += point.latlon.longitude();
286 ++num_samples;
287 }
288 for (int i = 0; i < getNumSegments(); ++i)
289 {
290 size = getSegmentPointCount(i);
291 for (int k = 0; k < size; ++k)
292 {
293 const TrackPoint& point = getSegmentPoint(i, k);
294 avg_latitude += point.latlon.latitude();
295 avg_longitude += point.latlon.longitude();
296 ++num_samples;
297 }
298 }
299
300 return LatLon((num_samples > 0) ? (avg_latitude / num_samples) : 0,
301 (num_samples > 0) ? (avg_longitude / num_samples) : 0);
302}
303
304bool Track::loadGpxFrom(QIODevice& device, bool project_points)
305{

Callers 2

postLoadSetupMethod · 0.80

Calls 3

latitudeMethod · 0.80
longitudeMethod · 0.80
LatLonClass · 0.70

Tested by

no test coverage detected