12 #include <QCoreApplication>
13 #include <QDataStream>
15 #include <QStringList>
16 #include <QTextStream>
19 int main(
int argc,
char *argv[])
21 const qreal INT2SVG = 216.0 / 10800.0;
22 const qreal INT2DEG = 180.0 / 10800.0;
26 qDebug(
" Syntax: pnt2svg [-i pnt-sourcefile -o svg-targetfile -cn clipNorth -cs clipSouth -cw clipWest -ce clipEast]" );
28 QString inputFilename(
"PBORDERS.PNT");
30 if (inputIndex > 0 && inputIndex + 1 < argc )
31 inputFilename = app.
arguments().
at( inputIndex + 1 );
33 QString outputFilename(
"output.svg");
35 if (outputIndex > 0 && outputIndex + 1 < argc )
36 outputFilename = app.
arguments().
at( outputIndex + 1 );
38 qreal clipNorth = 90.0;
40 if (clipNorthIndex > 0 && clipNorthIndex + 1 < argc )
41 clipNorth = app.
arguments().
at( clipNorthIndex + 1 ).toDouble();
43 qreal clipSouth = -90.0;
45 if (clipSouthIndex > 0 && clipSouthIndex + 1 < argc )
46 clipSouth = app.
arguments().
at( clipSouthIndex + 1 ).toDouble();
48 qreal clipEast = 180.0;
50 if (clipEastIndex > 0 && clipEastIndex + 1 < argc )
51 clipEast = app.
arguments().
at( clipEastIndex + 1 ).toDouble();
53 qreal clipWest = -180.0;
55 if (clipWestIndex > 0 && clipWestIndex + 1 < argc )
56 clipWest = app.
arguments().
at( clipWestIndex + 1 ).toDouble();
58 qDebug() <<
"input filename:" << inputFilename;
59 qDebug() <<
"output filename:" << outputFilename;
60 qDebug() <<
"clipNorth:" << clipNorth;
61 qDebug() <<
"clipSouth:" << clipSouth;
62 qDebug() <<
"clipWest:" << clipWest;
63 qDebug() <<
"clipEast:" << clipEast;
74 QFile file( inputFilename );
76 if ( file.
open( QIODevice::ReadOnly ) ) {
86 while( !stream.
atEnd() ){
87 stream >> header >> iLat >> iLon;
92 if ( ( header >= 7000 && header < 8000 )
93 || ( header >= 9000 && header < 20000 ) ) {
95 styleString =
QString(
" fill=\"none\" stroke=\"black\" stroke-width=\"0.02\"");
99 styleString =
QString(
" fill=\"lightgrey\" stroke=\"black\" stroke-width=\"0.02\"");
102 if (!pathString.
isEmpty() && !clipped) {
103 pathString += closePolygon;
104 pathString += styleString;
105 pathString +=
QString(
" id=\"path%1_%2\" />").
arg(pathIndex).
arg(origHeader);
106 pathList.
append(pathString);
111 pathString =
QString(
"<path d=\"M %1, %2").
arg((qreal)(iLon) * INT2SVG + 216 ).
arg(-(qreal)(iLat) * INT2SVG + 108);
115 pathString +=
QString(
" L %1, %2").
arg((qreal)(iLon) * INT2SVG + 216 ).
arg(-(qreal)(iLat) * INT2SVG + 108);
119 if ((qreal)(iLat) * INT2DEG > clipNorth || (qreal)(iLat) * INT2DEG < clipSouth)
121 if ((qreal)(iLon) * INT2DEG > clipEast || (qreal)(iLon) * INT2DEG < clipWest)
126 if (!pathString.
isEmpty() && !clipped) {
127 pathString += closePolygon;
128 pathString +=
QString(
" id=\"path%1_%2\" />").
arg(count).
arg(origHeader);
135 qDebug() <<
"ERROR: Source file not found!";
140 QFile data(outputFilename);
141 if (data.
open(QFile::WriteOnly | QFile::Truncate)) {
144 out <<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << endl;
145 out <<
"<svg width=\"432.00000px\" height=\"216.00000px\">" << endl;
146 foreach (
const QString & path, pathList)
148 out <<
"</svg>" << endl;
153 qDebug() <<
"ERROR: Couldn't write output file to disc!";
const T & at(int i) const
void exit(int returnCode)
void append(const T &value)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
void setByteOrder(ByteOrder bo)
int indexOf(const QRegExp &rx, int from) const
int main(int argc, char *argv[])
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const