@@ -9,13 +9,21 @@ using namespace std;
99extern bool verbose;
1010
1111typedef std::pair<double ,double > xy_pair;
12+ namespace std {
13+ template <>
14+ struct hash <xy_pair> {
15+ size_t operator ()(const xy_pair &xy) const {
16+ return std::hash<double >()(xy.first ) ^ std::hash<double >()(xy.second );
17+ }
18+ };
19+ }
1220
1321// Connect disconnected linestrings within a MultiLinestring
1422void ReorderMultiLinestring (MultiLinestring &input, MultiLinestring &output) {
1523 // create a map of the start/end points of each linestring
1624 // (we should be able to do std::map<Point,unsigned>, but that errors)
17- std::map <xy_pair,unsigned > startPoints;
18- std::map <xy_pair,unsigned > endPoints;
25+ std::unordered_map <xy_pair,unsigned > startPoints;
26+ std::unordered_map <xy_pair,unsigned > endPoints;
1927 for (unsigned i=0 ; i<input.size (); i++) {
2028 startPoints[xy_pair (input[i][0 ].x (),input[i][0 ].y ())] = i;
2129 endPoints[xy_pair (input[i][input[i].size ()-1 ].x (),input[i][input[i].size ()-1 ].y ())] = i;
@@ -61,11 +69,10 @@ void ReorderMultiLinestring(MultiLinestring &input, MultiLinestring &output) {
6169 }
6270}
6371
64- // Merge two multilinestrings (just a wrapper around boost::geometry::union_)
72+ // Merge two multilinestrings by simply appending
73+ // (the constituent parts will be matched up in subsequent call to ReorderMultiLinestring)
6574void MergeIntersecting (MultiLinestring &input, MultiLinestring &to_merge) {
66- MultiLinestring output;
67- geom::union_ (input, to_merge, output);
68- input = move (output);
75+ for (auto ls : to_merge) input.emplace_back (ls);
6976}
7077
7178// Merge two multipolygons by doing intersection checks for each constituent polygon
0 commit comments