Skip to content
Snippets Groups Projects
Commit e8c85777 authored by Lorenz Gruber's avatar Lorenz Gruber
Browse files

adding distance functions for different coordinate systems

parent d0863b45
Branches
No related tags found
No related merge requests found
......@@ -5,18 +5,44 @@
/**
* @brief Distance BiPredicate Functor.
* Emits true if the distance between the two shapes is less or equal to the maximum distance.
* Uses WGS84Ellipsoid distance between the two closest points of the two shapes
* Emits true if the distance between the two shapes is less or equal to the maximum distance (in meters).
* @tparam DistanceFunction type determining how to calculate the distance between two points in meters.
*/
template<fishnet::util::BiFunction<fishnet::geometry::Vec2DReal,fishnet::geometry::Vec2DReal, fishnet::math::DEFAULT_FLOATING_POINT> DistanceFunction>
struct DistanceBiPredicate{
DistanceFunction distanceFunction;
double maxDistanceInMeters;
bool operator()(fishnet::geometry::Shape auto const & lhs, fishnet::geometry::Shape auto const & rhs) const noexcept {
auto [l,r] = fishnet::geometry::closestPoints(lhs,rhs);
return l == r || fishnet::WGS84Ellipsoid::distance(l,r) <= maxDistanceInMeters;
}
return l == r || distanceFunction(l,r) <= maxDistanceInMeters;
}
static NeighbouringPredicateType type() {
return NeighbouringPredicateType::DistanceBiPredicate;
}
};
\ No newline at end of file
};
struct WGS84Distance{
static auto operator()(const fishnet::geometry::Vec2DReal & lhs, const fishnet::geometry::Vec2DReal & rhs) noexcept {
return fishnet::WGS84Ellipsoid::distance(lhs,rhs);
}
};
struct MetricDistance{
static auto operator()(const fishnet::geometry::Vec2DReal & lhs, const fishnet::geometry::Vec2DReal & rhs) noexcept {
return lhs.distance(rhs);
}
};
using DistanceFunction = std::function<fishnet::math::DEFAULT_FLOATING_POINT(const fishnet::geometry::Vec2DReal &, const fishnet::geometry::Vec2DReal &)>;
static DistanceFunction distanceFunctionForSpatialReference(const OGRSpatialReference & spatialRef) {
if(spatialRef.IsEmpty())
throw std::runtime_error("No distance function available for empty coordinate system");
if(spatialRef.IsLocal() || spatialRef.IsProjected())
return MetricDistance();
if(spatialRef.IsGeographic())
return WGS84Distance();
throw std::runtime_error("No distance function found for coordinate system: \""+std::string(spatialRef.GetName())+"\"");
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment