• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • tools
  • pnt2svg
pnt2svg.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2012 Torsten Rahn <tackat@kde.org>
9 //
10 
11 
12 #include <QCoreApplication>
13 #include <QDataStream>
14 #include <QFile>
15 #include <QStringList>
16 #include <QTextStream>
17 #include <QDebug>
18 
19 int main(int argc, char *argv[])
20 {
21  const qreal INT2SVG = 216.0 / 10800.0;
22  const qreal INT2DEG = 180.0 / 10800.0;
23 
24  QCoreApplication app(argc, argv);
25 
26  qDebug( " Syntax: pnt2svg [-i pnt-sourcefile -o svg-targetfile -cn clipNorth -cs clipSouth -cw clipWest -ce clipEast]" );
27 
28  QString inputFilename("PBORDERS.PNT");
29  int inputIndex = app.arguments().indexOf("-i");
30  if (inputIndex > 0 && inputIndex + 1 < argc )
31  inputFilename = app.arguments().at( inputIndex + 1 );
32 
33  QString outputFilename("output.svg");
34  int outputIndex = app.arguments().indexOf("-o");
35  if (outputIndex > 0 && outputIndex + 1 < argc )
36  outputFilename = app.arguments().at( outputIndex + 1 );
37 
38  qreal clipNorth = 90.0;
39  int clipNorthIndex = app.arguments().indexOf("-cn");
40  if (clipNorthIndex > 0 && clipNorthIndex + 1 < argc )
41  clipNorth = app.arguments().at( clipNorthIndex + 1 ).toDouble();
42 
43  qreal clipSouth = -90.0;
44  int clipSouthIndex = app.arguments().indexOf("-cs");
45  if (clipSouthIndex > 0 && clipSouthIndex + 1 < argc )
46  clipSouth = app.arguments().at( clipSouthIndex + 1 ).toDouble();
47 
48  qreal clipEast = 180.0;
49  int clipEastIndex = app.arguments().indexOf("-ce");
50  if (clipEastIndex > 0 && clipEastIndex + 1 < argc )
51  clipEast = app.arguments().at( clipEastIndex + 1 ).toDouble();
52 
53  qreal clipWest = -180.0;
54  int clipWestIndex = app.arguments().indexOf("-cw");
55  if (clipWestIndex > 0 && clipWestIndex + 1 < argc )
56  clipWest = app.arguments().at( clipWestIndex + 1 ).toDouble();
57 
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;
64 
65  // INPUT
66  QStringList pathList;
67  QString pathString;
68  QString closePolygon;
69  QString styleString;
70  int count = 0;
71  int origHeader = 0;
72  int pathIndex = 0;
73 
74  QFile file( inputFilename );
75 
76  if ( file.open( QIODevice::ReadOnly ) ) {
77  QDataStream stream( &file ); // read the data serialized from the file
78  stream.setByteOrder( QDataStream::LittleEndian );
79 
80  short header;
81  short iLat;
82  short iLon;
83 
84  bool clipped = false;
85 
86  while( !stream.atEnd() ){
87  stream >> header >> iLat >> iLon;
88  // Transforming Range of Coordinates to iLat [0,ARCMINUTE] , iLon [0,2 * ARCMINUTE]
89 
90  if ( header > 5 ) {
91  // Find out whether the Polyline is a river or a closed polygon
92  if ( ( header >= 7000 && header < 8000 )
93  || ( header >= 9000 && header < 20000 ) ) {
94  closePolygon=" \"";
95  styleString = QString(" fill=\"none\" stroke=\"black\" stroke-width=\"0.02\"");
96  }
97  else {
98  closePolygon=" z \"";
99  styleString = QString(" fill=\"lightgrey\" stroke=\"black\" stroke-width=\"0.02\"");
100  }
101  // Finish old path
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);
107  }
108  // Start new path
109  origHeader = header;
110  clipped = false;
111  pathString = QString("<path d=\"M %1, %2").arg((qreal)(iLon) * INT2SVG + 216 ).arg(-(qreal)(iLat) * INT2SVG + 108);
112  ++pathIndex;
113  }
114  else {
115  pathString += QString(" L %1, %2").arg((qreal)(iLon) * INT2SVG + 216 ).arg(-(qreal)(iLat) * INT2SVG + 108);
116  }
117  ++count;
118 
119  if ((qreal)(iLat) * INT2DEG > clipNorth || (qreal)(iLat) * INT2DEG < clipSouth)
120  clipped = true;
121  if ((qreal)(iLon) * INT2DEG > clipEast || (qreal)(iLon) * INT2DEG < clipWest)
122  clipped = true;
123  }
124 
125  // Finish old path
126  if (!pathString.isEmpty() && !clipped) {
127  pathString += closePolygon;
128  pathString += QString(" id=\"path%1_%2\" />").arg(count).arg(origHeader);
129  if (!pathString.isEmpty()) pathList.append(pathString);
130  }
131 
132  file.close();
133  }
134  else {
135  qDebug() << "ERROR: Source file not found!";
136  }
137 
138 
139  // OUTPUT
140  QFile data(outputFilename);
141  if (data.open(QFile::WriteOnly | QFile::Truncate)) {
142  QTextStream out(&data);
143 
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)
147  out << path << endl;
148  out << "</svg>" << endl;
149  qDebug() << "Done!";
150  data.close();
151  }
152  else {
153  qDebug() << "ERROR: Couldn't write output file to disc!";
154  }
155 
156  app.exit();
157 }
QCoreApplication
main
int main(int argc, char *argv[])
Definition: pnt2svg.cpp:19
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal