• 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
  • monav
MonavMap.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 2010 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "MonavMap.h"
12 #include "MarbleDebug.h"
13 
14 #include "GeoDataParser.h"
15 #include "GeoDataPlacemark.h"
16 #include "GeoDataDocument.h"
17 #include "GeoDataExtendedData.h"
18 #include "GeoDataData.h"
19 
20 namespace Marble
21 {
22 
23 void MonavMap::setDirectory( const QDir &dir )
24 {
25  m_directory = dir;
26  QFileInfo boundingBox( dir, "marble.kml" );
27  if ( boundingBox.exists() ) {
28  parseBoundingBox( boundingBox );
29  } else {
30  mDebug() << "No monav bounding box given for " << boundingBox.absoluteFilePath();
31  }
32 }
33 
34 void MonavMap::parseBoundingBox( const QFileInfo &file )
35 {
36  GeoDataLineString points;
37  bool tooLarge = false;
38  QFile input( file.absoluteFilePath() );
39  if ( input.open( QFile::ReadOnly ) ) {
40  GeoDataParser parser( GeoData_KML );
41  if ( !parser.read( &input ) ) {
42  mDebug() << "Could not parse file: " << parser.errorString();
43  return;
44  }
45 
46  GeoDocument *doc = parser.releaseDocument();
47  input.close();
48  GeoDataDocument *document = dynamic_cast<GeoDataDocument*>( doc );
49  QVector<GeoDataPlacemark*> placemarks = document->placemarkList();
50  if ( placemarks.size() == 1 ) {
51  GeoDataPlacemark* placemark = placemarks.first();
52  m_name = placemark->name();
53  m_version = placemark->extendedData().value( "version" ).value().toString();
54  m_date = placemark->extendedData().value( "date" ).value().toString();
55  m_transport = placemark->extendedData().value( "transport" ).value().toString();
56  m_payload = placemark->extendedData().value( "payload" ).value().toString();
57  const GeoDataMultiGeometry* geometry = dynamic_cast<const GeoDataMultiGeometry*>( placemark->geometry() );
58  if ( geometry->size() > 1500 ) {
59  tooLarge = true;
60  }
61  for ( int i = 0; geometry && i < geometry->size(); ++i ) {
62  const GeoDataLinearRing* poly = dynamic_cast<const GeoDataLinearRing*>( geometry->child( i ) );
63  if ( poly ) {
64  for ( int j = 0; j < poly->size(); ++j ) {
65  points << poly->at( j );
66  }
67  m_tiles.push_back( *poly );
68 
69  if ( poly->size() > 1500 ) {
70  tooLarge = true;
71  }
72  }
73  }
74  } else {
75  mDebug() << "File " << file.absoluteFilePath() << " does not contain one placemark, but " << placemarks.size();
76  }
77 
78  delete doc;
79  }
80  m_boundingBox = points.latLonAltBox();
81 
82  if ( tooLarge ) {
83  // The bounding box polygon is rather complicated, therefore not allowing a quick check
84  // and also occupying memory. Discard the polygon and only store the rectangular bounding
85  // box. Only happens for non-simplified bounding box polygons.
86  mDebug() << "Discarding too large bounding box poylgon for " << file.absoluteFilePath() << ". Please check for a map update.";
87  m_tiles.clear();
88  }
89 }
90 
91 bool MonavMap::containsPoint( const GeoDataCoordinates &point ) const
92 {
93  // If we do not have a bounding box at all, we err on the safe side
94  if ( m_boundingBox.isEmpty() ) {
95  return true;
96  }
97 
98  // Quick check for performance reasons
99  if ( !m_boundingBox.contains( point ) ) {
100  return false;
101  }
102 
103  if ( m_tiles.isEmpty() ) {
104  return true; // Tiles discarded for performance reason
105  }
106 
107  // GeoDataLinearRing does a 3D check, but we only have 2D data for
108  // the map bounding box. Therefore the 3D info of e.g. the GPS position
109  // must be ignored.
110  GeoDataCoordinates flatPosition = point;
111  flatPosition.setAltitude( 0.0 );
112  foreach( const GeoDataLinearRing & box, m_tiles ) {
113  if ( box.contains( flatPosition ) ) {
114  return true;
115  }
116  }
117 
118  return false;
119 }
120 
121 qint64 MonavMap::size() const
122 {
123  qint64 result = 0;
124  foreach( const QFileInfo & file, files() ) {
125  result += file.size();
126  }
127 
128  return result;
129 }
130 
131 QList<QFileInfo> MonavMap::files() const
132 {
133  QList<QFileInfo> files;
134  QStringList fileNames = QStringList() << "config" << "edges" << "names" << "paths" << "types";
135  foreach( const QString & file, fileNames ) {
136  files << QFileInfo( m_directory, QString( "Contraction Hierarchies_" ) + file );
137  }
138 
139  fileNames = QStringList() << "config" << "grid" << "index_1" << "index_2" << "index_3";
140  foreach( const QString & file, fileNames ) {
141  files << QFileInfo( m_directory, QString( "GPSGrid_" ) + file );
142  }
143 
144  files << QFileInfo( m_directory, "plugins.ini" );
145  QFileInfo moduleDotIni( m_directory, "Module.ini" );
146  if ( moduleDotIni.exists() ) {
147  files << moduleDotIni;
148  }
149  files << QFileInfo( m_directory, "marble.kml" );
150  return files;
151 }
152 
153 void MonavMap::remove() const
154 {
155  foreach( const QFileInfo & file, files() ) {
156  QFile ( file.absoluteFilePath() ).remove();
157  }
158 }
159 
160 bool MonavMap::areaLessThan( const MonavMap &first, const MonavMap &second )
161 {
162  if ( !first.m_tiles.isEmpty() && second.m_tiles.isEmpty() ) {
163  return true;
164  }
165 
166  if ( first.m_tiles.isEmpty() && !second.m_tiles.isEmpty() ) {
167  return false;
168  }
169 
170  qreal const areaOne = first.m_boundingBox.width() * first.m_boundingBox.height();
171  qreal const areaTwo = second.m_boundingBox.width() * second.m_boundingBox.height();
172  return areaOne < areaTwo;
173 }
174 
175 bool MonavMap::nameLessThan( const MonavMap &first, const MonavMap &second )
176 {
177  return first.name() < second.name();
178 }
179 
180 QDir MonavMap::directory() const
181 {
182  return m_directory;
183 }
184 
185 QString MonavMap::transport() const
186 {
187  return m_transport;
188 }
189 
190 QString MonavMap::name() const
191 {
192  return m_name;
193 }
194 
195 QString MonavMap::version() const
196 {
197  return m_version;
198 }
199 
200 QString MonavMap::date() const
201 {
202  return m_date;
203 }
204 
205 QString MonavMap::payload() const
206 {
207  return m_payload;
208 }
209 
210 }
GeoDataDocument.h
Marble::MonavMap::transport
QString transport() const
Definition: MonavMap.cpp:185
Marble::MonavMap::nameLessThan
static bool nameLessThan(const MonavMap &first, const MonavMap &second)
Definition: MonavMap.cpp:175
Marble::GeoDataLatLonBox::height
qreal height(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the height of the latitude interval.
Definition: GeoDataLatLonBox.cpp:255
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
MonavMap.h
Marble::GeoDataLatLonBox::isEmpty
virtual bool isEmpty() const
Indicates whether the bounding box is not initialised (and contains nothing).
Definition: GeoDataLatLonBox.cpp:768
Marble::GeoDataLatLonBox::width
qreal width(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the width of the longitude interval.
Definition: GeoDataLatLonBox.cpp:236
Marble::GeoDataParser
Definition: GeoDataParser.h:40
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
Marble::GeoDataCoordinates::setAltitude
void setAltitude(const qreal altitude)
set the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1191
Marble::GeoDataLinearRing::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataLinearRing.cpp:58
Marble::MonavMap::version
QString version() const
Definition: MonavMap.cpp:195
Marble::MonavMap::setDirectory
void setDirectory(const QDir &dir)
Definition: MonavMap.cpp:23
GeoDataParser.h
QVector::first
T & first()
GeoDataExtendedData.h
Marble::GeoDataLatLonBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonBox.cpp:309
Marble::MonavMap::remove
void remove() const
Definition: MonavMap.cpp:153
MarbleDebug.h
Marble::MonavMap::name
QString name() const
Definition: MonavMap.cpp:190
QFile
Marble::MonavMap::containsPoint
bool containsPoint(const GeoDataCoordinates &point) const
Definition: MonavMap.cpp:91
Marble::GeoData_KML
Definition: GeoDataParser.h:36
Marble::MonavMap::areaLessThan
static bool areaLessThan(const MonavMap &first, const MonavMap &second)
Definition: MonavMap.cpp:160
QFileInfo::absoluteFilePath
QString absoluteFilePath() const
Marble::MonavMap::directory
QDir directory() const
Definition: MonavMap.cpp:180
QString
QList
Marble::MonavMap::payload
QString payload() const
Definition: MonavMap.cpp:205
GeoDataPlacemark.h
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
QStringList
Marble::GeoDataLineString::at
GeoDataCoordinates & at(int pos)
Returns a reference to the coordinates of a node at a given position. This method detaches the return...
Definition: GeoDataLineString.cpp:143
QFileInfo
QFileInfo::size
qint64 size() const
QFileInfo::exists
bool exists() const
QDir
Marble::MonavMap::date
QString date() const
Definition: MonavMap.cpp:200
GeoDataData.h
QVector
Marble::MonavMap::size
qint64 size() const
Definition: MonavMap.cpp:121
QVector::size
int size() const
Marble::MonavMap
Definition: MonavMap.h:22
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:580
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