• 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
  • gosmore-reversegeocoding
GosmoreReverseGeocodingRunner.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 // Copyright 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
10 //
11 
12 #include "GosmoreReverseGeocodingRunner.h"
13 
14 #include "MarbleDebug.h"
15 #include "MarbleDirs.h"
16 #include "routing/RouteRequest.h"
17 #include "routing/instructions/WaypointParser.h"
18 #include "routing/instructions/InstructionTransformation.h"
19 #include "GeoDataDocument.h"
20 #include "GeoDataExtendedData.h"
21 
22 #include <QProcess>
23 #include <QMap>
24 
25 namespace Marble
26 {
27 
28 class GosmoreRunnerPrivate
29 {
30 public:
31  QFileInfo m_gosmoreMapFile;
32 
33  WaypointParser m_parser;
34 
35  QByteArray retrieveWaypoints( const QString &query ) const;
36 
37  GosmoreRunnerPrivate();
38 };
39 
40 GosmoreRunnerPrivate::GosmoreRunnerPrivate()
41 {
42  m_parser.setLineSeparator("\r");
43  m_parser.setFieldSeparator(',');
44  m_parser.setFieldIndex( WaypointParser::RoadName, 4 );
45  m_parser.addJunctionTypeMapping( "Jr", RoutingWaypoint::Roundabout );
46 }
47 
48 QByteArray GosmoreRunnerPrivate::retrieveWaypoints( const QString &query ) const
49 {
50  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
51  env.insert("QUERY_STRING", query);
52  env.insert("LC_ALL", "C");
53  QProcess gosmore;
54  gosmore.setProcessEnvironment(env);
55 
56  gosmore.start("gosmore", QStringList() << m_gosmoreMapFile.absoluteFilePath() );
57  if (!gosmore.waitForStarted(5000)) {
58  mDebug() << "Couldn't start gosmore from the current PATH. Install it to retrieve routing results from gosmore.";
59  return QByteArray();
60  }
61 
62  if ( gosmore.waitForFinished(15000) ) {
63  return gosmore.readAllStandardOutput();
64  }
65  else {
66  mDebug() << "Couldn't stop gosmore";
67  }
68 
69  return QByteArray();
70 }
71 
72 GosmoreRunner::GosmoreRunner( QObject *parent ) :
73  ReverseGeocodingRunner( parent ),
74  d( new GosmoreRunnerPrivate )
75 {
76  // Check installation
77  QDir mapDir( MarbleDirs::localPath() + "/maps/earth/gosmore/" );
78  d->m_gosmoreMapFile = QFileInfo ( mapDir, "gosmore.pak" );
79 }
80 
81 GosmoreRunner::~GosmoreRunner()
82 {
83  delete d;
84 }
85 
86 void GosmoreRunner::reverseGeocoding( const GeoDataCoordinates &coordinates )
87 {
88  if ( !d->m_gosmoreMapFile.exists() )
89  {
90  emit reverseGeocodingFinished( coordinates, GeoDataPlacemark() );
91  return;
92  }
93 
94  QString queryString = "flat=%1&flon=%2&tlat=%1&tlon=%2&fastest=1&v=motorcar";
95  double lon = coordinates.longitude( GeoDataCoordinates::Degree );
96  double lat = coordinates.latitude( GeoDataCoordinates::Degree );
97  queryString = queryString.arg( lat, 0, 'f', 8).arg(lon, 0, 'f', 8 );
98  QByteArray output = d->retrieveWaypoints( queryString );
99 
100  GeoDataPlacemark placemark;
101  placemark.setCoordinate( coordinates );
102 
103  QStringList lines = QString::fromUtf8( output ).split( '\r' );
104  if ( lines.size() > 2 ) {
105  QStringList fields = lines.at( lines.size()-2 ).split(',');
106  if ( fields.size() >= 5 ) {
107  QString road = fields.last().trimmed();
108  placemark.setAddress( road );
109  GeoDataExtendedData extendedData;
110  extendedData.addValue( GeoDataData( "road", road ) );
111  placemark.setExtendedData( extendedData );
112  }
113  }
114 
115  emit reverseGeocodingFinished( coordinates, placemark );
116 }
117 
118 } // namespace Marble
GeoDataDocument.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::WaypointParser::RoadName
Definition: WaypointParser.h:33
QProcessEnvironment
QByteArray
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QList::at
const T & at(int i) const
Marble::GeoDataFeature::setExtendedData
void setExtendedData(const GeoDataExtendedData &extendedData)
Sets the ExtendedData of the feature.
Definition: GeoDataFeature.cpp:748
QProcessEnvironment::insert
void insert(const QString &name, const QString &value)
Marble::MarbleDirs::localPath
static QString localPath()
Definition: MarbleDirs.cpp:223
GeoDataExtendedData.h
Marble::GeoDataPlacemark::setCoordinate
void setCoordinate(qreal longitude, qreal latitude, qreal altitude=0, GeoDataCoordinates::Unit _unit=GeoDataCoordinates::Radian)
Set the coordinate of the placemark in longitude and latitude.
Definition: GeoDataPlacemark.cpp:215
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
InstructionTransformation.h
MarbleDebug.h
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::GeoDataExtendedData
a class which allows to add custom data to KML Feature.
Definition: GeoDataExtendedData.h:35
QList::size
int size() const
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QProcess
QObject
Marble::GosmoreRunner::~GosmoreRunner
~GosmoreRunner()
Definition: GosmoreReverseGeocodingRunner.cpp:81
MarbleDirs.h
Marble::GosmoreRunner::reverseGeocoding
virtual void reverseGeocoding(const GeoDataCoordinates &coordinates)
Start a reverse geocoding request.
Definition: GosmoreReverseGeocodingRunner.cpp:86
Marble::GosmoreRunner::GosmoreRunner
GosmoreRunner(QObject *parent=0)
Definition: GosmoreReverseGeocodingRunner.cpp:72
QString
WaypointParser.h
QStringList
GosmoreReverseGeocodingRunner.h
QFileInfo
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
QProcess::waitForStarted
bool waitForStarted(int msecs)
Marble::GeoDataFeature::setAddress
void setAddress(const QString &value)
Set the address of this feature to value.
Definition: GeoDataFeature.cpp:571
QDir
QProcess::setProcessEnvironment
void setProcessEnvironment(const QProcessEnvironment &environment)
Marble::GeoDataData
Definition: GeoDataData.h:26
Marble::GeoDataExtendedData::addValue
void addValue(const GeoDataData &data)
add a data object to the GeoDataExtendedData with the key
Definition: GeoDataExtendedData.cpp:71
Marble::RoutingWaypoint::Roundabout
Definition: RoutingWaypoint.h:31
QList::last
T & last()
Marble::ReverseGeocodingRunner
Definition: ReverseGeocodingRunner.h:25
RouteRequest.h
QProcessEnvironment::systemEnvironment
QProcessEnvironment systemEnvironment()
Marble::ReverseGeocodingRunner::reverseGeocodingFinished
void reverseGeocodingFinished(const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark)
Reverse geocoding is finished, result in the given placemark.
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) 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
QProcess::readAllStandardOutput
QByteArray readAllStandardOutput()
QProcess::start
void start(const QString &program, const QStringList &arguments, QFlags< QIODevice::OpenModeFlag > mode)
QProcess::waitForFinished
bool waitForFinished(int msecs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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