Nav2 Navigation Stack - humble  humble
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 #include "nav2_util/lifecycle_node.hpp"
24 
25 #ifndef NAV2_ROUTE__PLUGINS__GRAPH_FILE_SAVERS__GEOJSON_GRAPH_FILE_SAVER_HPP_
26 #define NAV2_ROUTE__PLUGINS__GRAPH_FILE_SAVERS__GEOJSON_GRAPH_FILE_SAVER_HPP_
27 
28 namespace nav2_route
29 {
30 
36 {
37 public:
38  using Json = nlohmann::json;
39 
43  GeoJsonGraphFileSaver() = default;
44 
49 
54  void configure(
55  const nav2_util::LifecycleNode::SharedPtr node) override;
56 
63  bool saveGraphToFile(
64  Graph & graph,
65  std::string filepath) override;
66 
67 protected:
73  void loadNodesFromGraph(Graph & graph, std::vector<Json> & json_features);
74 
80  void loadEdgesFromGraph(Graph & graph, std::vector<Json> & json_edges);
81 
87  void convertMetaDataToJson(const Metadata & metadata, Json & json_metadata);
88 
94  void convertOperationsToJson(const Operations & operations, Json & json_operations);
95 
96  rclcpp::Logger logger_{rclcpp::get_logger("GeoJsonGraphFileSaver")};
97 };
98 } // namespace nav2_route
99 
100 #endif // NAV2_ROUTE__PLUGINS__GRAPH_FILE_SAVERS__GEOJSON_GRAPH_FILE_SAVER_HPP_
A GraphFileSaver plugin to save a geojson graph representation.
void configure(const nav2_util::LifecycleNode::SharedPtr node) override
Configure, but do not store the node.
void convertOperationsToJson(const Operations &operations, Json &json_operations)
Convert graph operation to Json.
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