4#include "nlohmann/json.hpp"
8 inline void to_json(nlohmann::json &j,
const projection_t &p)
10 if (p.type == ProjType_Equirectangular)
11 j[
"type"] =
"equirec";
12 else if (p.type == ProjType_Stereographic)
14 else if (p.type == ProjType_UniversalTransverseMercator)
16 else if (p.type == ProjType_Geos)
18 else if (p.type == ProjType_Tpers)
20 else if (p.type == ProjType_WebMerc)
21 j[
"type"] =
"webmerc";
25 if (p.type == ProjType_UniversalTransverseMercator)
27 j[
"zone"] = p.params.zone;
28 j[
"south"] = p.params.south;
31 if (p.type == ProjType_Geos)
33 j[
"altitude"] = p.params.altitude;
34 j[
"sweep_x"] = p.params.sweep_x;
37 if (p.type == ProjType_Tpers)
39 j[
"altitude"] = p.params.altitude;
40 j[
"tilt"] = p.params.tilt;
41 j[
"azimuth"] = p.params.azimuth;
44 if (p.proj_offset_x != 0)
45 j[
"offset_x"] = p.proj_offset_x;
46 if (p.proj_offset_y != 0)
47 j[
"offset_y"] = p.proj_offset_y;
48 if (p.proj_scalar_x != 1)
49 j[
"scalar_x"] = p.proj_scalar_x;
50 if (p.proj_scalar_y != 1)
51 j[
"scalar_y"] = p.proj_scalar_y;
54 j[
"lon0"] = p.lam0 * RAD2DEG;
56 j[
"lat0"] = p.phi0 * RAD2DEG;
59 inline void from_json(
const nlohmann::json &j_in,
projection_t &p)
61 nlohmann::json j = j_in;
63 if (j[
"type"].get<std::string>() ==
"equirec")
64 p.type = ProjType_Equirectangular;
65 else if (j[
"type"].get<std::string>() ==
"stereo")
66 p.type = ProjType_Stereographic;
67 else if (j[
"type"].get<std::string>() ==
"utm")
68 p.type = ProjType_UniversalTransverseMercator;
69 else if (j[
"type"].get<std::string>() ==
"geos")
70 p.type = ProjType_Geos;
71 else if (j[
"type"].get<std::string>() ==
"tpers")
72 p.type = ProjType_Tpers;
73 else if (j[
"type"].get<std::string>() ==
"webmerc")
74 p.type = ProjType_WebMerc;
80 if (p.type == ProjType_Stereographic &&
81 j.contains(
"center_lon") && j.contains(
"center_lat") && j.contains(
"scale") &&
82 j.contains(
"width") && j.contains(
"height"))
84 double projections_image_width = j[
"width"];
85 double projections_image_height = j[
"height"];
86 double projections_stereo_center_lon = j[
"center_lon"];
87 double projections_stereo_center_lat = j[
"center_lat"];
88 double projections_stereo_scale = j[
"scale"];
89 j[
"lon0"] = projections_stereo_center_lon;
90 j[
"lat0"] = projections_stereo_center_lat;
91 j[
"scalar_x"] = projections_stereo_scale;
92 j[
"scalar_y"] = -projections_stereo_scale;
93 j[
"offset_x"] = -projections_image_width * 0.5 * projections_stereo_scale;
94 j[
"offset_y"] = projections_image_height * 0.5 * projections_stereo_scale;
96 else if (p.type == ProjType_Tpers &&
97 j.contains(
"center_lon") && j.contains(
"center_lat") && j.contains(
"scale") &&
98 j.contains(
"width") && j.contains(
"height"))
100 double projections_image_width = j[
"width"];
101 double projections_image_height = j[
"height"];
102 double projections_tpers_center_lon = j[
"center_lon"];
103 double projections_tpers_center_lat = j[
"center_lat"];
104 double projections_tpers_scale = j[
"scale"];
105 j[
"lon0"] = projections_tpers_center_lon;
106 j[
"lat0"] = projections_tpers_center_lat;
107 j[
"scalar_x"] = projections_tpers_scale;
108 j[
"scalar_y"] = -projections_tpers_scale;
109 j[
"offset_x"] = -projections_image_width * 0.5 * projections_tpers_scale;
110 j[
"offset_y"] = projections_image_height * 0.5 * projections_tpers_scale;
112 else if (p.type == ProjType_UniversalTransverseMercator &&
113 j.contains(
"scale") &&
114 j.contains(
"width") && j.contains(
"height"))
116 double projections_image_width = j[
"width"];
117 double projections_image_height = j[
"height"];
118 double projections_utm_scale = j[
"scale"];
119 double projections_utm_offset_y = j.contains(
"offset_y") ? j[
"offset_y"].get<
double>() : 0.0;
120 j[
"scalar_x"] = projections_utm_scale;
121 j[
"scalar_y"] = -projections_utm_scale;
122 j[
"offset_x"] = -projections_image_width * 0.5 * projections_utm_scale;
123 j[
"offset_y"] = projections_image_height * 0.5 * projections_utm_scale + projections_utm_offset_y;
128 if (p.type == ProjType_UniversalTransverseMercator)
130 if (j.contains(
"zone"))
131 p.params.zone = j[
"zone"];
132 if (j.contains(
"south"))
133 p.params.south = j[
"south"];
136 if (p.type == ProjType_Geos)
138 if (j.contains(
"altitude"))
139 p.params.altitude = j[
"altitude"];
140 if (j.contains(
"sweep_x"))
141 p.params.sweep_x = j[
"sweep_x"];
144 if (p.type == ProjType_Tpers)
146 if (j.contains(
"altitude"))
147 p.params.altitude = j[
"altitude"];
148 if (j.contains(
"tilt"))
149 p.params.tilt = j[
"tilt"];
150 if (j.contains(
"azimuth"))
151 p.params.azimuth = j[
"azimuth"];
156 if (j.contains(
"offset_x"))
157 p.proj_offset_x = j[
"offset_x"];
158 if (j.contains(
"offset_y"))
159 p.proj_offset_y = j[
"offset_y"];
160 if (j.contains(
"scalar_x"))
161 p.proj_scalar_x = j[
"scalar_x"];
162 if (j.contains(
"scalar_y"))
163 p.proj_scalar_y = j[
"scalar_y"];
165 if (j.contains(
"lon0"))
166 p.lam0 = j[
"lon0"].get<
double>() * DEG2RAD;
167 if (j.contains(
"lat0"))
168 p.phi0 = j[
"lat0"].get<
double>() * DEG2RAD;