• 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
  • asc2kml
asc2kml.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 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2010 Harshit Jain <hjain.itbhu@gmail.com>
11 //
12 
13 
14 #include <QCoreApplication>
15 #include <QDebug>
16 #include <QFile>
17 #include <QStringList>
18 
19 
20 QString escapeXml( const QString &str )
21 {
22  QString xml = str;
23  xml.replace('&', "&amp;");
24  xml.replace('<', "&lt;");
25  xml.replace('>', "&gt;");
26  xml.replace('\'', "&apos;");
27  xml.replace('"', "&quot;");
28 
29  return xml;
30 }
31 
32 
33 int main(int argc, char *argv[])
34 {
35  QCoreApplication app( argc, argv );
36 
37  for ( int i = 1; i < argc; ++i ) {
38  if ( strcmp( argv[ i ], "-o" ) != 0 )
39  continue;
40 
41  const QString targetfilename = QString( argv[i+1] );
42  const QString sourcefilename = QString( argv[i+2] );
43  const QString supportfilename = QString( argv[i+3] );
44  const QString timezonefilename = QString( argv[i+4] );
45 
46  qDebug() << "Source: " << sourcefilename;
47  qDebug() << "Support: " << supportfilename;
48  qDebug() << "Target: " << targetfilename;
49  qDebug() << "Timezone: " << timezonefilename;
50 
51  QFile sourcefile( sourcefilename );
52  sourcefile.open( QIODevice::ReadOnly );
53 
54  // Read the data serialized from the file.
55  QTextStream sourcestream( &sourcefile );
56  sourcestream.setCodec("UTF-8");
57 
58  QFile targetfile( targetfilename );
59  targetfile.open( QIODevice::WriteOnly );
60 
61  QTextStream targetstream( &targetfile );
62  targetstream.setCodec("UTF-8");
63 
64  QFile supportfile( supportfilename );
65  supportfile.open( QIODevice::ReadOnly );
66 
67  QTextStream supportstream( &supportfile );
68  supportstream.setCodec("UTF-8");
69 
70  QFile timezonefile( timezonefilename );
71  timezonefile.open( QIODevice::ReadOnly );
72 
73  QTextStream timezonestream( &timezonefile );
74  timezonestream.setCodec("UTF-8");
75 
76  // gzFile gzDoc = gzopen( targetfilename.toLatin1(), "w");
77  // QTextStream targetstream( new QString() );
78 
79  targetstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
80  << "<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n"
81  << "<Document> \n";
82  QString state;
83  QString gmt;
84  QString dst;
85 
86  while ( !sourcestream.atEnd() ) {
87 
88  const QString rawline = sourcestream.readLine();
89  const QStringList splitline = rawline.split('\t');
90 
91  const QString name = splitline[1];
92  const QString latstring = splitline[4];
93  const QString lngstring = splitline[5];
94  const QString role = splitline[7];
95  const QString country = splitline[8];
96  const QString statecode = splitline[10];
97  const QString popstring = splitline[14];
98  const QString elestring = splitline[16];
99  const QString timezone = splitline[17];
100 
101  supportstream.seek(0);
102  while ( !supportstream.atEnd() ) {
103  const QString supportrawline = supportstream.readLine();
104  const QStringList supportsplitline = supportrawline.split('\t');
105  if(supportsplitline[0] == (country + '.' +statecode))
106  {
107  state = supportsplitline[1];
108  break;
109  }
110  }
111 
112  timezonestream.seek(0);
113  timezonestream.readLine();
114  while ( !timezonestream.atEnd() ) {
115  const QString timezonerawline = timezonestream.readLine();
116  const QStringList timezonesplitline = timezonerawline.split('\t');
117 
118  if( timezonesplitline[0] == timezone )
119  {
120  gmt = timezonesplitline[1];
121  dst = timezonesplitline[2];
122  break;
123  }
124  }
125 
126  const int gmtoffset = ( int ) ( gmt.toFloat() * 100 );
127  const int dstoffset = ( int ) ( dst.toFloat() * 100 ) - gmtoffset;
128 
129  if(role != "PPLX")
130  {
131  targetstream << " <Placemark> \n";
132  targetstream << " <name>" << escapeXml( name ) << "</name> \n";
133  targetstream << " <state>" << escapeXml( state ) << "</state> \n";
134  targetstream << " <CountryNameCode>" << escapeXml( country.toUpper() ) << "</CountryNameCode>\n";
135  targetstream << " <role>" << escapeXml( role ) << "</role> \n";
136  targetstream << " <pop>"
137  << escapeXml( popstring ) << "</pop> \n";
138  targetstream << " <Point>\n"
139  << " <coordinates>"
140  << escapeXml( lngstring )
141  << ","
142  << escapeXml( latstring )
143  << ","
144  << escapeXml( elestring )
145  << "</coordinates> \n"
146  << " </Point> \n";
147  targetstream << " <ExtendedData>\n"
148  << " <Data name=\"gmt\">\n"
149  << " <value>" << escapeXml( QString::number( gmtoffset ) ) << "</value>\n"
150  << " </Data>\n";
151  if( dstoffset )
152  {
153  targetstream << " <Data name=\"dst\">\n"
154  << " <value>" << escapeXml( QString::number( dstoffset) ) << "</value>\n"
155  << " </Data>\n";
156  }
157  targetstream << " </ExtendedData>\n";
158  targetstream << " </Placemark> \n";
159  }
160  }
161 
162  targetstream << "</Document> \n"
163  << "</kml> \n";
164  qDebug("Putting");
165 
166  // gzputs( gzDoc, targetstream.readAll().toUtf8() );
167  // gzclose( gzDoc );
168 
169  sourcefile.close();
170  targetfile.close();
171  supportfile.close();
172  timezonefile.close();
173  qDebug("Finished!");
174  return 0;
175  }
176 
177  qDebug(" asc2kml -o targetfile sourcefile supporfile timezonefile");
178  app.exit();
179 }
QTextStream::setCodec
void setCodec(QTextCodec *codec)
escapeXml
QString escapeXml(const QString &str)
Definition: asc2kml.cpp:20
QString::toUpper
QString toUpper() const
QTextStream::readLine
QString readLine(qint64 maxlen)
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QCoreApplication
QFile
QTextStream
QCoreApplication::exit
void exit(int returnCode)
QString::number
QString number(int n, int base)
QTextStream::atEnd
bool atEnd() const
QString
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QStringList
QFile::close
virtual void close()
QString::replace
QString & replace(int position, int n, QChar after)
QString::toFloat
float toFloat(bool *ok) const
main
int main(int argc, char *argv[])
Definition: asc2kml.cpp:33
QTextStream::seek
bool seek(qint64 pos)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:38 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