[Marble-commits] KDE/kdeedu/marble/src/plugins/runner/gosmore

Dennis Nienhüser earthwings at gentoo.org
Tue Aug 24 11:57:57 CEST 2010


SVN commit 1167304 by nienhueser:

Offline reverse geocoding support (road name only) using a trivial (src=dest) route request.

 M  +1 -1      GosmorePlugin.cpp  
 M  +37 -8     GosmoreRunner.cpp  
 M  +3 -0      GosmoreRunner.h  


--- trunk/KDE/kdeedu/marble/src/plugins/runner/gosmore/GosmorePlugin.cpp #1167303:1167304
@@ -16,7 +16,7 @@
 
 GosmorePlugin::GosmorePlugin( QObject *parent ) : RunnerPlugin( parent )
 {
-    setCapabilities( Routing );
+    setCapabilities( ReverseGeocoding | Routing );
     setSupportedCelestialBodies( QStringList() << "earth" );
     setCanWorkOffline( true );
     setName( tr( "Gosmore" ) );
--- trunk/KDE/kdeedu/marble/src/plugins/runner/gosmore/GosmoreRunner.cpp #1167303:1167304
@@ -14,6 +14,7 @@
 #include "MarbleDirs.h"
 #include "routing/RouteSkeleton.h"
 #include "GeoDataDocument.h"
+#include "GeoDataExtendedData.h"
 
 #include <QtCore/QProcess>
 #include <QtCore/QMap>
@@ -26,7 +27,7 @@
 public:
     QFileInfo m_gosmoreMapFile;
 
-    GeoDataLineString retrieveWaypoints( const QString &query ) const;
+    QByteArray retrieveWaypoints( const QString &query ) const;
 
     GeoDataDocument* createDocument( GeoDataLineString* routeWaypoints ) const;
 
@@ -35,10 +36,10 @@
     void merge( GeoDataLineString* one, const GeoDataLineString& two ) const;
 
     /** Static to share the cache among all instances */
-    static QMap<QString, GeoDataLineString> m_partialRoutes;
+    static QMap<QString, QByteArray> m_partialRoutes;
 };
 
-QMap<QString, GeoDataLineString> GosmoreRunnerPrivate::m_partialRoutes;
+QMap<QString, QByteArray> GosmoreRunnerPrivate::m_partialRoutes;
 
 void GosmoreRunnerPrivate::merge( GeoDataLineString* one, const GeoDataLineString& two ) const
 {
@@ -51,7 +52,7 @@
     }
 }
 
-GeoDataLineString GosmoreRunnerPrivate::retrieveWaypoints( const QString &query ) const
+QByteArray GosmoreRunnerPrivate::retrieveWaypoints( const QString &query ) const
 {
     if ( m_partialRoutes.contains(query) ) {
         return m_partialRoutes[query];
@@ -66,18 +67,18 @@
     gosmore.start("gosmore", QStringList() << m_gosmoreMapFile.absoluteFilePath() );
     if (!gosmore.waitForStarted(5000)) {
         mDebug() << "Couldn't start gosmore from the current PATH. Install it to retrieve routing results from gosmore.";
-        return GeoDataLineString();
+        return QByteArray();
     }
 
     if ( gosmore.waitForFinished(15000) ) {
-        m_partialRoutes[query] = parseGosmoreOutput( gosmore.readAllStandardOutput() );
+        m_partialRoutes[query] = gosmore.readAllStandardOutput();
         return m_partialRoutes[query];
     }
     else {
         mDebug() << "Couldn't stop gosmore";
     }
 
-    return GeoDataLineString();
+    return QByteArray();
 }
 
 GeoDataLineString GosmoreRunnerPrivate::parseGosmoreOutput( const QByteArray &content ) const
@@ -162,11 +163,39 @@
         double tLat = destination.latitude( GeoDataCoordinates::Degree );
         queryString = queryString.arg(tLat, 0, 'f', 8).arg(tLon, 0, 'f', 8);
 
-        d->merge( wayPoints, d->retrieveWaypoints( queryString ) );
+        d->merge( wayPoints, d->parseGosmoreOutput( d->retrieveWaypoints( queryString ) ) );
     }
 
     GeoDataDocument* result = d->createDocument( wayPoints );
     emit routeCalculated( result );
 }
 
+void GosmoreRunner::reverseGeocoding( const GeoDataCoordinates &coordinates )
+{
+    QString queryString = "flat=%1&flon=%2&tlat=%1&tlon=%2&fastest=1&v=motorcar";
+    double lon = coordinates.longitude( GeoDataCoordinates::Degree );
+    double lat = coordinates.latitude( GeoDataCoordinates::Degree );
+    queryString = queryString.arg( lat, 0, 'f', 8).arg(lon, 0, 'f', 8 );
+    QByteArray output = d->retrieveWaypoints( queryString );
+
+    GeoDataPlacemark placemark;
+    placemark.setCoordinate( GeoDataPoint( coordinates ) );
+
+    QStringList lines = QString::fromUtf8( output ).split( '\r' );
+    if ( lines.size() > 2 ) {
+        QStringList fields = lines.at( lines.size()-2 ).split(',');
+        if ( fields.size() >= 5 ) {
+            QString road = fields.last();
+            placemark.setAddress( road );
+            GeoDataExtendedData extendedData;
+            GeoDataData data;
+            data.setValue( road );
+            extendedData.addValue( "road", data );
+            placemark.setExtendedData( extendedData );
+        }
+    }
+
+    emit reverseGeocodingFinished( coordinates, placemark );
+}
+
 } // namespace Marble
--- trunk/KDE/kdeedu/marble/src/plugins/runner/gosmore/GosmoreRunner.h #1167303:1167304
@@ -33,6 +33,9 @@
     // Overriding MarbleAbstractRunner
     virtual void retrieveRoute( RouteSkeleton *skeleton );
 
+    // Overriding MarbleAbstractRunner
+    virtual void reverseGeocoding( const GeoDataCoordinates &coordinates );
+
 private:
     GosmoreRunnerPrivate* const d;
 };


More information about the Marble-commits mailing list