FERS 1.0.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 bool 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 interprets the simulation coordinates based on the user-specified coordinate system in the XML file, which 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 46 of file kml_generator.h.

Member Function Documentation

◆ generateKml()

bool 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
True on success, false on failure.

Definition at line 26 of file kml_generator.cpp.

27 {
28 try
29 {
30 kml_generator_utils::KmlContext ctx;
31 ctx.parameters = params::params;
32
33 switch (ctx.parameters.coordinate_frame)
34 {
36 {
37 auto proj = std::make_shared<GeographicLib::LocalCartesian>(ctx.parameters.origin_latitude,
38 ctx.parameters.origin_longitude,
39 ctx.parameters.origin_altitude);
40 ctx.converter = [proj](const math::Vec3& pos, double& lat, double& lon, double& alt)
41 { proj->Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
42 break;
43 }
45 {
46 const int zone = ctx.parameters.utm_zone;
47 const bool northp = ctx.parameters.utm_north_hemisphere;
48 ctx.converter = [zone, northp](const math::Vec3& pos, double& lat, double& lon, double& alt)
49 {
50 double gamma, k;
51 GeographicLib::UTMUPS::Reverse(zone, northp, pos.x, pos.y, lat, lon, gamma, k);
52 alt = pos.z;
53 };
54 break;
55 }
57 {
58 const auto& earth = GeographicLib::Geocentric::WGS84();
59 ctx.converter = [&earth](const math::Vec3& pos, double& lat, double& lon, double& alt)
60 { earth.Reverse(pos.x, pos.y, pos.z, lat, lon, alt); };
61 break;
62 }
63 }
64
65 std::ofstream kml_file(outputKmlPath.c_str());
66 if (!kml_file.is_open())
67 {
68 LOG(logging::Level::ERROR, "Error opening output KML file {}", outputKmlPath);
69 return false;
70 }
71
72 kml_generator_utils::generateKmlToStream(kml_file, world, ctx);
73 kml_file.close();
74 }
75 catch (const std::exception& e)
76 {
77 LOG(logging::Level::ERROR, "Error generating KML file: {}", e.what());
78 return false;
79 }
80 catch (...)
81 {
82 LOG(logging::Level::ERROR, "Unknown error occurred while generating KML file.");
83 return false;
84 }
85 return true;
86 }
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
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...

References serial::kml_generator_utils::KmlContext::converter, params::Parameters::coordinate_frame, params::ECEF, params::ENU, logging::ERROR, serial::kml_generator_utils::generateKmlToStream(), LOG, params::Parameters::origin_altitude, params::Parameters::origin_latitude, params::Parameters::origin_longitude, serial::kml_generator_utils::KmlContext::parameters, params::params, params::UTM, params::Parameters::utm_north_hemisphere, params::Parameters::utm_zone, 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: