Fast map matching  0.1.0
network.hpp
1 
10 #ifndef FMM_NETWORK_HPP
11 #define FMM_NETWORK_HPP
12 
13 #include "network/type.hpp"
14 #include "core/gps.hpp"
15 #include "mm/mm_type.hpp"
16 #include <ogrsf_frmts.h> // C++ API for GDAL
17 #include <iostream>
18 #include <math.h> // Calulating probability
19 #include <iomanip>
20 #include <algorithm> // Partial sort copy
21 #include <unordered_set> // Partial sort copy
22 
23 // Data structures for Rtree
24 #include <boost/geometry/geometries/box.hpp>
25 #include <boost/geometry/index/rtree.hpp>
26 #include <boost/function_output_iterator.hpp>
27 
28 namespace FMM {
32 namespace NETWORK {
36 class Network {
37  public:
41  typedef boost::geometry::model::box<FMM::CORE::Point> boost_box;
45  typedef std::pair<boost_box, Edge *> Item;
49  typedef boost::geometry::index::rtree<
50  Item, boost::geometry::index::quadratic<16> > Rtree;
60  Network(const std::string &filename,
61  const std::string &id_name = "id",
62  const std::string &source_name = "source",
63  const std::string &target_name = "target"); // Network constructor
68  int get_node_count() const;
73  int get_edge_count() const;
78  const std::vector<Edge> &get_edges() const;
84  EdgeID get_edge_id(EdgeIndex index) const;
96  NodeID get_node_id(NodeIndex index) const;
102  NodeIndex get_node_index(NodeID id) const;
109 
122  FMM::CORE::Trajectory &trajectory, std::size_t k, double radius) const;
123 
135  std::size_t k,
136  double radius) const;
142  const FMM::CORE::LineString &get_edge_geom(EdgeID edge_id) const;
150  const FMM::CORE::LineString &traj,
151  const MM::C_Path &complete_path) const;
156  const std::vector<FMM::CORE::Point> &get_vertex_points() const;
168  FMM::CORE::LineString route2geometry(const std::vector<EdgeID> &path) const;
175  const std::vector<EdgeIndex> &path) const;
182  static bool candidate_compare(const MM::Candidate &a, const MM::Candidate &b);
183  private:
192  static void append_segs_to_line(FMM::CORE::LineString *line,
193  const FMM::CORE::LineString &segs,
194  int offset = 0);
198  void build_rtree_index();
199  int srid; // Spatial reference id
200  Rtree rtree; // Network rtree structure
201  std::vector<Edge> edges; // all edges in the network
202  NodeIDVec node_id_vec;
203  unsigned int num_vertices;
204  NodeIndexMap node_map;
205  EdgeIndexMap edge_map;
206  std::vector<FMM::CORE::Point> vertex_points;
207 }; // Network
208 } // NETWORK
209 } // FMM
210 #endif /* FMM_NETWORK_HPP */
FMM::NETWORK::Network::get_node_count
int get_node_count() const
Get number of nodes in the network.
Definition: network.cpp:137
FMM::MM::Traj_Candidates
std::vector< Point_Candidates > Traj_Candidates
trajectory candidates
Definition: mm_type.hpp:38
FMM::NETWORK::Network::get_edges
const std::vector< Edge > & get_edges() const
Get edges in the network.
Definition: network.cpp:146
FMM::NETWORK::Network::complete_path_to_geometry
FMM::CORE::LineString complete_path_to_geometry(const FMM::CORE::LineString &traj, const MM::C_Path &complete_path) const
Extract the geometry of a complete path, whose two end segment will be clipped according to the input...
Definition: network.cpp:259
FMM::NETWORK::Network::get_vertex_point
const FMM::CORE::Point & get_vertex_point(NodeIndex u) const
Get node geometry.
Definition: network.cpp:307
FMM::NETWORK::NodeIDVec
std::vector< NodeID > NodeIDVec
Vector of node id.
Definition: type.hpp:32
FMM::NETWORK::Network::boost_box
boost::geometry::model::box< FMM::CORE::Point > boost_box
Box of a edge.
Definition: network.hpp:41
FMM::NETWORK::Network::get_vertex_points
const std::vector< FMM::CORE::Point > & get_vertex_points() const
Get all node geometry.
Definition: network.cpp:303
FMM::NETWORK::Network::get_node_id
NodeID get_node_id(NodeIndex index) const
Get node ID from index.
Definition: network.cpp:161
FMM::MM::C_Path
std::vector< FMM::NETWORK::EdgeID > C_Path
Complete path, ids of a sequence of topologically connected edges.
Definition: mm_type.hpp:47
FMM::NETWORK::Network::Item
std::pair< boost_box, Edge * > Item
Item stored in a node of Rtree.
Definition: network.hpp:45
FMM
Fast map matching.
Definition: geom_algorithm.hpp:17
FMM::NETWORK::Network::get_edge_geom
const FMM::CORE::LineString & get_edge_geom(EdgeID edge_id) const
Get edge geometry.
Definition: network.cpp:255
FMM::NETWORK::Network::get_edge_count
int get_edge_count() const
Get number of edges in the network.
Definition: network.cpp:141
FMM::CORE::Trajectory
Trajectory class
Definition: gps.hpp:26
FMM::NETWORK::Network::search_tr_cs_knn
FMM::MM::Traj_Candidates search_tr_cs_knn(FMM::CORE::Trajectory &trajectory, std::size_t k, double radius) const
Search for k nearest neighboring (KNN) candidates of a trajectory within a search radius.
Definition: network.cpp:189
FMM::NETWORK::Network::get_node_index
NodeIndex get_node_index(NodeID id) const
Get node index from id.
Definition: network.cpp:165
FMM::NETWORK::Network
Road network class.
Definition: network.hpp:36
FMM::NETWORK::Network::get_edge_id
EdgeID get_edge_id(EdgeIndex index) const
Get edge ID from index.
Definition: network.cpp:152
FMM::NETWORK::EdgeID
int EdgeID
Edge ID in the network, can be discontinuous int.
Definition: type.hpp:23
FMM::MM::Candidate
Candidate edge matched to a GPS point
Definition: mm_type.hpp:26
FMM::NETWORK::Network::get_node_geom_from_idx
FMM::CORE::Point get_node_geom_from_idx(NodeIndex index) const
Get node geometry from index.
Definition: network.cpp:169
FMM::CORE::LineString
Linestring geometry class.
Definition: geometry.hpp:34
FMM::NETWORK::Network::get_edge_index
EdgeIndex get_edge_index(EdgeID id) const
Get edge index from ID.
Definition: network.cpp:157
FMM::NETWORK::Network::candidate_compare
static bool candidate_compare(const MM::Candidate &a, const MM::Candidate &b)
Compare two candidate according to their GPS error.
Definition: network.cpp:20
FMM::NETWORK::NodeID
int NodeID
Node ID in the network, can be discontinuous int.
Definition: type.hpp:22
FMM::NETWORK::Network::Network
Network(const std::string &filename, const std::string &id_name="id", const std::string &source_name="source", const std::string &target_name="target")
Constructor of Network.
Definition: network.cpp:32
FMM::NETWORK::NodeIndex
unsigned int NodeIndex
Node Index in the network, range from [0,num_vertices-1 ].
Definition: type.hpp:24
FMM::NETWORK::EdgeIndexMap
std::unordered_map< EdgeID, EdgeIndex > EdgeIndexMap
Map of edge index.
Definition: type.hpp:40
FMM::NETWORK::EdgeIndex
unsigned int EdgeIndex
Edge Index in the network, range from [0,num_edges-1 ].
Definition: type.hpp:26
FMM::CORE::Point
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Point class.
Definition: geometry.hpp:28
FMM::NETWORK::NodeIndexMap
std::unordered_map< NodeID, NodeIndex > NodeIndexMap
Map of node index.
Definition: type.hpp:36
FMM::NETWORK::Network::route2geometry
FMM::CORE::LineString route2geometry(const std::vector< EdgeID > &path) const
Extract the geometry of a route in the network.
Definition: network.cpp:311
FMM::NETWORK::Network::Rtree
boost::geometry::index::rtree< Item, boost::geometry::index::quadratic< 16 > > Rtree
Rtree of road edges.
Definition: network.hpp:50