Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
geojson_graph_file_saver.hpp
1 // Copyright (c) 2024 John Chrosniak
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <memory>
16 #include <string>
17 #include <vector>
18 #include <nlohmann/json.hpp>
19 
20 #include "nav2_core/route_exceptions.hpp"
21 #include "nav2_route/interfaces/graph_file_saver.hpp"
22 #include "nav2_route/plugins/graph_file_loaders/geojson_graph_file_loader.hpp"
23 
24 #ifndef NAV2_ROUTE__PLUGINS__GRAPH_FILE_SAVERS__GEOJSON_GRAPH_FILE_SAVER_HPP_
25 #define NAV2_ROUTE__PLUGINS__GRAPH_FILE_SAVERS__GEOJSON_GRAPH_FILE_SAVER_HPP_
26 
27 namespace nav2_route
28 {
29 
35 {
36 public:
37  using Json = nlohmann::json;
38 
42  GeoJsonGraphFileSaver() = default;
43 
48 
53  void configure(
54  const rclcpp_lifecycle::LifecycleNode::SharedPtr node) override;
55 
62  bool saveGraphToFile(
63  Graph & graph,
64  std::string filepath) override;
65 
66 protected:
72  void loadNodesFromGraph(Graph & graph, std::vector<Json> & json_features);
73 
79  void loadEdgesFromGraph(Graph & graph, std::vector<Json> & json_edges);
80 
86  void convertMetaDataToJson(const Metadata & metadata, Json & json_metadata);
87 
93  void convertOperationsToJson(const Operations & operations, Json & json_operations);
94 
95  rclcpp::Logger logger_{rclcpp::get_logger("GeoJsonGraphFileSaver")};
96 };
97 } // namespace nav2_route
98 
99 #endif // NAV2_ROUTE__PLUGINS__GRAPH_FILE_SAVERS__GEOJSON_GRAPH_FILE_SAVER_HPP_
A GraphFileSaver plugin to save a geojson graph representation.
void convertOperationsToJson(const Operations &operations, Json &json_operations)
Convert graph operation to Json.
void configure(const rclcpp_lifecycle::LifecycleNode::SharedPtr node) override
Configure, but do not store the node.
GeoJsonGraphFileSaver()=default
Constructor.
bool saveGraphToFile(Graph &graph, std::string filepath) override
Saves the graph to a geojson file.
void loadNodesFromGraph(Graph &graph, std::vector< Json > &json_features)
Add nodes into the graph.
void loadEdgesFromGraph(Graph &graph, std::vector< Json > &json_edges)
Add edges into the graph.
~GeoJsonGraphFileSaver()=default
Destructor.
void convertMetaDataToJson(const Metadata &metadata, Json &json_metadata)
Convert graph metadata to Json.
A plugin interface to parse a file into the graph.
An object to store arbitrary metadata regarding nodes from the graph file.
Definition: types.hpp:35