MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / makeGeoJSONGeometry

Function makeGeoJSONGeometry

include/engine/api/json_factory.hpp:60–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58
59template <typename ForwardIter>
60util::json::Object makeGeoJSONGeometry(ForwardIter begin, ForwardIter end)
61{
62 auto num_coordinates = std::distance(begin, end);
63 BOOST_ASSERT(num_coordinates != 0);
64 util::json::Object geojson;
65 geojson.values["type"] = "LineString";
66 util::json::Array coordinates;
67 if (num_coordinates > 1)
68 {
69 coordinates.values.reserve(num_coordinates);
70 auto into = std::back_inserter(coordinates.values);
71 std::transform(begin, end, into, &detail::coordinateToLonLat);
72 }
73 else if (num_coordinates > 0)
74 {
75 // For a single location we create a [location, location] LineString
76 // instead of a single Point making the GeoJSON output consistent.
77 coordinates.values.reserve(2);
78 auto location = detail::coordinateToLonLat(*begin);
79 coordinates.values.push_back(location);
80 coordinates.values.push_back(location);
81 }
82 geojson.values["coordinates"] = util::json::Value{std::move(coordinates)};
83
84 return geojson;
85}
86
87util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver);
88

Callers 3

BOOST_AUTO_TEST_CASEFunction · 0.85
MakeGeometryMethod · 0.85
MakeRouteMethod · 0.85

Calls 3

coordinateToLonLatFunction · 0.85
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected