// // This file is part of the Marble Desktop Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2007 Torsten Rahn // Copyright 2007 Inge Wallin // // #include #include #include #include #include QString escapeXml( const QString &str ) { QString xml = str; xml.replace('&', "&"); xml.replace('<', "<"); xml.replace('>', ">"); xml.replace('\'', "'"); xml.replace('"', """); return xml; } int main(int argc, char *argv[]) { QString sourcefilename; QString targetfilename; QCoreApplication app( argc, argv ); for ( int i = 1; i < argc; ++i ) { if ( strcmp( argv[ i ], "-o" ) != 0 ) continue; targetfilename = QString(argv[i+1]); sourcefilename = QString(argv[i+2]); qDebug() << "Source: " << sourcefilename; qDebug() << "Target: " << targetfilename; QFile sourcefile( sourcefilename ); sourcefile.open( QIODevice::ReadOnly ); // Read the data serialized from the file. QTextStream sourcestream( &sourcefile ); sourcestream.setCodec("UTF-8"); QFile targetfile( targetfilename ); targetfile.open( QIODevice::ReadWrite ); QTextStream targetstream( &targetfile ); targetstream.setCodec("UTF-8"); // gzFile gzDoc = gzopen( targetfilename.toLatin1(), "w"); // QTextStream targetstream( new QString() ); targetstream << " \n" << " \n" << " \n"; QString rawline; QString name; QString state; QString country; QString role; QString popstring; QString latstring; QString lngstring; float lat; float lng; int population; QStringList splitline; while ( !sourcestream.atEnd() ) { rawline=sourcestream.readLine(); splitline = rawline.split('\t'); name = splitline[0]; state = splitline[1]; country = splitline[2]; role = splitline[3]; popstring = splitline[4]; latstring = splitline[5]; lngstring = splitline[6]; population = (int) ( 1000 * popstring.toFloat() ); lng = lngstring.left( lngstring.size() - 2 ).toFloat(); if ( lngstring.contains( "W" ) ) lng=-lng; lat = latstring.left( latstring.size() - 2 ).toFloat(); if ( latstring.contains( "S" ) ) lat=-lat; targetstream << " \n"; targetstream << " " << escapeXml( name ) << " \n"; targetstream << " " << escapeXml( state ) << " \n"; targetstream << " " << escapeXml( country.toUpper() ) << "\n"; targetstream << " " << escapeXml( role ) << " \n"; targetstream << " " << escapeXml( QString::number( population ) ) << " \n"; targetstream << " \n" << " " << escapeXml( QString::number( lng ) ) << "," << escapeXml( QString::number( lat ) ) << " \n" << " \n"; targetstream << " \n"; } targetstream << " \n" << " \n"; qDebug("Putting"); // gzputs( gzDoc, targetstream.readAll().toUtf8() ); // gzclose( gzDoc ); sourcefile.close(); targetfile.close(); qDebug("Finished!"); return 0; } qDebug(" asc2kml -o targetfile sourcefile"); app.exit(); }