• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • tools
  • kml2cache
kml2cache.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2008 Patrick Spendrin <ps_ml@gmx.de>
9 // Copyright 2013 Dennis Nienhüser <earthwings@gentoo.org>
10 //
11 
12 // A simple tool to read a .kml file and write it back to a .cache file
13 
14 #include <ParsingRunnerManager.h>
15 #include <PluginManager.h>
16 #include <MarbleClock.h>
17 #include <GeoDataDocument.h>
18 #include <GeoDataFolder.h>
19 #include <GeoDataPlacemark.h>
20 #include <GeoDataExtendedData.h>
21 #include <GeoWriter.h>
22 
23 #include <QApplication>
24 #include <QDebug>
25 #include <QFile>
26 #include <iostream>
27 
28 using namespace std;
29 using namespace Marble;
30 
31 const quint32 MarbleMagicNumber = 0x31415926;
32 
33 void savePlacemarks( QDataStream &out, const GeoDataContainer *container, MarbleClock* clock )
34 {
35  qreal lon;
36  qreal lat;
37  qreal alt;
38 
39  const QVector<GeoDataPlacemark*> placemarks = container->placemarkList();
40  QVector<GeoDataPlacemark*>::const_iterator it = placemarks.constBegin();
41  QVector<GeoDataPlacemark*>::const_iterator const end = placemarks.constEnd();
42  for (; it != end; ++it ) {
43  out << (*it)->name();
44  (*it)->coordinate().geoCoordinates( lon, lat, alt );
45 
46  // Use double to provide a single cache file format across architectures
47  out << (double)(lon) << (double)(lat) << (double)(alt);
48  out << QString( (*it)->role() );
49  out << QString( (*it)->description() );
50  out << QString( (*it)->countryCode() );
51  out << QString( (*it)->state() );
52  out << (double) (*it)->area();
53  out << (qint64) (*it)->population();
54  out << ( qint16 ) ( (*it)->extendedData().value("gmt").value().toInt() );
55  out << ( qint8 ) ( (*it)->extendedData().value("dst").value().toInt() );
56  }
57 
58  const QVector<GeoDataFolder*> folders = container->folderList();
59  QVector<GeoDataFolder*>::const_iterator cont = folders.constBegin();
60  QVector<GeoDataFolder*>::const_iterator endcont = folders.constEnd();
61  for (; cont != endcont; ++cont ) {
62  savePlacemarks( out, *cont, clock );
63  }
64 }
65 
66 void saveFile( const QString& filename, GeoDataDocument* document )
67 {
68  QFile file( filename );
69  if ( !file.open( QIODevice::WriteOnly ) ) {
70  qDebug() << Q_FUNC_INFO << "Can't open" << filename << "for writing";
71  return;
72  }
73  QDataStream out( &file );
74 
75  // Write a header with a "magic number" and a version
76  // out << (quint32)0xA0B0C0D0;
77  out << (quint32)MarbleMagicNumber;
78  out << (qint32)015;
79 
80  out.setVersion( QDataStream::Qt_4_2 );
81 
82  savePlacemarks( out, document, new MarbleClock );
83 }
84 
85 int main(int argc, char** argv)
86 {
87  QApplication app(argc,argv);
88 
89  QString inputFilename;
90  int inputIndex = app.arguments().indexOf( "-i" );
91  if ( inputIndex > 0 && inputIndex + 1 < argc ) {
92  inputFilename = app.arguments().at( inputIndex + 1 );
93  } else {
94  qDebug( " Syntax: kml2cache -i sourcefile [-o cache-targetfile]" );
95  return 1;
96  }
97 
98  QString outputFilename = "output.cache";
99  int outputIndex = app.arguments().indexOf("-o");
100  if ( outputIndex > 0 && outputIndex + 1 < argc )
101  outputFilename = app.arguments().at( outputIndex + 1 );
102 
103  ParsingRunnerManager* manager = new ParsingRunnerManager( new PluginManager );
104  GeoDataDocument* document = manager->openFile( inputFilename );
105  if (!document) {
106  qDebug() << "Could not parse input file. No error message available unfortunately";
107  return 2;
108  }
109 
110  saveFile( outputFilename, document );
111 }
GeoDataDocument.h
Marble::PluginManager
The class that handles Marble's plugins.
Definition: PluginManager.h:45
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::ParsingRunnerManager
Definition: ParsingRunnerManager.h:31
QDataStream
saveFile
void saveFile(const QString &filename, GeoDataDocument *document)
Definition: kml2cache.cpp:66
QVector::constEnd
const_iterator constEnd() const
QList::at
const T & at(int i) const
QApplication
Marble::GeoDataContainer
A base class that can hold GeoDataFeatures.
Definition: GeoDataContainer.h:47
GeoDataExtendedData.h
QFile
ParsingRunnerManager.h
GeoWriter.h
Marble::ParsingRunnerManager::openFile
GeoDataDocument * openFile(const QString &fileName, DocumentRole role=UserDocument, int timeout=30000)
Definition: ParsingRunnerManager.cpp:121
main
int main(int argc, char **argv)
Definition: kml2cache.cpp:85
Marble::GeoDataContainer::folderList
QVector< GeoDataFolder * > folderList() const
A convenience function that returns all folders in this container.
Definition: GeoDataContainer.cpp:197
QString
GeoDataPlacemark.h
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QDataStream::setVersion
void setVersion(int v)
MarbleClock.h
GeoDataFolder.h
QVector::constBegin
const_iterator constBegin() const
savePlacemarks
void savePlacemarks(QDataStream &out, const GeoDataContainer *container, MarbleClock *clock)
Definition: kml2cache.cpp:33
QVector
PluginManager.h
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
QCoreApplication::arguments
QStringList arguments()
Marble::MarbleClock
Definition: MarbleClock.h:25
MarbleMagicNumber
const quint32 MarbleMagicNumber
Definition: kml2cache.cpp:31
Marble::GeoDataContainer::placemarkList
QVector< GeoDataPlacemark * > placemarkList() const
A convenience function that returns all placemarks in this container.
Definition: GeoDataContainer.cpp:214
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal