swift
coordinategeodeticlist.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "misc/math/mathutils.h"
7 
8 using namespace swift::misc::math;
9 using namespace swift::misc::physical_quantities;
10 
11 SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc::geo, CCoordinateGeodetic, CCoordinateGeodeticList)
12 
13 namespace swift::misc::geo
14 {
15  CCoordinateGeodeticList::CCoordinateGeodeticList() {}
16 
17  CCoordinateGeodeticList::CCoordinateGeodeticList(const CSequence<CCoordinateGeodetic> &other)
19  {}
20 
22  const CLength &range, const CLength &maxDeviation,
23  int minValues, int sufficentValues) const
24  {
25  if (this->size() < minValues) { return CElevationPlane::null(); } // no chance to succeed
26 
27  QList<double> valuesInFt;
29  .findWithinRange(reference, range)
31  if (sorted.size() < minValues) { return CElevationPlane::null(); }
32 
33  // we know all values have MSL and are within range
34  for (const CCoordinateGeodetic &coordinate : sorted)
35  {
36  const double elvFt = coordinate.geodeticHeight().value(CLengthUnit::ft());
37  valuesInFt.push_back(elvFt);
38  if (valuesInFt.size() >= sufficentValues) { break; }
39  }
40 
41  if (valuesInFt.size() < minValues) { return CElevationPlane::null(); }
42 
43  const double MaxDevFt = maxDeviation.value(CLengthUnit::ft());
44  const QPair<double, double> elvStdDevMean = CMathUtils::standardDeviationAndMean(valuesInFt);
45  if (elvStdDevMean.first > MaxDevFt) { return CElevationPlane::null(); }
46  return CElevationPlane(reference, elvStdDevMean.second, CElevationPlane::singlePointRadius());
47  }
48 
49 } // namespace swift::misc::geo
size_type size() const
Returns number of elements in the sequence.
Definition: sequence.h:273
CCoordinateGeodetic & reference
STL compatibility.
Definition: sequence.h:95
Q_REQUIRED_RESULT CSequence sorted(Predicate p) const
Return a copy sorted by a given comparator predicate.
Definition: sequence.h:583
Value object encapsulating a list of coordinates.
CElevationPlane averageGeodeticHeight(const CCoordinateGeodetic &reference, const physical_quantities::CLength &range, const physical_quantities::CLength &maxDeviation=physical_quantities::CLength(1.0, physical_quantities::CLengthUnit::m()), int minValues=3, int sufficentValues=5) const
Average height within range and having an height.
Plane of same elevation, can be a single point or larger area (e.g. airport)
static const physical_quantities::CLength & singlePointRadius()
Radius for single point.
static const CElevationPlane & null()
NULL plane.
CONTAINER sortedByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate) const
Sorted by distance.
CONTAINER findWithinRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Find 0..n objects within range of given coordinate.
Definition: geoobjectlist.h:32
CCoordinateGeodeticList findWithGeodeticMSLHeight() const
Elements with geodetic height (only MSL)
Definition: geoobjectlist.h:58
Physical unit length (length)
Definition: length.h:18
double value(MU unit) const
Value in given unit.
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition: sequence.h:63