• 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
  • iau2kml
iau2kml.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 //
11 
12 
13 // #include <zlib.h>
14 
15 #include <QCoreApplication>
16 #include <QDebug>
17 #include <QFile>
18 #include <QStringList>
19 
20 
21 QString escapeXml( const QString &str )
22 {
23  QString xml = str;
24  xml.replace('&', "&amp;");
25  xml.replace('<', "&lt;");
26  xml.replace('>', "&gt;");
27  xml.replace('\'', "&apos;");
28  xml.replace('"', "&quot;");
29 
30  return xml;
31 }
32 
33 
34 int main(int argc, char *argv[])
35 {
36  QString sourcefilename;
37  QString targetfilename;
38 
39  QCoreApplication app( argc, argv );
40 
41  for ( int i = 1; i < argc; ++i ) {
42  if ( strcmp( argv[ i ], "-o" ) != 0 )
43  continue;
44 
45  targetfilename = QString(argv[i+1]);
46  sourcefilename = QString(argv[i+2]);
47 
48  qDebug() << "Source: " << sourcefilename;
49  qDebug() << "Target: " << targetfilename;
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::ReadWrite );
60 
61  QTextStream targetstream( &targetfile );
62  targetstream.setCodec("UTF-8");
63 
64  // gzFile gzDoc = gzopen( targetfilename.toLatin1(), "w");
65  // QTextStream targetstream( new QString() );
66 
67  targetstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
68  << "<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n"
69  << "<Document> \n";
70 
71  targetstream << " <Schema name=\"MarblePlacemark\" parent=\"Placemark\"> \n";
72  targetstream << " <SimpleField name=\"pop\" type=\"int\"></SimpleField> \n";
73  targetstream << " <SimpleField name=\"role\" type=\"string\"></SimpleField> \n";
74  targetstream << " </Schema> \n";
75 
76  targetstream << "\n";
77 
78  QString rawline;
79  QString nameString;
80  QString latString;
81  QString lonString;
82  QString popString;
83  QString roleString;
84  QString description;
85  float lat;
86  float lon;
87  int population;
88  QStringList splitline;
89 
90  while ( !sourcestream.atEnd() ) {
91 
92  rawline = sourcestream.readLine();
93 // if ( !rawline.startsWith("\"E\"|\"m\"|\"" ) ) {
94  if ( !rawline.startsWith(QLatin1String( "\"V\"|\"V\"|\"" ) ) ) {
95  continue;
96  }
97  rawline = rawline.replace( "\"|", "|" );
98  rawline = rawline.replace( "|\"", "|" );
99  if ( rawline.startsWith('\"') && rawline.endsWith('\"') ) {
100  rawline = rawline.left( rawline.length() - 1 );
101  rawline = rawline.right( rawline.length() - 2 );
102  }
103 
104  splitline = rawline.split('|');
105 
106  nameString = splitline[2];
107  latString = splitline[3];
108  lonString = splitline[4];
109  popString = splitline[10];
110  roleString = splitline[18];
111  description = splitline[19];
112 
113  // if ( roleString == "SF" ) continue;
114 
115  QString marbleRoleString = QLatin1String( "o" );
116 
117  if ( roleString == "AA" || roleString == "SF" ) marbleRoleString = "c";
118  if ( roleString == "ME" || roleString == "OC"
119  || roleString == "LC" || roleString == "SI" ) marbleRoleString = "a";
120  if ( roleString == "MO" ) marbleRoleString = "m";
121  if ( roleString == "VA" ) marbleRoleString = "v";
122 
123  population = (int) ( 1000.0 * popString.toFloat() );
124 
125  lon = lonString.toFloat();
126 
127  if ( lon > 180.0 ) lon = lon - 360.0;
128 
129  if ( rawline.startsWith(QLatin1String( "\"M\"|\"M\"|\"" ) ) || rawline.startsWith("\"V\"|\"V\"|\"" ) ) {
130  lon = -lon;
131  }
132 
133  lat = latString.toFloat();
134 
135  description = description.remove('"');
136 
137  targetstream << " <MarblePlacemark> \n";
138  targetstream << " <name>" << escapeXml( nameString ) << "</name> \n";
139  targetstream << " <role>" << escapeXml( marbleRoleString ) << "</role> \n";
140  targetstream << " <pop>"
141  << escapeXml( QString::number( population ) ) << "</pop> \n";
142  targetstream << " <description>" << escapeXml( description ) << "</description> \n";
143  targetstream << " <Point>\n"
144  << " <coordinates>"
145  << escapeXml( QString::number( lon ) )
146  << ","
147  << escapeXml( QString::number( lat ) )
148  << "</coordinates> \n"
149  << " </Point> \n";
150  targetstream << " </MarblePlacemark> \n";
151  }
152 
153  targetstream << "</Document> \n"
154  << "</kml> \n";
155  qDebug("...");
156 
157  sourcefile.close();
158  targetfile.close();
159 
160  qDebug("Finished!");
161  return 0;
162  }
163 
164  qDebug(" iau2kml -o targetfile sourcefile");
165  app.exit();
166 }
escapeXml
QString escapeXml(const QString &str)
Definition: iau2kml.cpp:21
main
int main(int argc, char *argv[])
Definition: iau2kml.cpp:34
QCoreApplication
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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