Skip to content

Commit

Permalink
added node conversion for kml-reader
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 24, 2023
1 parent 76c9873 commit ffca665
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 55 deletions.
5 changes: 3 additions & 2 deletions Arrangement_on_surface_2/demo/earth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ source_group( "geometry" FILES ${source_files_geometry} )
qt_standard_project_setup()

qt_add_executable(earth
main.cpp
Main_widget.h Main_widget.cpp
Camera.h Camera.cpp
Common_defs.h
Geodesic_arcs.h Geodesic_arcs.cpp
Kml_reader.h Kml_reader.cpp
main.cpp
Main_widget.h Main_widget.cpp
Shader_program.h Shader_program.cpp
Tools.h Tools.cpp
${source_files_geometry}
Expand Down
5 changes: 5 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#include "Kml_reader.h"



16 changes: 16 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#ifndef KML_READER_H
#define KML_READER_H

#include <string>
#include <vector>


class Kml
{
public:

};


#endif
70 changes: 17 additions & 53 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ namespace {
struct LinearRing
{
std::vector<Node> nodes;
QString str;
};

struct MultiGeometry
Expand All @@ -136,7 +135,7 @@ namespace {
struct Placemark
{
MultiGeometry geometry;
QString name;
std::string name;
};
}

Expand All @@ -145,32 +144,6 @@ void Main_widget::initializeGL()
{
QString file_name("C:/work/gsoc2023/data/world_countries.kml");

if(0)
{
QDomDocument doc("mydoc");
QFile file(file_name);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "could not open file!";
return;
}
if (!doc.setContent(&file)) {
file.close();
return;
}
file.close();

//QDomElement docElem = doc.documentElement();
//QDomNode n = docElem.firstChild();
//qDebug() << n.nodeName();
//qDebug() << n.isElement();
//auto doc_elem = n.toElement();

auto placemarks = doc.elementsByTagName("Placemark");
qDebug() << placemarks.count();

}
else
{
std::vector<Placemark> placemarks;

Expand All @@ -191,74 +164,65 @@ void Main_widget::initializeGL()
while (!xmlReader.isEndDocument())
{
QString name = xmlReader.name().toString();
// qDebug() << "----------------------";
// qDebug() << name;
// qDebug() << xmlReader.text();


if (xmlReader.isStartElement())
{
// qDebug() << "START ELEMENT";
if (name == "Placemark")
{
// qDebug() << "Placemark - Start";
placemark = Placemark{};
}
else if (name == "MultiGeometry")
{
// qDebug() << "MultiGeometry - Start";
mgeometry = MultiGeometry{};
}
else if (name == "LinearRing")
{
// qDebug() << "LinearRing - Start";
lring = LinearRing{};
}
else if (name == "coordinates")
{
// qDebug() << "coordinates - Start";
xmlReader.readNext();
lring.str = xmlReader.text().toString();
// qDebug() << lring.str;
auto str = xmlReader.text().toString();
auto node_strs = str.split(" ");
for (const auto& node_str : node_strs)
{
if (node_str.isEmpty())
continue;

auto coord_strs = node_str.split(",");
const auto lon = coord_strs[0].toDouble();
const auto lat = coord_strs[1].toDouble();
lring.nodes.push_back(Node{ lon, lat });
}
}
else if (name == "SimpleData")
{
// qDebug() << "SimpleData - Start";
auto attributes = xmlReader.attributes();
auto attr_name = attributes[0].name().toString();
auto attr_value = attributes[0].value().toString();
if ((attr_name == "name") && (attr_value == "name"))
{
xmlReader.readNext();
placemark.name = xmlReader.text().toString();
// qDebug() << "country name = " << placemark.name;
placemark.name = xmlReader.text().toString().toStdString();;
}
//qDebug() << "num attribues = " << attributes.size();
//qDebug() << "attribute[0].name = " << attributes[0].name();
//qDebug() << "attribute[0].value = " << attributes[0].value();
}
}
else if (xmlReader.isEndElement())
{
// qDebug() << "END ELEMENT";
if (name == "Placemark")
{
// qDebug() << "Placemark - End";
placemarks.push_back(placemark); // move?
placemarks.push_back(std::move(placemark));
}
else if (name == "MultiGeometry")
{
// qDebug() << "MultiGeometry - End";
placemark.geometry = mgeometry; // move?
placemark.geometry = std::move(mgeometry);
}
else if (name == "LinearRing")
{
// qDebug() << "LinearRing - End";
mgeometry.polygons.push_back(lring); // move?
mgeometry.polygons.push_back(std::move(lring));
}
else if (name == "coordinates")
{
// qDebug() << "coordinates - End";
// no need to do anything here: the coordinates are read above!
}
}
Expand Down

0 comments on commit ffca665

Please sign in to comment.