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

marble

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