2015-12-03 14:04:23 -05:00
|
|
|
#ifndef GEOSPATIAL_QUERY_HPP
|
|
|
|
#define GEOSPATIAL_QUERY_HPP
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/coordinate_calculation.hpp"
|
|
|
|
#include "util/typedefs.hpp"
|
|
|
|
#include "engine/phantom_node.hpp"
|
|
|
|
#include "util/bearing.hpp"
|
2016-02-16 13:51:04 -05:00
|
|
|
#include "util/rectangle.hpp"
|
2015-12-03 14:04:23 -05:00
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "osrm/coordinate.hpp"
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
#include <algorithm>
|
2016-01-07 05:35:35 -05:00
|
|
|
#include <cmath>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2015-12-03 14:04:23 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
// Implements complex queries on top of an RTree and builds PhantomNodes from it.
|
|
|
|
//
|
|
|
|
// Only holds a weak reference on the RTree!
|
2016-01-29 20:52:20 -05:00
|
|
|
template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
|
|
|
using EdgeData = typename RTreeT::EdgeData;
|
|
|
|
using CoordinateList = typename RTreeT::CoordinateList;
|
2016-03-28 14:38:19 -04:00
|
|
|
using CandidateSegment = typename RTreeT::CandidateSegment;
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
public:
|
2016-03-03 08:26:13 -05:00
|
|
|
GeospatialQuery(RTreeT &rtree_,
|
|
|
|
std::shared_ptr<CoordinateList> coordinates_,
|
|
|
|
DataFacadeT &datafacade_)
|
2016-01-29 20:52:20 -05:00
|
|
|
: rtree(rtree_), coordinates(std::move(coordinates_)), datafacade(datafacade_)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-26 06:29:57 -05:00
|
|
|
std::vector<EdgeData> Search(const util::RectangleInt2D &bbox)
|
2016-02-16 13:51:04 -05:00
|
|
|
{
|
|
|
|
return rtree.SearchInBox(bbox);
|
|
|
|
}
|
|
|
|
|
2016-02-20 22:27:26 -05:00
|
|
|
// Returns nearest PhantomNodes in the given bearing range within max_distance.
|
|
|
|
// Does not filter by small/big component!
|
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const double max_distance)
|
2016-02-20 22:27:26 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results =
|
|
|
|
rtree.Nearest(input_coordinate,
|
|
|
|
[](const CandidateSegment &)
|
|
|
|
{
|
|
|
|
return std::make_pair(true, true);
|
|
|
|
},
|
|
|
|
[this, max_distance, input_coordinate](const std::size_t,
|
|
|
|
const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return checkSegmentDistance(input_coordinate, segment, max_distance);
|
|
|
|
});
|
2016-02-20 22:27:26 -05:00
|
|
|
|
|
|
|
return MakePhantomNodes(input_coordinate, results);
|
|
|
|
}
|
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
// Returns nearest PhantomNodes in the given bearing range within max_distance.
|
|
|
|
// Does not filter by small/big component!
|
2015-12-09 16:34:22 -05:00
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
|
2015-12-26 14:12:10 -05:00
|
|
|
const double max_distance,
|
2016-02-20 22:27:26 -05:00
|
|
|
const int bearing,
|
|
|
|
const int bearing_range)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results = rtree.Nearest(
|
|
|
|
input_coordinate,
|
|
|
|
[this, bearing, bearing_range, max_distance](const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return checkSegmentBearing(segment, bearing, bearing_range);
|
|
|
|
},
|
|
|
|
[this, max_distance, input_coordinate](const std::size_t,
|
|
|
|
const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return checkSegmentDistance(input_coordinate, segment, max_distance);
|
|
|
|
});
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
return MakePhantomNodes(input_coordinate, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns max_results nearest PhantomNodes in the given bearing range.
|
|
|
|
// Does not filter by small/big component!
|
2015-12-09 16:34:22 -05:00
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
NearestPhantomNodes(const util::Coordinate input_coordinate,
|
2015-12-03 14:04:23 -05:00
|
|
|
const unsigned max_results,
|
2016-02-22 18:44:35 -05:00
|
|
|
const int bearing,
|
|
|
|
const int bearing_range)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results =
|
|
|
|
rtree.Nearest(input_coordinate,
|
|
|
|
[this, bearing, bearing_range](const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return checkSegmentBearing(segment, bearing, bearing_range);
|
|
|
|
},
|
|
|
|
[max_results](const std::size_t num_results, const CandidateSegment &)
|
|
|
|
{
|
|
|
|
return num_results >= max_results;
|
|
|
|
});
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
return MakePhantomNodes(input_coordinate, results);
|
|
|
|
}
|
|
|
|
|
2016-02-23 15:23:13 -05:00
|
|
|
// Returns max_results nearest PhantomNodes in the given bearing range within the maximum
|
|
|
|
// distance.
|
2016-02-22 18:44:35 -05:00
|
|
|
// Does not filter by small/big component!
|
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
NearestPhantomNodes(const util::Coordinate input_coordinate,
|
2016-02-22 18:44:35 -05:00
|
|
|
const unsigned max_results,
|
|
|
|
const double max_distance,
|
|
|
|
const int bearing,
|
|
|
|
const int bearing_range)
|
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results =
|
|
|
|
rtree.Nearest(input_coordinate,
|
|
|
|
[this, bearing, bearing_range](const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return checkSegmentBearing(segment, bearing, bearing_range);
|
|
|
|
},
|
|
|
|
[this, max_distance, max_results, input_coordinate](
|
|
|
|
const std::size_t num_results, const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return num_results >= max_results ||
|
|
|
|
checkSegmentDistance(input_coordinate, segment, max_distance);
|
|
|
|
});
|
2016-02-22 18:44:35 -05:00
|
|
|
|
|
|
|
return MakePhantomNodes(input_coordinate, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns max_results nearest PhantomNodes.
|
|
|
|
// Does not filter by small/big component!
|
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
NearestPhantomNodes(const util::Coordinate input_coordinate, const unsigned max_results)
|
2016-02-22 18:44:35 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results =
|
|
|
|
rtree.Nearest(input_coordinate,
|
|
|
|
[](const CandidateSegment &)
|
|
|
|
{
|
|
|
|
return std::make_pair(true, true);
|
|
|
|
},
|
|
|
|
[max_results](const std::size_t num_results, const CandidateSegment &)
|
|
|
|
{
|
|
|
|
return num_results >= max_results;
|
|
|
|
});
|
2016-02-22 18:44:35 -05:00
|
|
|
|
|
|
|
return MakePhantomNodes(input_coordinate, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns max_results nearest PhantomNodes in the given max distance.
|
|
|
|
// Does not filter by small/big component!
|
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
NearestPhantomNodes(const util::Coordinate input_coordinate,
|
2016-02-22 18:44:35 -05:00
|
|
|
const unsigned max_results,
|
|
|
|
const double max_distance)
|
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results =
|
|
|
|
rtree.Nearest(input_coordinate,
|
|
|
|
[](const CandidateSegment &)
|
|
|
|
{
|
|
|
|
return std::make_pair(true, true);
|
|
|
|
},
|
|
|
|
[this, max_distance, max_results, input_coordinate](
|
|
|
|
const std::size_t num_results, const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
return num_results >= max_results ||
|
|
|
|
checkSegmentDistance(input_coordinate, segment, max_distance);
|
|
|
|
});
|
2016-02-22 18:44:35 -05:00
|
|
|
|
|
|
|
return MakePhantomNodes(input_coordinate, results);
|
|
|
|
}
|
|
|
|
|
2016-01-28 10:28:44 -05:00
|
|
|
// Returns the nearest phantom node. If this phantom node is not from a big component
|
|
|
|
// a second phantom node is return that is the nearest coordinate in a big component.
|
2016-02-23 15:23:13 -05:00
|
|
|
std::pair<PhantomNode, PhantomNode>
|
|
|
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
|
|
|
const double max_distance)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
|
|
|
bool has_small_component = false;
|
|
|
|
bool has_big_component = false;
|
|
|
|
auto results = rtree.Nearest(
|
|
|
|
input_coordinate,
|
2016-03-28 14:38:19 -04:00
|
|
|
[&has_big_component, &has_small_component](const CandidateSegment &segment)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto use_segment = (!has_small_component ||
|
|
|
|
(!has_big_component && !segment.data.component.is_tiny));
|
2016-01-28 10:28:44 -05:00
|
|
|
auto use_directions = std::make_pair(use_segment, use_segment);
|
|
|
|
|
2016-03-28 14:38:19 -04:00
|
|
|
has_big_component = has_big_component || !segment.data.component.is_tiny;
|
|
|
|
has_small_component = has_small_component || segment.data.component.is_tiny;
|
2016-01-28 10:28:44 -05:00
|
|
|
|
|
|
|
return use_directions;
|
|
|
|
},
|
2016-03-28 14:38:19 -04:00
|
|
|
[this, &has_big_component, max_distance,
|
|
|
|
input_coordinate](const std::size_t num_results, const CandidateSegment &segment)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
return (num_results > 0 && has_big_component) ||
|
|
|
|
checkSegmentDistance(input_coordinate, segment, max_distance);
|
2016-01-28 10:28:44 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (results.size() == 0)
|
|
|
|
{
|
|
|
|
return std::make_pair(PhantomNode{}, PhantomNode{});
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_ASSERT(results.size() == 1 || results.size() == 2);
|
|
|
|
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
|
|
|
|
MakePhantomNode(input_coordinate, results.back()).phantom_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the nearest phantom node. If this phantom node is not from a big component
|
|
|
|
// a second phantom node is return that is the nearest coordinate in a big component.
|
2016-02-23 15:23:13 -05:00
|
|
|
std::pair<PhantomNode, PhantomNode>
|
|
|
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
|
|
|
bool has_small_component = false;
|
|
|
|
bool has_big_component = false;
|
2016-03-28 14:38:19 -04:00
|
|
|
auto results = rtree.Nearest(
|
|
|
|
input_coordinate,
|
|
|
|
[&has_big_component, &has_small_component](const CandidateSegment &segment)
|
|
|
|
{
|
|
|
|
auto use_segment = (!has_small_component ||
|
|
|
|
(!has_big_component && !segment.data.component.is_tiny));
|
|
|
|
auto use_directions = std::make_pair(use_segment, use_segment);
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-03-28 14:38:19 -04:00
|
|
|
has_big_component = has_big_component || !segment.data.component.is_tiny;
|
|
|
|
has_small_component = has_small_component || segment.data.component.is_tiny;
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-03-28 14:38:19 -04:00
|
|
|
return use_directions;
|
|
|
|
},
|
|
|
|
[&has_big_component](const std::size_t num_results, const CandidateSegment &)
|
|
|
|
{
|
|
|
|
return num_results > 0 && has_big_component;
|
|
|
|
});
|
2016-01-28 10:28:44 -05:00
|
|
|
|
|
|
|
if (results.size() == 0)
|
|
|
|
{
|
|
|
|
return std::make_pair(PhantomNode{}, PhantomNode{});
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_ASSERT(results.size() == 1 || results.size() == 2);
|
|
|
|
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
|
|
|
|
MakePhantomNode(input_coordinate, results.back()).phantom_node);
|
|
|
|
}
|
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
// Returns the nearest phantom node. If this phantom node is not from a big component
|
|
|
|
// a second phantom node is return that is the nearest coordinate in a big component.
|
2016-01-07 19:31:57 -05:00
|
|
|
std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent(
|
2016-02-23 15:23:13 -05:00
|
|
|
const util::Coordinate input_coordinate, const int bearing, const int bearing_range)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
|
|
|
bool has_small_component = false;
|
|
|
|
bool has_big_component = false;
|
|
|
|
auto results = rtree.Nearest(
|
|
|
|
input_coordinate,
|
2016-03-28 11:06:51 -04:00
|
|
|
[this, bearing, bearing_range, &has_big_component,
|
2016-03-28 14:38:19 -04:00
|
|
|
&has_small_component](const CandidateSegment &segment)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto use_segment = (!has_small_component ||
|
|
|
|
(!has_big_component && !segment.data.component.is_tiny));
|
2015-12-03 14:04:23 -05:00
|
|
|
auto use_directions = std::make_pair(use_segment, use_segment);
|
|
|
|
|
|
|
|
if (use_segment)
|
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
use_directions = checkSegmentBearing(segment, bearing, bearing_range);
|
2015-12-03 14:04:23 -05:00
|
|
|
if (use_directions.first || use_directions.second)
|
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
has_big_component = has_big_component || !segment.data.component.is_tiny;
|
|
|
|
has_small_component = has_small_component || segment.data.component.is_tiny;
|
2015-12-03 14:04:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return use_directions;
|
|
|
|
},
|
2016-03-28 14:38:19 -04:00
|
|
|
[&has_big_component](const std::size_t num_results, const CandidateSegment &)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
|
|
|
return num_results > 0 && has_big_component;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (results.size() == 0)
|
|
|
|
{
|
2015-12-09 16:34:22 -05:00
|
|
|
return std::make_pair(PhantomNode{}, PhantomNode{});
|
2015-12-03 14:04:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_ASSERT(results.size() > 0);
|
2015-12-09 16:34:22 -05:00
|
|
|
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
|
|
|
|
MakePhantomNode(input_coordinate, results.back()).phantom_node);
|
2015-12-03 14:04:23 -05:00
|
|
|
}
|
|
|
|
|
2016-01-28 10:28:44 -05:00
|
|
|
// Returns the nearest phantom node. If this phantom node is not from a big component
|
|
|
|
// a second phantom node is return that is the nearest coordinate in a big component.
|
2016-02-23 15:23:13 -05:00
|
|
|
std::pair<PhantomNode, PhantomNode>
|
|
|
|
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
|
|
|
|
const double max_distance,
|
|
|
|
const int bearing,
|
|
|
|
const int bearing_range)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
|
|
|
bool has_small_component = false;
|
|
|
|
bool has_big_component = false;
|
|
|
|
auto results = rtree.Nearest(
|
|
|
|
input_coordinate,
|
2016-03-28 11:06:51 -04:00
|
|
|
[this, bearing, bearing_range, &has_big_component,
|
2016-03-28 14:38:19 -04:00
|
|
|
&has_small_component](const CandidateSegment &segment)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
auto use_segment = (!has_small_component ||
|
|
|
|
(!has_big_component && !segment.data.component.is_tiny));
|
2016-01-28 10:28:44 -05:00
|
|
|
auto use_directions = std::make_pair(use_segment, use_segment);
|
|
|
|
|
|
|
|
if (use_segment)
|
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
use_directions = checkSegmentBearing(segment, bearing, bearing_range);
|
2016-01-28 10:28:44 -05:00
|
|
|
if (use_directions.first || use_directions.second)
|
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
has_big_component = has_big_component || !segment.data.component.is_tiny;
|
|
|
|
has_small_component = has_small_component || segment.data.component.is_tiny;
|
2016-01-28 10:28:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return use_directions;
|
|
|
|
},
|
2016-03-28 14:38:19 -04:00
|
|
|
[this, &has_big_component, max_distance,
|
|
|
|
input_coordinate](const std::size_t num_results, const CandidateSegment &segment)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
return (num_results > 0 && has_big_component) ||
|
|
|
|
checkSegmentDistance(input_coordinate, segment, max_distance);
|
2016-01-28 10:28:44 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (results.size() == 0)
|
|
|
|
{
|
|
|
|
return std::make_pair(PhantomNode{}, PhantomNode{});
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_ASSERT(results.size() > 0);
|
|
|
|
return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node,
|
|
|
|
MakePhantomNode(input_coordinate, results.back()).phantom_node);
|
|
|
|
}
|
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
private:
|
2015-12-09 16:34:22 -05:00
|
|
|
std::vector<PhantomNodeWithDistance>
|
2016-02-23 15:23:13 -05:00
|
|
|
MakePhantomNodes(const util::Coordinate input_coordinate,
|
2015-12-03 14:04:23 -05:00
|
|
|
const std::vector<EdgeData> &results) const
|
|
|
|
{
|
2015-12-09 16:34:22 -05:00
|
|
|
std::vector<PhantomNodeWithDistance> distance_and_phantoms(results.size());
|
2015-12-03 14:04:23 -05:00
|
|
|
std::transform(results.begin(), results.end(), distance_and_phantoms.begin(),
|
|
|
|
[this, &input_coordinate](const EdgeData &data)
|
|
|
|
{
|
|
|
|
return MakePhantomNode(input_coordinate, data);
|
|
|
|
});
|
|
|
|
return distance_and_phantoms;
|
|
|
|
}
|
|
|
|
|
2016-02-23 15:23:13 -05:00
|
|
|
PhantomNodeWithDistance MakePhantomNode(const util::Coordinate input_coordinate,
|
2016-01-05 06:04:04 -05:00
|
|
|
const EdgeData &data) const
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
2016-02-23 15:23:13 -05:00
|
|
|
util::Coordinate point_on_segment;
|
2015-12-26 14:12:10 -05:00
|
|
|
double ratio;
|
2016-01-07 19:31:57 -05:00
|
|
|
const auto current_perpendicular_distance =
|
|
|
|
util::coordinate_calculation::perpendicularDistance(
|
|
|
|
coordinates->at(data.u), coordinates->at(data.v), input_coordinate,
|
|
|
|
point_on_segment, ratio);
|
2015-12-03 14:04:23 -05:00
|
|
|
|
2016-01-29 20:52:20 -05:00
|
|
|
// Find the node-based-edge that this belongs to, and directly
|
|
|
|
// calculate the forward_weight, forward_offset, reverse_weight, reverse_offset
|
2015-12-03 14:04:23 -05:00
|
|
|
|
2016-01-29 20:52:20 -05:00
|
|
|
int forward_offset = 0, forward_weight = 0;
|
|
|
|
int reverse_offset = 0, reverse_weight = 0;
|
2015-12-03 14:04:23 -05:00
|
|
|
|
2016-03-03 08:26:13 -05:00
|
|
|
if (data.forward_packed_geometry_id != SPECIAL_EDGEID)
|
|
|
|
{
|
2016-01-29 20:52:20 -05:00
|
|
|
std::vector<EdgeWeight> forward_weight_vector;
|
|
|
|
datafacade.GetUncompressedWeights(data.forward_packed_geometry_id,
|
2016-03-03 08:26:13 -05:00
|
|
|
forward_weight_vector);
|
2016-01-29 20:52:20 -05:00
|
|
|
for (std::size_t i = 0; i < data.fwd_segment_position; i++)
|
|
|
|
{
|
|
|
|
forward_offset += forward_weight_vector[i];
|
|
|
|
}
|
|
|
|
forward_weight = forward_weight_vector[data.fwd_segment_position];
|
2015-12-03 14:04:23 -05:00
|
|
|
}
|
2016-01-29 20:52:20 -05:00
|
|
|
|
2016-03-03 08:26:13 -05:00
|
|
|
if (data.reverse_packed_geometry_id != SPECIAL_EDGEID)
|
|
|
|
{
|
2016-01-29 20:52:20 -05:00
|
|
|
std::vector<EdgeWeight> reverse_weight_vector;
|
|
|
|
datafacade.GetUncompressedWeights(data.reverse_packed_geometry_id,
|
|
|
|
reverse_weight_vector);
|
|
|
|
|
|
|
|
BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size());
|
|
|
|
|
2016-03-03 08:26:13 -05:00
|
|
|
for (std::size_t i = 0;
|
|
|
|
i < reverse_weight_vector.size() - data.fwd_segment_position - 1; i++)
|
2016-01-29 20:52:20 -05:00
|
|
|
{
|
|
|
|
reverse_offset += reverse_weight_vector[i];
|
|
|
|
}
|
2016-03-03 08:26:13 -05:00
|
|
|
reverse_weight =
|
|
|
|
reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1];
|
2016-01-29 20:52:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ratio = std::min(1.0, std::max(0.0, ratio));
|
2016-03-28 11:06:51 -04:00
|
|
|
if (data.forward_segment_id.id != SPECIAL_SEGMENTID)
|
2016-03-03 08:26:13 -05:00
|
|
|
{
|
2016-01-29 20:52:20 -05:00
|
|
|
forward_weight *= ratio;
|
2015-12-03 14:04:23 -05:00
|
|
|
}
|
2016-03-28 11:06:51 -04:00
|
|
|
if (data.reverse_segment_id.id != SPECIAL_SEGMENTID)
|
2016-03-03 08:26:13 -05:00
|
|
|
{
|
2016-01-29 20:52:20 -05:00
|
|
|
reverse_weight *= 1.0 - ratio;
|
|
|
|
}
|
|
|
|
|
2016-03-28 11:06:51 -04:00
|
|
|
auto transformed = PhantomNodeWithDistance{PhantomNode{data, forward_weight, forward_offset,
|
|
|
|
reverse_weight, reverse_offset,
|
|
|
|
point_on_segment, input_coordinate},
|
2016-03-08 10:46:01 -05:00
|
|
|
current_perpendicular_distance};
|
2016-01-29 20:52:20 -05:00
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
return transformed;
|
|
|
|
}
|
|
|
|
|
2016-03-28 14:38:19 -04:00
|
|
|
bool checkSegmentDistance(const Coordinate input_coordinate,
|
|
|
|
const CandidateSegment &segment,
|
|
|
|
const double max_distance)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(segment.data.forward_segment_id.id != SPECIAL_SEGMENTID ||
|
|
|
|
!segment.data.forward_segment_id.enabled);
|
|
|
|
BOOST_ASSERT(segment.data.reverse_segment_id.id != SPECIAL_SEGMENTID ||
|
|
|
|
!segment.data.reverse_segment_id.enabled);
|
|
|
|
|
|
|
|
Coordinate wsg84_coordinate = util::coordinate_calculation::mercator::toWGS84(
|
|
|
|
segment.fixed_projected_coordinate);
|
|
|
|
|
|
|
|
return util::coordinate_calculation::haversineDistance(input_coordinate, wsg84_coordinate) > max_distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<bool, bool> checkSegmentBearing(const CandidateSegment &segment,
|
2015-12-26 14:12:10 -05:00
|
|
|
const int filter_bearing,
|
|
|
|
const int filter_bearing_range)
|
2015-12-03 14:04:23 -05:00
|
|
|
{
|
2016-03-28 14:38:19 -04:00
|
|
|
BOOST_ASSERT(segment.data.forward_segment_id.id != SPECIAL_SEGMENTID ||
|
|
|
|
!segment.data.forward_segment_id.enabled);
|
|
|
|
BOOST_ASSERT(segment.data.reverse_segment_id.id != SPECIAL_SEGMENTID ||
|
|
|
|
!segment.data.reverse_segment_id.enabled);
|
2016-03-28 11:06:51 -04:00
|
|
|
|
2016-01-07 19:31:57 -05:00
|
|
|
const double forward_edge_bearing = util::coordinate_calculation::bearing(
|
2016-03-28 14:38:19 -04:00
|
|
|
coordinates->at(segment.data.u), coordinates->at(segment.data.v));
|
2015-12-03 14:04:23 -05:00
|
|
|
|
2015-12-26 14:12:10 -05:00
|
|
|
const double backward_edge_bearing = (forward_edge_bearing + 180) > 360
|
2016-01-05 06:04:04 -05:00
|
|
|
? (forward_edge_bearing - 180)
|
|
|
|
: (forward_edge_bearing + 180);
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
const bool forward_bearing_valid =
|
2016-01-05 10:51:13 -05:00
|
|
|
util::bearing::CheckInBounds(std::round(forward_edge_bearing), filter_bearing,
|
2016-01-07 19:31:57 -05:00
|
|
|
filter_bearing_range) &&
|
2016-03-28 14:38:19 -04:00
|
|
|
segment.data.forward_segment_id.enabled;
|
2015-12-03 14:04:23 -05:00
|
|
|
const bool backward_bearing_valid =
|
2016-01-05 10:51:13 -05:00
|
|
|
util::bearing::CheckInBounds(std::round(backward_edge_bearing), filter_bearing,
|
2016-01-07 19:31:57 -05:00
|
|
|
filter_bearing_range) &&
|
2016-03-28 14:38:19 -04:00
|
|
|
segment.data.reverse_segment_id.enabled;
|
2015-12-03 14:04:23 -05:00
|
|
|
return std::make_pair(forward_bearing_valid, backward_bearing_valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
RTreeT &rtree;
|
|
|
|
const std::shared_ptr<CoordinateList> coordinates;
|
2016-01-29 20:52:20 -05:00
|
|
|
DataFacadeT &datafacade;
|
2015-12-03 14:04:23 -05:00
|
|
|
};
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 14:04:23 -05:00
|
|
|
#endif
|