Difference between revisions of "Projects/Marble/Runners/LoadingOSM"

Jump to: navigation, search
 
Line 7: Line 7:
 
pre=[[Projects/Marble/Runners/LoadingKML|Tutorial 4 - Changing basic map properties]]|
 
pre=[[Projects/Marble/Runners/LoadingKML|Tutorial 4 - Changing basic map properties]]|
  
next=[[Projects/Marble/Runners/DisplayGeoDataPlacemarks|Tutorial 6 - Displaying places the proper way(via GeoDataDocument)]]|  
+
next=[[Projects/Marble/Runners/DisplayGeoDataPlacemark|Tutorial 6 - Displaying places the proper way(via GeoDataDocument)]]|  
 
}}
 
}}
  

Latest revision as of 17:05, 13 January 2013

Loading OSM files in MarbleWidget
Tutorial Series   Marble C++ Tutorial
Previous   Tutorial 4 - Changing basic map properties
What's Next   Tutorial 6 - Displaying places the proper way(via GeoDataDocument)
Further Reading   n/a

[edit] Exporting OSM

Osm files can be used for creating small street maps or can be scaled to store streets worldwide. OSM files can be exported from OpenStreetMaps by clicking the export button as shown below.


OsmTutorial.png


[edit] Loading OSM files into a Marble Widget

Marble uses so-called runners to calculate routes, do reverse geocoding, parse files and search for placemarks (cities, addresses, points of interest, ...). This tutorial shows how to open a .osm file and display it into the Marble Widget.

#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtGui/QApplication>
 
#include <marble/MarbleWidget.h>
#include <marble/MarbleModel.h>
 
using namespace Marble;
 
int main(int argc, char** argv)
{
    QApplication app(argc,argv);
 
    QFileInfo inputFile( app.arguments().last() );
    if ( app.arguments().size() < 2 || !inputFile.exists() ) {
        qWarning() << "Usage: " << app.arguments().first() << "file.osm";
        return 1;
    }
 
    MarbleWidget *mapWidget = new MarbleWidget();
    mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
 
    mapWidget->centerOn( GeoDataCoordinates( 77.5674, 12.9782, 0, GeoDataCoordinates::Degree ) );
    mapWidget->zoomView( 3000 );
 
    mapWidget->model()->addGeoDataFile( inputFile.absoluteFilePath() );
 
    mapWidget->show();
 
    return app.exec();
}

Copy and paste the code above into a text editor. Then save it as my_marble.cpp and compile it by entering the following command on the command line:

 g++ -I /usr/include/qt4/ -o my_marble my_marble.cpp -lmarblewidget -lQtGui -lQtCore

If things go fine, execute ./my_marble some-file.osm and you get a Marble Widget which displays your OSM file. For example, download and unpack Map.osm (a LinearRing representing Bangalore city junction), place it in the same folder as your my_marble.cpp file and run ./my_marble map.osm. The result should be similar to this:


OsmTutorial1.png


The placemarks on the map are clickable and trigger a dialog. The screenshot below is of the dialog of Bangalore City Station triggered by clicking it on the map.


OsmTutorial2.png


noframe
 
Note
If you provide maps in your application please check the Terms of Use of the map material. The map material that is shipped with Marble is licensed in the spirit of Free Software. This usually means at least that the authors should be credited and that the license is mentioned. E.g. for OpenStreetMap the license is CC-BY-SA. Other map data shipped with Marble is either public domain or licensed in the spirit of the BSD license.

This page was last modified on 13 January 2013, at 17:05. This page has been accessed 2,595 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal