FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
serial::KmlGenerator Class Reference

Generates KML files from FERS simulation scenarios for geographical visualization. More...

#include "kml_generator.h"

Static Public Member Functions

static std::expected< void, std::string > generateKml (const core::World &world, const std::string &outputKmlPath)
 Generates a KML file from a pre-built simulation world.
 

Detailed Description

Generates KML files from FERS simulation scenarios for geographical visualization.

This class generates KML files for geographical visualization of FERS scenarios. It converts the stored platform coordinates to geodetic KML output using the user-specified KML/geospatial coordinate system in the XML file. This affects KML conversion only; the signal simulation uses the raw platform vectors directly. The KML/geospatial coordinate system can be one of:

  • ENU (East-North-Up): Default. Local Cartesian coordinates (x, y, z) are treated as meters in an ENU tangent plane centered at a geodetic <origin>.
  • UTM (Universal Transverse Mercator): Coordinates (x, y, z) are treated as easting (m), northing (m), and altitude (m) within a specified UTM zone and hemisphere.
  • ECEF (Earth-Centered, Earth-Fixed): Coordinates (x, y, z) are treated as geocentric X, Y, Z values in meters.

All input coordinates are converted to WGS84 geodetic coordinates (latitude, longitude, altitude) for the final KML output. The KML is written with <altitudeMode>absolute</altitudeMode>, where altitude is relative to Mean Sea Level (MSL).

Definition at line 49 of file kml_generator.h.

Member Function Documentation

◆ generateKml()

std::expected< void, std::string > serial::KmlGenerator::generateKml ( const core::World world,
const std::string &  outputKmlPath 
)
static

Generates a KML file from a pre-built simulation world.

Parameters
worldThe simulation world containing all objects and paths.
outputKmlPathThe path for the output KML file.
Returns
Success or an error message describing why generation failed.

Definition at line 28 of file kml_generator.cpp.

30 {
31 try
32 {
33 kml_generator_utils::KmlContext ctx;
34 ctx.parameters = params::params;
35
36 switch (ctx.parameters.coordinate_frame)
37 {
39 {
40 auto proj = std::make_shared<GeographicLib::LocalCartesian>(ctx.parameters.origin_latitude,
41 ctx.parameters.origin_longitude,
42 ctx.parameters.origin_altitude);
43 ctx.converter = [proj](const math::Vec3& pos, double& lat, double& lon, double& alt)
44 { proj->Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
45 break;
46 }
48 {
49 const int zone = ctx.parameters.utm_zone;
50 const bool northp = ctx.parameters.utm_north_hemisphere;
51 ctx.converter = [zone, northp](const math::Vec3& pos, double& lat, double& lon, double& alt)
52 {
53 double gamma = std::numeric_limits<double>::quiet_NaN();
54 double k = std::numeric_limits<double>::quiet_NaN();
55 GeographicLib::UTMUPS::Reverse(zone, northp, pos.x, pos.y, lat, lon, gamma, k);
56 alt = pos.z;
57 };
58 break;
59 }
61 {
62 const auto& earth = GeographicLib::Geocentric::WGS84();
63 ctx.converter = [&earth](const math::Vec3& pos, double& lat, double& lon, double& alt)
64 { earth.Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
65 break;
66 }
67 }
68
69 std::ofstream kml_file(outputKmlPath.c_str());
70 if (!kml_file.is_open())
71 {
72 const std::string message = "Error opening output KML file " + outputKmlPath;
74 return std::unexpected(message);
75 }
76
78 kml_file.close();
79 }
80 catch (const std::exception& e)
81 {
82 const std::string message = "Error generating KML file: " + std::string(e.what());
84 return std::unexpected(message);
85 }
86 catch (...)
87 {
88 const std::string message = "Unknown error occurred while generating KML file.";
90 return std::unexpected(message);
91 }
92 return {};
93 }
A class representing a vector in rectangular coordinates.
RealType x
The x component of the vector.
RealType z
The z component of the vector.
RealType y
The y component of the vector.
#define LOG(level,...)
Definition logging.h:19
@ ERROR
Error level for error events.
@ UTM
Universal Transverse Mercator.
@ ENU
East-North-Up local tangent plane (default)
@ ECEF
Earth-Centered, Earth-Fixed.
Parameters params
Global simulation parameter state.
Definition parameters.h:85
void generateKmlToStream(std::ostream &out, const core::World &world, const KmlContext &ctx)
Master entry point designed to convert the comprehensive simulation world state into a valid KML docu...
math::Vec3 max

References params::ECEF, params::ENU, logging::ERROR, serial::kml_generator_utils::generateKmlToStream(), LOG, max, params::params, params::UTM, math::Vec3::x, math::Vec3::y, and math::Vec3::z.

Referenced by fers_generate_kml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: