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

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • runner
  • pnt
PntRunner.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 2011 Thibaut Gridel <tgridel@free.fr>
9 // Copyright 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
10 
11 #include "PntRunner.h"
12 
13 #include "GeoDataDocument.h"
14 #include "GeoDataLineString.h"
15 #include "GeoDataPlacemark.h"
16 #include "MarbleDebug.h"
17 #include "MarbleGlobal.h"
18 
19 #include <qmath.h>
20 #include <QFile>
21 #include <QFileInfo>
22 
23 namespace Marble
24 {
25 
26 // distance of 180deg in arcminutes
27 const qreal INT2RAD = M_PI / 10800.0;
28 
29 PntRunner::PntRunner(QObject *parent) :
30  ParsingRunner(parent)
31 {
32 }
33 
34 PntRunner::~PntRunner()
35 {
36 }
37 
38 void PntRunner::parseFile( const QString &fileName, DocumentRole role = UnknownDocument )
39 {
40  QFileInfo fileinfo( fileName );
41  if( fileinfo.suffix().compare( "pnt", Qt::CaseInsensitive ) != 0 ) {
42  emit parsingFinished( 0 );
43  return;
44  }
45 
46  QFile file( fileName );
47  if ( !file.exists() ) {
48  qWarning( "File does not exist!" );
49  emit parsingFinished( 0 );
50  return;
51  }
52 
53  file.open( QIODevice::ReadOnly );
54  QDataStream stream( &file ); // read the data serialized from the file
55  stream.setByteOrder( QDataStream::LittleEndian );
56 
57  GeoDataDocument *document = new GeoDataDocument();
58  document->setDocumentRole( role );
59  GeoDataPlacemark *placemark = 0;
60 
61  int count = 0;
62  bool error = false;
63  while( !stream.atEnd() || error ){
64  short header = -1;
65  short iLat = -5400 - 1;
66  short iLon = -10800 - 1;
67 
68  stream >> header >> iLat >> iLon;
69 
70  // make sure iLat is within valid range
71  if ( !( -5400 <= iLat && iLat <= 5400 ) ) {
72  mDebug() << Q_FUNC_INFO << "invalid iLat =" << iLat << "(" << ( iLat * INT2RAD ) * RAD2DEG << ") in dataset" << count << "of file" << fileName;
73  error = true;
74  }
75 
76  // make sure iLon is within valid range
77  if ( !( -10800 <= iLon && iLon <= 10800 ) ) {
78  mDebug() << Q_FUNC_INFO << "invalid iLon =" << iLon << "(" << ( iLon * INT2RAD ) * RAD2DEG << ") in dataset" << count << "of file" << fileName;
79  error = true;
80  }
81 
82  if ( header >= 1000 && document->size() > 0 ) {
83  GeoDataLineString *const polyline = static_cast<GeoDataLineString*>( placemark->geometry() );
84  if ( polyline->size() == 1 ) {
85  mDebug() << Q_FUNC_INFO << fileName << "contains single-point polygon at" << count << ". Aborting.";
86  error = true;
87  break;
88  }
89  }
90 
91  if ( header < 1 ) {
92  /* invalid header */
93  mDebug() << Q_FUNC_INFO << "invalid header:" << header << "in" << fileName << "at" << count;
94  error = true;
95  break;
96  }
97  else if ( header <= 5 ) {
98  /* header represents level of detail */
99  /* nothing to do */
100  }
101  else if ( header < 1000 ) {
102  /* invalid header */
103  mDebug() << Q_FUNC_INFO << "invalid header:" << header << "in" << fileName << "at" << count;
104  error = true;
105  break;
106  }
107  else if ( header < 2000 ) {
108  /* header represents start of coastline */
109  placemark = new GeoDataPlacemark;
110  document->append( placemark );
111  placemark->setGeometry( new GeoDataLinearRing );
112  }
113  else if ( header < 4000 ) {
114  /* header represents start of country border */
115  placemark = new GeoDataPlacemark;
116  document->append( placemark );
117  placemark->setGeometry( new GeoDataLineString );
118  }
119  else if ( header < 5000 ) {
120  /* header represents start of internal political border */
121  placemark = new GeoDataPlacemark;
122  document->append( placemark );
123  placemark->setGeometry( new GeoDataLineString );
124  }
125  else if ( header < 6000 ) {
126  /* header represents start of island */
127  placemark = new GeoDataPlacemark;
128  document->append( placemark );
129  placemark->setGeometry( new GeoDataLinearRing );
130  }
131  else if ( header < 7000 ) {
132  /* header represents start of lake */
133  placemark = new GeoDataPlacemark;
134  document->append( placemark );
135  placemark->setGeometry( new GeoDataLinearRing );
136  }
137  else if ( header < 8000 ) {
138  /* header represents start of river */
139  placemark = new GeoDataPlacemark;
140  document->append( placemark );
141  placemark->setGeometry( new GeoDataLineString );
142  }
143  else if ( header < 9000 ) {
144  /* custom header represents start of glaciers, lakes or islands */
145  placemark = new GeoDataPlacemark;
146  document->append( placemark );
147  placemark->setGeometry( new GeoDataLinearRing );
148  }
149  else if ( header < 10000 ) {
150  /* custom header represents start of political borders */
151  placemark = new GeoDataPlacemark;
152  document->append( placemark );
153  placemark->setGeometry( new GeoDataLineString );
154  }
155  else if ( header < 14000 ) {
156  /* invalid header */
157  mDebug() << Q_FUNC_INFO << "invalid header:" << header << "in" << fileName << "at" << count;
158  error = true;
159  break;
160  }
161  else if ( header < 15000 ) {
162  /* custom header represents start of political borders */
163  placemark = new GeoDataPlacemark;
164  document->append( placemark );
165  placemark->setGeometry( new GeoDataLineString );
166  }
167  else if ( header < 19000 ) {
168  /* invalid header */
169  mDebug() << Q_FUNC_INFO << "invalid header:" << header << "in" << fileName << "at" << count;
170  error = true;
171  break;
172  }
173  else if ( header < 20000 ) {
174  /* custom header represents start of dateline */
175  placemark = new GeoDataPlacemark;
176  document->append( placemark );
177  placemark->setGeometry( new GeoDataLineString );
178  }
179  else {
180  /* invalid header */
181  mDebug() << Q_FUNC_INFO << "invalid header:" << header << "in" << fileName << "at" << count;
182  error = true;
183  break;
184  }
185 
186  GeoDataLineString *polyline = static_cast<GeoDataLineString*>( placemark->geometry() );
187 
188  // Transforming Range of Coordinates to iLat [0,ARCMINUTE] , iLon [0,2 * ARCMINUTE]
189  polyline->append( GeoDataCoordinates( (qreal)(iLon) * INT2RAD, (qreal)(iLat) * INT2RAD,
190  0.0, GeoDataCoordinates::Radian,
191  5 - qMin( 5, (int)header ) ) ); // if 1 <= header <= 5, header contains level of detail
192  // else pick most sparse level of detail, which equals 0
193 
194  ++count;
195  }
196 
197  file.close();
198  if ( document->size() == 0 || error ) {
199  delete document;
200  document = 0;
201  emit parsingFinished( 0 );
202  return;
203  }
204  document->setFileName( fileName );
205  emit parsingFinished( document );
206 }
207 
208 }
209 
210 #include "PntRunner.moc"
GeoDataDocument.h
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:220
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::GeoDataDocument::setDocumentRole
void setDocumentRole(DocumentRole role)
Definition: GeoDataDocument.cpp:86
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
QDataStream
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:138
Marble::PntRunner::~PntRunner
~PntRunner()
Definition: PntRunner.cpp:34
QFile::exists
bool exists() const
MarbleDebug.h
QFile
Marble::UnknownDocument
Definition: GeoDataDocument.h:40
Marble::ParsingRunner::parsingFinished
void parsingFinished(GeoDataDocument *document, const QString &error=QString())
File parsing is finished, result in the given document object.
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry()
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:152
Marble::PntRunner::parseFile
virtual void parseFile(const QString &fileName, DocumentRole role)
Start a file parsing.
Definition: PntRunner.cpp:38
QObject
GeoDataLineString.h
Marble::GeoDataContainer::size
int size() const
size of the container
Definition: GeoDataContainer.cpp:286
QString
Marble::INT2RAD
const qreal INT2RAD
Definition: PntRunner.cpp:27
MarbleGlobal.h
GeoDataPlacemark.h
PntRunner.h
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QDataStream::atEnd
bool atEnd() const
Marble::GeoDataLineString::append
void append(const GeoDataCoordinates &position)
Appends a given geodesic position as a new node to the LineString.
Definition: GeoDataLineString.cpp:225
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::ParsingRunner
Definition: ParsingRunner.h:23
Marble::GeoDataContainer::append
void append(GeoDataFeature *other)
add an element
Definition: GeoDataContainer.cpp:272
QFileInfo
QFile::close
virtual void close()
QDataStream::setByteOrder
void setByteOrder(ByteOrder bo)
QFileInfo::suffix
QString suffix() const
Marble::GeoDataDocument::setFileName
void setFileName(const QString &value)
Set a new file name for this document.
Definition: GeoDataDocument.cpp:106
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
QString::compare
int compare(const QString &other) const
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::DocumentRole
DocumentRole
Definition: GeoDataDocument.h:39
Marble::PntRunner::PntRunner
PntRunner(QObject *parent=0)
Definition: PntRunner.cpp:29
Marble::GeoDataPlacemark::setGeometry
void setGeometry(GeoDataGeometry *entry)
Sets the current Geometry of this Placemark.
Definition: GeoDataPlacemark.cpp:230
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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
  • 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