15 #include <QCoreApplication>
18 #include <QStringList>
34 int main(
int argc,
char *argv[])
41 for (
int i = 1; i < argc; ++i ) {
42 if ( strcmp( argv[ i ],
"-o" ) != 0 )
45 targetfilename =
QString(argv[i+1]);
46 sourcefilename =
QString(argv[i+2]);
48 qDebug() <<
"Source: " << sourcefilename;
49 qDebug() <<
"Target: " << targetfilename;
51 QFile sourcefile( sourcefilename );
52 sourcefile.
open( QIODevice::ReadOnly );
58 QFile targetfile( targetfilename );
59 targetfile.
open( QIODevice::ReadWrite );
67 targetstream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
68 <<
"<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n"
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";
90 while ( !sourcestream.
atEnd() ) {
97 rawline = rawline.
replace(
"\"|",
"|" );
98 rawline = rawline.
replace(
"|\"",
"|" );
100 rawline = rawline.
left( rawline.
length() - 1 );
104 splitline = rawline.
split(
'|');
106 nameString = splitline[2];
107 latString = splitline[3];
108 lonString = splitline[4];
109 popString = splitline[10];
110 roleString = splitline[18];
111 description = splitline[19];
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";
123 population = (int) ( 1000.0 * popString.
toFloat() );
127 if ( lon > 180.0 ) lon = lon - 360.0;
135 description = description.
remove(
'"');
137 targetstream <<
" <MarblePlacemark> \n";
138 targetstream <<
" <name>" <<
escapeXml( nameString ) <<
"</name> \n";
139 targetstream <<
" <role>" <<
escapeXml( marbleRoleString ) <<
"</role> \n";
140 targetstream <<
" <pop>"
142 targetstream <<
" <description>" <<
escapeXml( description ) <<
"</description> \n";
143 targetstream <<
" <Point>\n"
148 <<
"</coordinates> \n"
150 targetstream <<
" </MarblePlacemark> \n";
153 targetstream <<
"</Document> \n"
164 qDebug(
" iau2kml -o targetfile sourcefile");
void setCodec(QTextCodec *codec)
QString readLine(qint64 maxlen)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString & remove(int position, int n)
void exit(int returnCode)
QString number(int n, int base)
QString escapeXml(const QString &str)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
int main(int argc, char *argv[])
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString right(int n) const
QString & replace(int position, int n, QChar after)
float toFloat(bool *ok) const
QString left(int n) const