mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-14 20:20:35 +00:00
Merge branch 'extend-gpx-kml' of https://github.com/acebrianjuan/gnss-sdr into acebrianjuan-extend-gpx-kml
This commit is contained in:
commit
66c3a9ed3a
@ -138,13 +138,15 @@ bool Gpx_Printer::set_headers(std::string filename, bool time_tag_name)
|
||||
gpx_file << std::setprecision(14);
|
||||
gpx_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl
|
||||
<< "<gpx version=\"1.1\" creator=\"GNSS-SDR\"" << std::endl
|
||||
<< "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\"" << std::endl
|
||||
<< "xmlns=\"http://www.topografix.com/GPX/1/1\"" << std::endl
|
||||
<< "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" << std::endl
|
||||
<< "<trk>" << std::endl
|
||||
<< indent << "<name>Position fixes computed by GNSS-SDR v" << GNSS_SDR_VERSION << "</name>" << std::endl
|
||||
<< indent << "<desc>GNSS-SDR position log generated at " << pt << " (local time)</desc>" << std::endl
|
||||
<< indent << "<trkseg>" << std::endl;
|
||||
<< indent << "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v2 http://www.garmin.com/xmlschemas/TrackPointExtensionv2.xsd\"" << std::endl
|
||||
<< indent << "xmlns=\"http://www.topografix.com/GPX/1/1\"" << std::endl
|
||||
<< indent << "xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"" << std::endl
|
||||
<< indent << "xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v2\"" << std::endl
|
||||
<< indent << "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" << std::endl
|
||||
<< indent << "<trk>" << std::endl
|
||||
<< indent << indent << "<name>Position fixes computed by GNSS-SDR v" << GNSS_SDR_VERSION << "</name>" << std::endl
|
||||
<< indent << indent << "<desc>GNSS-SDR position log generated at " << pt << " (local time)</desc>" << std::endl
|
||||
<< indent << indent << "<trkseg>" << std::endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -164,6 +166,9 @@ bool Gpx_Printer::print_position(const std::shared_ptr<rtklib_solver>& position,
|
||||
positions_printed = true;
|
||||
std::shared_ptr<rtklib_solver> position_ = position;
|
||||
|
||||
double speed_over_ground = position_->get_speed_over_ground(); // expressed in m/s
|
||||
double course_over_ground = position_->get_course_over_ground(); // expressed in deg
|
||||
|
||||
double hdop = position_->get_hdop();
|
||||
double vdop = position_->get_vdop();
|
||||
double pdop = position_->get_pdop();
|
||||
@ -187,9 +192,13 @@ bool Gpx_Printer::print_position(const std::shared_ptr<rtklib_solver>& position,
|
||||
|
||||
if (gpx_file.is_open())
|
||||
{
|
||||
gpx_file << indent << indent << "<trkpt lon=\"" << longitude << "\" lat=\"" << latitude << "\"><ele>" << height << "</ele>"
|
||||
gpx_file << indent << indent << indent << "<trkpt lon=\"" << longitude << "\" lat=\"" << latitude << "\"><ele>" << height << "</ele>"
|
||||
<< "<time>" << utc_time << "</time>"
|
||||
<< "<hdop>" << hdop << "</hdop><vdop>" << vdop << "</vdop><pdop>" << pdop << "</pdop></trkpt>" << std::endl;
|
||||
<< "<hdop>" << hdop << "</hdop><vdop>" << vdop << "</vdop><pdop>" << pdop << "</pdop>"
|
||||
<< "<extensions><gpxtpx:TrackPointExtension>"
|
||||
<< "<gpxtpx:speed>" << speed_over_ground << "</gpxtpx:speed>"
|
||||
<< "<gpxtpx:course>" << course_over_ground << "</gpxtpx:course>"
|
||||
<< "</gpxtpx:TrackPointExtension></extensions></trkpt>" << std::endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -203,8 +212,8 @@ bool Gpx_Printer::close_file()
|
||||
{
|
||||
if (gpx_file.is_open())
|
||||
{
|
||||
gpx_file << indent << "</trkseg>" << std::endl
|
||||
<< "</trk>" << std::endl
|
||||
gpx_file << indent << indent << "</trkseg>" << std::endl
|
||||
<< indent << "</trk>" << std::endl
|
||||
<< "</gpx>";
|
||||
gpx_file.close();
|
||||
return true;
|
||||
|
@ -2,6 +2,7 @@
|
||||
* \file kml_printer.cc
|
||||
* \brief Implementation of a class that prints PVT information to a kml file
|
||||
* \author Javier Arribas, 2011. jarribas(at)cttc.es
|
||||
* Álvaro Cebrián Juan, 2018. acebrianjuan(at)gmail.com
|
||||
*
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
@ -43,6 +44,7 @@ using google::LogMessage;
|
||||
Kml_Printer::Kml_Printer(const std::string& base_path)
|
||||
{
|
||||
positions_printed = false;
|
||||
indent = " ";
|
||||
kml_base_path = base_path;
|
||||
boost::filesystem::path full_path(boost::filesystem::current_path());
|
||||
const boost::filesystem::path p(kml_base_path);
|
||||
@ -74,6 +76,14 @@ Kml_Printer::Kml_Printer(const std::string& base_path)
|
||||
}
|
||||
|
||||
kml_base_path = kml_base_path + boost::filesystem::path::preferred_separator;
|
||||
|
||||
boost::filesystem::path tmp_base_path = boost::filesystem::temp_directory_path();
|
||||
boost::filesystem::path tmp_filename = boost::filesystem::unique_path();
|
||||
boost::filesystem::path tmp_file = tmp_base_path / tmp_filename;
|
||||
|
||||
tmp_file_str = tmp_file.string();
|
||||
|
||||
point_id = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -127,36 +137,73 @@ bool Kml_Printer::set_headers(std::string filename, bool time_tag_name)
|
||||
kml_filename = kml_base_path + kml_filename;
|
||||
kml_file.open(kml_filename.c_str());
|
||||
|
||||
if (kml_file.is_open())
|
||||
tmp_file.open(tmp_file_str.c_str());
|
||||
|
||||
if (kml_file.is_open() && tmp_file.is_open())
|
||||
{
|
||||
DLOG(INFO) << "KML printer writing on " << filename.c_str();
|
||||
// Set iostream numeric format and precision
|
||||
kml_file.setf(kml_file.fixed, kml_file.floatfield);
|
||||
kml_file << std::setprecision(14);
|
||||
|
||||
tmp_file.setf(tmp_file.fixed, tmp_file.floatfield);
|
||||
tmp_file << std::setprecision(14);
|
||||
|
||||
kml_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl
|
||||
<< "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" << std::endl
|
||||
<< " <Document>" << std::endl
|
||||
<< " <name>GNSS Track</name>" << std::endl
|
||||
<< " <description>GNSS-SDR Receiver position log file created at " << pt
|
||||
<< " </description>" << std::endl
|
||||
<< "<Style id=\"yellowLineGreenPoly\">" << std::endl
|
||||
<< " <LineStyle>" << std::endl
|
||||
<< " <color>7f00ffff</color>" << std::endl
|
||||
<< " <width>1</width>" << std::endl
|
||||
<< " </LineStyle>" << std::endl
|
||||
<< "<PolyStyle>" << std::endl
|
||||
<< " <color>7f00ff00</color>" << std::endl
|
||||
<< "</PolyStyle>" << std::endl
|
||||
<< "</Style>" << std::endl
|
||||
<< "<Placemark>" << std::endl
|
||||
<< "<name>GNSS-SDR PVT</name>" << std::endl
|
||||
<< "<description>GNSS-SDR position log</description>" << std::endl
|
||||
<< "<styleUrl>#yellowLineGreenPoly</styleUrl>" << std::endl
|
||||
<< "<LineString>" << std::endl
|
||||
<< "<extrude>0</extrude>" << std::endl
|
||||
<< "<tessellate>1</tessellate>" << std::endl
|
||||
<< "<altitudeMode>absolute</altitudeMode>" << std::endl
|
||||
<< "<coordinates>" << std::endl;
|
||||
<< "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" << std::endl
|
||||
<< indent << "<Document>" << std::endl
|
||||
<< indent << indent << "<name>GNSS Track</name>" << std::endl
|
||||
<< indent << indent << "<description><![CDATA[" << std::endl
|
||||
<< indent << indent << indent << "<table>" << std::endl
|
||||
<< indent << indent << indent << indent << "<tr><td>GNSS-SDR Receiver position log file created at " << pt << "</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << "<tr><td>https://gnss-sdr.org/</td></tr>" << std::endl
|
||||
<< indent << indent << indent << "</table>" << std::endl
|
||||
<< indent << indent << "]]></description>" << std::endl
|
||||
<< indent << indent << "<!-- Normal track style -->" << std::endl
|
||||
<< indent << indent << "<Style id=\"track_n\">" << std::endl
|
||||
<< indent << indent << indent << "<IconStyle>" << std::endl
|
||||
<< indent << indent << indent << indent << "<color>ff00ffff</color>" << std::endl
|
||||
<< indent << indent << indent << indent << "<scale>0.3</scale>" << std::endl
|
||||
<< indent << indent << indent << indent << "<Icon>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "<href>http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png</href>" << std::endl
|
||||
<< indent << indent << indent << indent << "</Icon>" << std::endl
|
||||
<< indent << indent << indent << "</IconStyle>" << std::endl
|
||||
<< indent << indent << indent << "<LabelStyle>" << std::endl
|
||||
<< indent << indent << indent << indent << "<scale>0</scale>" << std::endl
|
||||
<< indent << indent << indent << "</LabelStyle>" << std::endl
|
||||
<< indent << indent << "</Style>" << std::endl
|
||||
<< indent << indent << "<!-- Highlighted track style -->" << std::endl
|
||||
<< indent << indent << "<Style id=\"track_h\">" << std::endl
|
||||
<< indent << indent << indent << "<IconStyle>" << std::endl
|
||||
<< indent << indent << indent << indent << "<color>ff00ffff</color>" << std::endl
|
||||
<< indent << indent << indent << indent << "<scale>1</scale>" << std::endl
|
||||
<< indent << indent << indent << indent << "<Icon>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "<href>http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png</href>" << std::endl
|
||||
<< indent << indent << indent << indent << "</Icon>" << std::endl
|
||||
<< indent << indent << indent << "</IconStyle>" << std::endl
|
||||
<< indent << indent << "</Style>" << std::endl
|
||||
<< indent << indent << "<StyleMap id=\"track\">" << std::endl
|
||||
<< indent << indent << indent << "<Pair>" << std::endl
|
||||
<< indent << indent << indent << indent << "<key>normal</key>" << std::endl
|
||||
<< indent << indent << indent << indent << "<styleUrl>#track_n</styleUrl>" << std::endl
|
||||
<< indent << indent << indent << "</Pair>" << std::endl
|
||||
<< indent << indent << indent << "<Pair>" << std::endl
|
||||
<< indent << indent << indent << indent << "<key>highlight</key>" << std::endl
|
||||
<< indent << indent << indent << indent << "<styleUrl>#track_h</styleUrl>" << std::endl
|
||||
<< indent << indent << indent << "</Pair>" << std::endl
|
||||
<< indent << indent << "</StyleMap>" << std::endl
|
||||
<< indent << indent << "<Style id=\"yellowLineGreenPoly\">" << std::endl
|
||||
<< indent << indent << indent << "<LineStyle>" << std::endl
|
||||
<< indent << indent << indent << indent << "<color>7f00ffff</color>" << std::endl
|
||||
<< indent << indent << indent << indent << "<width>1</width>" << std::endl
|
||||
<< indent << indent << indent << "</LineStyle>" << std::endl
|
||||
<< indent << indent << indent << "<PolyStyle>" << std::endl
|
||||
<< indent << indent << indent << indent << "<color>7f00ff00</color>" << std::endl
|
||||
<< indent << indent << indent << "</PolyStyle>" << std::endl
|
||||
<< indent << indent << "</Style>" << std::endl
|
||||
<< indent << indent << "<Folder>" << std::endl
|
||||
<< indent << indent << indent << "<name>Points</name>" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -167,7 +214,7 @@ bool Kml_Printer::set_headers(std::string filename, bool time_tag_name)
|
||||
}
|
||||
|
||||
|
||||
bool Kml_Printer::print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values)
|
||||
bool Kml_Printer::print_position(const std::shared_ptr<rtklib_solver>& position, bool print_average_values)
|
||||
{
|
||||
double latitude;
|
||||
double longitude;
|
||||
@ -175,7 +222,18 @@ bool Kml_Printer::print_position(const std::shared_ptr<Pvt_Solution>& position,
|
||||
|
||||
positions_printed = true;
|
||||
|
||||
std::shared_ptr<Pvt_Solution> position_ = position;
|
||||
std::shared_ptr<rtklib_solver> position_ = position;
|
||||
|
||||
double speed_over_ground = position_->get_speed_over_ground(); // expressed in m/s
|
||||
double course_over_ground = position_->get_course_over_ground(); // expressed in deg
|
||||
|
||||
double hdop = position_->get_hdop();
|
||||
double vdop = position_->get_vdop();
|
||||
double pdop = position_->get_pdop();
|
||||
std::string utc_time = to_iso_extended_string(position_->get_position_UTC_time());
|
||||
if (utc_time.length() < 23) utc_time += ".";
|
||||
utc_time.resize(23, '0'); // time up to ms
|
||||
utc_time.append("Z"); // UTC time zone
|
||||
|
||||
if (print_average_values == false)
|
||||
{
|
||||
@ -190,9 +248,38 @@ bool Kml_Printer::print_position(const std::shared_ptr<Pvt_Solution>& position,
|
||||
height = position_->get_avg_height();
|
||||
}
|
||||
|
||||
if (kml_file.is_open())
|
||||
if (kml_file.is_open() && tmp_file.is_open())
|
||||
{
|
||||
kml_file << longitude << "," << latitude << "," << height << std::endl;
|
||||
point_id++;
|
||||
kml_file << indent << indent << indent << "<Placemark>" << std::endl
|
||||
<< indent << indent << indent << indent << "<name>" << point_id << "</name>" << std::endl
|
||||
<< indent << indent << indent << indent << "<snippet/>" << std::endl
|
||||
<< indent << indent << indent << indent << "<description><![CDATA[" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "<table>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>Time:</td><td>" << utc_time << "</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>Longitude:</td><td>" << longitude << "</td><td>deg</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>Latitude:</td><td>" << latitude << "</td><td>deg</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>Altitude:</td><td>" << height << "</td><td>m</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>Speed:</td><td>" << speed_over_ground << "</td><td>m/s</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>Course:</td><td>" << course_over_ground << "</td><td>deg</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>HDOP:</td><td>" << hdop << "</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>VDOP:</td><td>" << vdop << "</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << indent << "<tr><td>PDOP:</td><td>" << pdop << "</td></tr>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "</table>" << std::endl
|
||||
<< indent << indent << indent << indent << "]]></description>" << std::endl
|
||||
<< indent << indent << indent << indent << "<TimeStamp>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "<when>" << utc_time << "</when>" << std::endl
|
||||
<< indent << indent << indent << indent << "</TimeStamp>" << std::endl
|
||||
<< indent << indent << indent << indent << "<styleUrl>#track</styleUrl>" << std::endl
|
||||
<< indent << indent << indent << indent << "<Point>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "<altitudeMode>absolute</altitudeMode>" << std::endl
|
||||
<< indent << indent << indent << indent << indent << "<coordinates>" << longitude << "," << latitude << "," << height << "</coordinates>" << std::endl
|
||||
<< indent << indent << indent << indent << "</Point>" << std::endl
|
||||
<< indent << indent << indent << "</Placemark>" << std::endl;
|
||||
|
||||
tmp_file << indent << indent << indent << indent << indent
|
||||
<< longitude << "," << latitude << "," << height << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -204,14 +291,32 @@ bool Kml_Printer::print_position(const std::shared_ptr<Pvt_Solution>& position,
|
||||
|
||||
bool Kml_Printer::close_file()
|
||||
{
|
||||
if (kml_file.is_open())
|
||||
if (kml_file.is_open() && tmp_file.is_open())
|
||||
{
|
||||
kml_file << "</coordinates>" << std::endl
|
||||
<< "</LineString>" << std::endl
|
||||
<< "</Placemark>" << std::endl
|
||||
<< "</Document>" << std::endl
|
||||
tmp_file.close();
|
||||
|
||||
kml_file << indent << indent << "</Folder>"
|
||||
<< indent << indent << "<Placemark>" << std::endl
|
||||
<< indent << indent << indent << "<name>Path</name>" << std::endl
|
||||
<< indent << indent << indent << "<styleUrl>#yellowLineGreenPoly</styleUrl>" << std::endl
|
||||
<< indent << indent << indent << "<LineString>" << std::endl
|
||||
<< indent << indent << indent << indent << "<extrude>0</extrude>" << std::endl
|
||||
<< indent << indent << indent << indent << "<tessellate>1</tessellate>" << std::endl
|
||||
<< indent << indent << indent << indent << "<altitudeMode>absolute</altitudeMode>" << std::endl
|
||||
<< indent << indent << indent << indent << "<coordinates>" << std::endl;
|
||||
|
||||
// Copy the contents of tmp_file into kml_file
|
||||
std::ifstream src(tmp_file_str, std::ios::binary);
|
||||
kml_file << src.rdbuf();
|
||||
|
||||
kml_file << indent << indent << indent << indent << "</coordinates>" << std::endl
|
||||
<< indent << indent << indent << "</LineString>" << std::endl
|
||||
<< indent << indent << "</Placemark>" << std::endl
|
||||
<< indent << "</Document>" << std::endl
|
||||
<< "</kml>";
|
||||
|
||||
kml_file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -2,7 +2,7 @@
|
||||
* \file kml_printer.h
|
||||
* \brief Interface of a class that prints PVT information to a kml file
|
||||
* \author Javier Arribas, 2011. jarribas(at)cttc.es
|
||||
*
|
||||
* Álvaro Cebrián Juan, 2018. acebrianjuan(at)gmail.com
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
@ -34,6 +34,7 @@
|
||||
#define GNSS_SDR_KML_PRINTER_H_
|
||||
|
||||
#include "pvt_solution.h"
|
||||
#include "rtklib_solver.h"
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -48,15 +49,19 @@ class Kml_Printer
|
||||
{
|
||||
private:
|
||||
std::ofstream kml_file;
|
||||
std::ofstream tmp_file;
|
||||
bool positions_printed;
|
||||
std::string kml_filename;
|
||||
std::string kml_base_path;
|
||||
std::string tmp_file_str;
|
||||
unsigned int point_id;
|
||||
std::string indent;
|
||||
|
||||
public:
|
||||
Kml_Printer(const std::string& base_path = std::string("."));
|
||||
~Kml_Printer();
|
||||
bool set_headers(std::string filename, bool time_tag_name = true);
|
||||
bool print_position(const std::shared_ptr<Pvt_Solution>& position, bool print_average_values);
|
||||
bool print_position(const std::shared_ptr<rtklib_solver>& position, bool print_average_values);
|
||||
bool close_file();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user