Plot a 2D graph of UTM coordinates.
53 {
54
55 std::string szPlotTitle = szTitle;
56 matplot::figure_handle mtPlot = matplot::figure(true);
57 matplot::axes_handle mtAxes = mtPlot->current_axes();
58
59
60 if (vCoordinates.empty())
61 {
62
63 LOG_WARNING(logging::g_qSharedLogger, "Coordinates vector is empty. Cannot plot.");
64 return;
65 }
66
67 if (szPlotTitle.empty())
68 {
69
70 LOG_WARNING(logging::g_qSharedLogger, "Plot title is empty. Setting title to default.");
71 szPlotTitle = "UTMCoordinatePlot";
72 }
73
74
75 std::string szFileName = logging::g_szLoggingOutputPath + "/path_plots/" + szTitle;
76 int nFileNum = 0;
77 while (std::filesystem::exists(szFileName + ".png"))
78 {
79 szFileName = szFileName + std::to_string(nFileNum);
80 ++nFileNum;
81 }
82
83
84 if (!std::filesystem::exists(logging::g_szLoggingOutputPath + "/path_plots"))
85 {
86 std::filesystem::create_directory(logging::g_szLoggingOutputPath + "/path_plots");
87 }
88
89 mtPlot->backend()->output(szFileName + ".png");
90
91
92 std::vector<double> vEasting, vNorthing;
94 {
95 vEasting.push_back(stCoordinate.dEasting);
96 vNorthing.push_back(stCoordinate.dNorthing);
97 }
98 mtAxes->plot(vEasting, vNorthing, "-o");
99 mtPlot->title(szPlotTitle);
100 mtAxes->xlabel("Easting");
101 mtAxes->ylabel("Northing");
102
103 mtAxes->grid(true);
104 mtAxes->xtickangle(45);
105 mtAxes->axis(matplot::square);
106 mtAxes->xtickformat("%.0f");
107 mtAxes->ytickformat("%.0f");
108
109 mtAxes->hold(false);
110
111
112 for (size_t i = 1; i < vCoordinates.size(); ++i)
113 {
114 double dDistance = std::sqrt(std::pow(vCoordinates[i].dEasting - vCoordinates[i - 1].dEasting, 2) +
115 std::pow(vCoordinates[i].dNorthing - vCoordinates[i - 1].dNorthing, 2));
116 double dMidEasting = (vCoordinates[i].dEasting + vCoordinates[i - 1].dEasting) / 2;
117 double dMidNorthing = (vCoordinates[i].dNorthing + vCoordinates[i - 1].dNorthing) / 2;
118 mtAxes->text(dMidEasting, dMidNorthing, std::to_string(int(dDistance)) + " m");
119 }
120
121
122 mtPlot->save(szFileName + ".png");
123 }
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:195