diff --git a/src/blackmisc/geo/geoobjectlist.cpp b/src/blackmisc/geo/geoobjectlist.cpp index ceae36ecc..2daf8365b 100644 --- a/src/blackmisc/geo/geoobjectlist.cpp +++ b/src/blackmisc/geo/geoobjectlist.cpp @@ -52,6 +52,15 @@ namespace BlackMisc }); } + template + CONTAINER IGeoObjectList::findOutsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const + { + return this->container().findBy([&](const OBJ & geoObj) + { + return calculateGreatCircleDistance(geoObj, coordinate) > range; + }); + } + template OBJ IGeoObjectList::findFirstWithinRangeOrDefault(const ICoordinateGeodetic &coordinate, const CLength &range) const { @@ -147,6 +156,16 @@ namespace BlackMisc return max; } + template + int IGeoObjectList::removeInsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) + { + const int size = this->container().size(); + const CONTAINER copy = this->container().findOutsideRange(coordinate, range); + const int d = size - copy.size(); + if (d > 0) { *this = copy; } + return d; + } + template int IGeoObjectList::removeOutsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) { diff --git a/src/blackmisc/geo/geoobjectlist.h b/src/blackmisc/geo/geoobjectlist.h index 5cbab4024..2bb78c1ea 100644 --- a/src/blackmisc/geo/geoobjectlist.h +++ b/src/blackmisc/geo/geoobjectlist.h @@ -62,6 +62,11 @@ namespace BlackMisc //! \param range within range of other position CONTAINER findWithinRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const; + //! Find 0..n objects outside range of given coordinate + //! \param coordinate other position + //! \param range outside range of other position + CONTAINER findOutsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const; + //! Find first in range OBJ findFirstWithinRangeOrDefault(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const; @@ -86,6 +91,9 @@ namespace BlackMisc //! Find min/max/average height Aviation::CAltitude findMaxHeight() const; + //! Remove inside range + int removeInsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range); + //! Remove outside range int removeOutsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range);