• 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
  • constellations2kml
constellations2kml.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 2013 Mohammed Nafees <nafees.technocool@gmail.com>
9 //
10 
11 #include "MarbleGlobal.h"
12 
13 #include <QFile>
14 #include <QDebug>
15 #include <QApplication>
16 #include <QStringList>
17 #include <QHash>
18 #include <QPair>
19 
20 #include <cmath>
21 
22 using namespace Marble;
23 
24 int main(int argc, char *argv[])
25 {
26  QCoreApplication app(argc, argv);
27 
28  QFile file( "constellations.kml" );
29  file.open( QIODevice::WriteOnly );
30  QTextStream out( &file );
31 
32  out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
33  << "<kml xmlns=\"http://earth.google.com/kml/2.2\" hint=\"target=sky\"> \n"
34  << "<Document> \n"
35  << " <Style id=\"lineStyle1\"> \n"
36  << " <LineStyle> \n"
37  << " <color>ffffffff</color> \n"
38  << " </LineStyle> \n"
39  << " </Style> \n"
40  << " <Style id=\"lineStyle2\"> \n"
41  << " <LineStyle> \n"
42  << " <color>ffff0000</color> \n"
43  << " </LineStyle> \n"
44  << " </Style> \n"
45  << " <Style id=\"iconStyle\"> \n"
46  << " <IconStyle> \n"
47  << " <Icon> \n"
48  << " <href></href> \n"
49  << " </Icon> \n"
50  << " </IconStyle> \n"
51  << " </Style> \n";
52 
53  QFile starsData( "catalog.dat" );
54  QFile constellationsData( "constellations.dat" );
55 
56  if ( starsData.open( QFile::ReadOnly ) && constellationsData.open( QFile::ReadOnly ) ) {
57 
58  QTextStream streamConstellations( &constellationsData );
59  QTextStream streamStars( &starsData );
60 
61  QHash<int, QPair<qreal, qreal> > hash;
62 
63  QString starsLine;
64  int index;
65  qreal longitude;
66  qreal latitude;
67  QPair<qreal, qreal> pair;
68  do {
69  starsLine = streamStars.readLine();
70  index = starsLine.mid( 0, 4 ).toInt();
71 
72  QString recString = starsLine.mid( 75, 6 );
73  double raHH = recString.mid( 0, 2 ).toDouble();
74  double raMM = recString.mid( 2, 2 ).toDouble();
75  double raSS = recString.mid( 4, 2 ).toDouble();
76 
77  longitude = ( raHH + raMM / 60.0 + raSS / 3600.0 ) * 15.0 - 180.0;
78 
79  QString decString = starsLine.mid( 83, 7 );
80  double deSign = ( decString.mid( 0, 1 ) == "-" ) ? -1.0 : 1.0;
81  double deHH = decString.mid( 1, 2 ).toDouble();
82  double deMM = decString.mid( 3, 2 ).toDouble();
83  double deSS = decString.mid( 5, 2 ).toDouble();
84 
85  double deValue = deSign * ( deHH + deMM / 60.0 + deSS / 3600.0 );
86 
87  latitude = deValue;
88 
89  pair.first = longitude;
90  pair.second = latitude;
91 
92  hash.insert( index, pair );
93  } while ( !starsLine.isNull() );
94 
95  QString name;
96  QString indexList;
97  QStringList starIndexes;
98  while ( !streamConstellations.atEnd() ) {
99  name = streamConstellations.readLine();
100 
101  // Check for null line at end of file
102  if ( name.isNull() ) {
103  continue;
104  }
105 
106  // Ignore Comment lines in header and
107  // between constellation entries
108  if ( name.startsWith( '#' ) ) {
109  continue;
110  }
111 
112  indexList = streamConstellations.readLine();
113 
114  // Make sure we have a valid name and indexList
115  if ( indexList.isNull() ) {
116  break;
117  }
118 
119  out << " <Placemark> \n"
120  << " <styleUrl>#lineStyle1</styleUrl> \n"
121  << " <MultiGeometry> \n"
122  << " <LineString> \n"
123  << " <coordinates> \n";
124 
125  starIndexes = indexList.split( " " );
126  QList<qreal> x;
127  QList<qreal> y;
128  QList<qreal> z;
129  int numberOfStars = 0;
130  for ( int i = 0; i < starIndexes.size(); ++i ) {
131  if ( starIndexes.at(i) == "-1" ) {
132  out << " </coordinates> \n"
133  << " </LineString> \n"
134  << " <LineString> \n"
135  << " <coordinates> \n";
136  } else if ( starIndexes.at(i) == "-2" ) {
137  out << " </coordinates> \n"
138  << " </LineString> \n"
139  << " </MultiGeometry> \n"
140  << " </Placemark> \n"
141  << " <Placemark> \n"
142  << " <styleUrl>#lineStyle2</styleUrl> \n"
143  << " <MultiGeometry> \n"
144  << " <LineString> \n"
145  << " <coordinates> \n";
146  } else if ( starIndexes.at(i) == "-3" ) {
147  out << " </coordinates> \n"
148  << " </LineString> \n"
149  << " </MultiGeometry> \n"
150  << " </Placemark> \n"
151  << " <Placemark> \n"
152  << " <styleUrl>#lineStyle1</styleUrl> \n"
153  << " <MultiGeometry> \n"
154  << " <LineString> \n"
155  << " <coordinates> \n";
156  }
157  QHash<int, QPair<qreal, qreal> >::const_iterator j = hash.find( starIndexes.at(i).toInt() );
158  while( j != hash.end() && j.key() == starIndexes.at(i).toInt() ) {
159  out << " " << j.value().first << "," << j.value().second << " \n";
160  x.append( cos( j.value().first * DEG2RAD ) * cos( j.value().second * DEG2RAD ) );
161  y.append( sin( j.value().first * DEG2RAD ) * cos( j.value().second * DEG2RAD ) );
162  z.append( sin( j.value().second * DEG2RAD ) );
163  ++numberOfStars;
164  ++j;
165  }
166  }
167 
168  out << " </coordinates> \n"
169  << " </LineString> \n"
170  << " </MultiGeometry> \n"
171  << " </Placemark> \n";
172 
173  qreal xMean = 0.0;
174  qreal yMean = 0.0;
175  qreal zMean = 0.0;
176  for ( int s = 0; s < numberOfStars; ++s ) {
177  xMean += x.at(s);
178  yMean += y.at(s);
179  zMean += z.at(s);
180  }
181 
182  xMean = xMean / numberOfStars;
183  yMean = yMean / numberOfStars;
184  zMean = zMean / numberOfStars;
185 
186  qreal labelLongitude = RAD2DEG * atan2( yMean, xMean );
187  qreal labelLatitude = RAD2DEG * atan2( zMean, sqrt( xMean * xMean + yMean * yMean ) );
188 
189  out << " <Placemark> \n"
190  << " <styleUrl>#iconStyle</styleUrl> \n"
191  << " <name>" << name << "</name> \n"
192  << " <Point> \n"
193  << " <coordinates>" << labelLongitude << "," << labelLatitude << "</coordinates> \n"
194  << " </Point> \n"
195  << " </Placemark> \n";
196  }
197  }
198 
199  out << "</Document> \n"
200  << "</kml> \n";
201 
202  constellationsData.close();
203  starsData.close();
204  file.close();
205 
206  app.exit();
207 }
208 
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:201
main
int main(int argc, char *argv[])
Definition: constellations2kml.cpp:24
MarbleGlobal.h
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:200
QCoreApplication
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 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