14 #include <QCoreApplication>
17 #include <QStringList>
33 int main(
int argc,
char *argv[])
37 for (
int i = 1; i < argc; ++i ) {
38 if ( strcmp( argv[ i ],
"-o" ) != 0 )
46 qDebug() <<
"Source: " << sourcefilename;
47 qDebug() <<
"Support: " << supportfilename;
48 qDebug() <<
"Target: " << targetfilename;
49 qDebug() <<
"Timezone: " << timezonefilename;
51 QFile sourcefile( sourcefilename );
52 sourcefile.
open( QIODevice::ReadOnly );
58 QFile targetfile( targetfilename );
59 targetfile.
open( QIODevice::WriteOnly );
64 QFile supportfile( supportfilename );
65 supportfile.
open( QIODevice::ReadOnly );
70 QFile timezonefile( timezonefilename );
71 timezonefile.
open( QIODevice::ReadOnly );
79 targetstream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
80 <<
"<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n"
86 while ( !sourcestream.
atEnd() ) {
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];
101 supportstream.
seek(0);
102 while ( !supportstream.
atEnd() ) {
105 if(supportsplitline[0] == (country +
'.' +statecode))
107 state = supportsplitline[1];
112 timezonestream.
seek(0);
114 while ( !timezonestream.
atEnd() ) {
118 if( timezonesplitline[0] == timezone )
120 gmt = timezonesplitline[1];
121 dst = timezonesplitline[2];
126 const int gmtoffset = ( int ) ( gmt.
toFloat() * 100 );
127 const int dstoffset = ( int ) ( dst.
toFloat() * 100 ) - gmtoffset;
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"
145 <<
"</coordinates> \n"
147 targetstream <<
" <ExtendedData>\n"
148 <<
" <Data name=\"gmt\">\n"
153 targetstream <<
" <Data name=\"dst\">\n"
157 targetstream <<
" </ExtendedData>\n";
158 targetstream <<
" </Placemark> \n";
162 targetstream <<
"</Document> \n"
172 timezonefile.
close();
177 qDebug(
" asc2kml -o targetfile sourcefile supporfile timezonefile");
void setCodec(QTextCodec *codec)
QString escapeXml(const QString &str)
QString readLine(qint64 maxlen)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
void exit(int returnCode)
QString number(int n, int base)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString & replace(int position, int n, QChar after)
float toFloat(bool *ok) const
int main(int argc, char *argv[])