6#ifndef SWIFT_MISC_GEO_GEOOBJECTLIST_H
7#define SWIFT_MISC_GEO_GEOOBJECTLIST_H
19namespace swift::misc::geo
22 template <
class OBJ,
class CONTAINER>
27 using MinMaxAverageHeight = std::tuple<aviation::CAltitude, aviation::CAltitude, aviation::CAltitude, int>;
36 [&](
const OBJ &geoObj) {
return calculateGreatCircleDistance(geoObj, coordinate) <= range; });
46 [&](
const OBJ &geoObj) {
return calculateGreatCircleDistance(geoObj, coordinate) > range; });
53 return this->
container().findFirstByOrDefault(
54 [&](
const OBJ &geoObj) {
return calculateGreatCircleDistance(geoObj, coordinate) <= range; });
60 return this->
container().findBy(&OBJ::hasMSLGeodeticHeight,
true);
67 return this->
container().containsBy([&](
const OBJ &geoObj) {
77 return this->
container().containsBy([&](
const OBJ &geoObj) {
109 if (!obj.hasMSLGeodeticHeight())
114 if (std::get<0>(stats).isNull() || std::get<0>(stats) > alt)
116 std::get<0>(stats) = alt;
118 if (std::get<1>(stats).isNull() || std::get<1>(stats) < alt)
120 std::get<1>(stats) = alt;
131 std::get<3>(stats) = count;
145 if (!obj.hasMSLGeodeticHeight())
150 if (max.
isNull() || alt > max)
161 const int size = this->
container().size();
162 const CONTAINER copy = this->
container().findOutsideRange(coordinate, range);
163 const int d = size - copy.size();
174 const int size = this->
container().size();
175 const CONTAINER copy = this->
container().findWithinRange(coordinate, range);
176 const int d = size - copy.size();
187 const int size = this->
container().size();
189 const int d = size - copy.size();
200 CONTAINER closest = this->
container().partiallySorted(number, [&](
const OBJ &a,
const OBJ &b) {
201 return calculateEuclideanDistanceSquared(a, coordinate) <
202 calculateEuclideanDistanceSquared(b, coordinate);
204 closest.truncate(number);
211 CONTAINER farthest = this->
container().partiallySorted(number, [&](
const OBJ &a,
const OBJ &b) {
212 return calculateEuclideanDistanceSquared(a, coordinate) >
213 calculateEuclideanDistanceSquared(b, coordinate);
215 farthest.truncate(number);
232 if (distance.
isNull() || distance > d)
244 this->
container().sort([&](
const OBJ &a,
const OBJ &b) {
245 return calculateEuclideanDistanceSquared(a, coordinate) <
246 calculateEuclideanDistanceSquared(b, coordinate);
254 copy.sortByEuclideanDistanceSquared(coordinate);
263 const CONTAINER &
container()
const {
return static_cast<const CONTAINER &
>(*this); }
266 CONTAINER &
container() {
return static_cast<CONTAINER &
>(*this); }
270 template <
class OBJ,
class CONTAINER>
282 [&](
const OBJ &a,
const OBJ &b) {
return a.getRelativeDistance() < b.getRelativeDistance(); });
290 [&](
const OBJ &a,
const OBJ &b) {
return a.getRelativeDistance() < b.getRelativeDistance(); });
297 number, [&](
const OBJ &a,
const OBJ &b) {
return a.getRelativeDistance() < b.getRelativeDistance(); });
312 closest.partiallySortByDistanceToReferencePosition(number);
313 Q_ASSERT_X(closest.size() <= number, Q_FUNC_INFO,
"size exceeded");
321 this->
container().removeIf([&](OBJ &geoObj) {
322 return updateValues ? geoObj.calculcateAndUpdateRelativeDistanceAndBearing(position) > maxDistance :
323 geoObj.calculateGreatCircleDistance(position) > maxDistance;
332 geoObj.calculcateAndUpdateRelativeDistanceAndBearing(position);
Altitude as used in aviation, can be AGL or MSL altitude.
static const CAltitude & null()
Null altitude (MSL).
Geodetic coordinate, a position in 3D space relative to the reference geoid.
physical_quantities::CLength calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const
Great circle distance.
virtual bool isNull() const
Is null, means vector x, y, z == 0.
bool isGeodeticHeightNull() const
Geodetic height null?
CONTAINER findOutsideRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Find 0..n objects outside range of given coordinate.
bool containsNullPosition() const
Any NULL position?
CONTAINER sortedByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate) const
Sorted by distance.
void sortByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate)
Sort by distance.
int removeWithoutGeodeticHeight()
Remove if there is no geodetic height.
OBJ findFirstWithinRangeOrDefault(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Find first in range.
IGeoObjectList()
Constructor.
bool containsObjectInRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Any object in range?
CONTAINER & container()
Container.
CONTAINER findWithinRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Find 0..n objects within range of given coordinate.
OBJ findClosestWithinRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Find closest within range to the given coordinate.
bool containsObjectOutsideRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Any object in range?
const CONTAINER & container() const
Container.
int removeInsideRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range)
Remove inside range.
int removeOutsideRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range)
Remove outside range.
bool containsNullPositionOrHeight() const
Any NULL position or NULL height.
aviation::CAltitude findMaxHeight() const
Find min/max/average height.
MinMaxAverageHeight findMinMaxAverageHeight() const
Find min/max/average height.
CONTAINER findWithGeodeticMSLHeight() const
Elements with geodetic height (only MSL).
CONTAINER findClosest(int number, const ICoordinateGeodetic &coordinate) const
Find 0..n objects closest to the given coordinate.
CONTAINER findFarthest(int number, const ICoordinateGeodetic &coordinate) const
Find 0..n objects farthest to the given coordinate.
std::tuple< aviation::CAltitude, aviation::CAltitude, aviation::CAltitude, int > MinMaxAverageHeight
For statistics.
void calculcateAndUpdateRelativeDistanceAndBearing(const ICoordinateGeodetic &position)
Calculate distances.
void partiallySortByDistanceToReferencePosition(int number)
Sort the first n closest objects.
void sortByRange(const ICoordinateGeodetic &position, bool updateValues)
Calculate distances, then sort by range.
void sortByDistanceToReferencePosition()
If distance is already set, just sort container.
CONTAINER getClosestObjects(int number) const
Get n closest objects.
void removeIfOutsideRange(const ICoordinateGeodetic &position, const physical_quantities::CLength &maxDistance, bool updateValues)
Calculate distances, remove if outside range.
IGeoObjectWithRelativePositionList()
Constructor.
Physical unit length (length).
static CLengthUnit ft()
Foot ft.
bool isNull() const
Is quantity null?
double value(MU unit) const
Value in given unit.
static const CLength & null()