16 #include <QCoreApplication>
19 #include <QStringList>
25 xml.replace(
'&',
"&");
26 xml.replace(
'<',
"<");
27 xml.replace(
'>',
">");
28 xml.replace(
'\'',
"'");
29 xml.replace(
'"',
""");
35 int main(
int argc,
char *argv[])
37 QString sourcefilename;
38 QString targetfilename;
39 QString supportfilename;
40 QString timezonefilename;
44 for (
int i = 1; i < argc; ++i ) {
45 if ( strcmp( argv[ i ],
"-o" ) != 0 )
48 targetfilename = QString( argv[i+1] );
49 sourcefilename = QString( argv[i+2] );
50 supportfilename = QString( argv[i+3] );
51 timezonefilename = QString( argv[i+4] );
53 qDebug() <<
"Source: " << sourcefilename;
54 qDebug() <<
"Support: " << supportfilename;
55 qDebug() <<
"Target: " << targetfilename;
56 qDebug() <<
"Timezone: " << timezonefilename;
58 QFile sourcefile( sourcefilename );
59 sourcefile.open( QIODevice::ReadOnly );
62 QTextStream sourcestream( &sourcefile );
63 sourcestream.setCodec(
"UTF-8");
65 QFile targetfile( targetfilename );
66 targetfile.open( QIODevice::WriteOnly );
68 QTextStream targetstream( &targetfile );
69 targetstream.setCodec(
"UTF-8");
71 QFile supportfile( supportfilename );
72 supportfile.open( QIODevice::ReadOnly );
74 QTextStream supportstream( &supportfile );
75 supportstream.setCodec(
"UTF-8");
77 QFile timezonefile( timezonefilename );
78 timezonefile.open( QIODevice::ReadOnly );
80 QTextStream timezonestream( &timezonefile );
81 timezonestream.setCodec(
"UTF-8");
86 targetstream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
87 <<
"<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n"
104 QStringList splitline;
106 while ( !sourcestream.atEnd() ) {
108 rawline=sourcestream.readLine();
109 splitline = rawline.split(
'\t');
112 latstring = splitline[4];
113 lngstring = splitline[5];
115 country = splitline[8];
116 statecode = splitline[10];
117 popstring = splitline[14];
118 elestring = splitline[16];
119 timezone = splitline[17];
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))
129 state = supportsplitline[1];
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');
142 if( timezonesplitline[0] == timezone )
144 gmt = timezonesplitline[1];
145 dst = timezonesplitline[2];
150 gmtoffset = ( int ) ( gmt.toFloat() * 100 );
151 dstoffset = ( int ) ( dst.toFloat() * 100 ) - gmtoffset;
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"
169 <<
"</coordinates> \n"
171 targetstream <<
" <ExtendedData>\n"
172 <<
" <Data name=\"gmt\">\n"
173 <<
" <value>" <<
escapeXml( QString::number( gmtoffset ) ) <<
"</value>\n"
177 targetstream <<
" <Data name=\"dst\">\n"
178 <<
" <value>" <<
escapeXml( QString::number( dstoffset) ) <<
"</value>\n"
181 targetstream <<
" </ExtendedData>\n";
182 targetstream <<
" </Placemark> \n";
186 targetstream <<
"</Document> \n"
196 timezonefile.close();
201 qDebug(
" asc2kml -o targetfile sourcefile supporfile timezonefile");
QString escapeXml(const QString &str)
int main(int argc, char *argv[])