Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In QGIS 1.8 I used the openstreetmap plugin to request data from the server, or open a .osm XML file, which produced 3 layers (polygons, polylines and points) in QGIS. This was great (give or take the 64bit bug which highly affects the freshly mapped area I work on), but how do I do that in QGIS 2.x? I can't find any updated documentation about it.

In the vector menu, I've tried importing from osm servers, I get a .osm file, but then I'm stuck. There's a menu option for loading an XML file, but it produces a spatialite db, which apparently only has non-geometry tables when I try to add it as a spatialite layer. If I open the attribute table, I can see node ids, ways and so on, but I can't figure out how to actually make use of them.

I've also tried adding a vector layer from a .osm XML file. I get a gpsbabel window that shows nothing, then finally an invalid data source message in QGIS.

What am I doing wrong? Any pointers to updated documentation?


PS: I know there are a few questions around this subject, but none of them actually seems to answer the question.

share|improve this question
This OSM plugin worked perfectly in the previous version of QGIS. This is a classic example of try to improve a feature that worked fine.. – user23102 Oct 20 '13 at 21:58
Actually, no, it didn't work fine. It couldn't handle node IDs greater than a 32-bit signed integer. – scruss Oct 20 '13 at 23:08
Would someone make a step-by-step instructions (for the beginner) on how to get .osm file open with QGIS 2.2.0-valmiera? This seems to be bit too challengin to do 1st time in my life.I have no previous QGIS experience. – user28703 Apr 1 '14 at 12:10
It works in QGIS 2.2 the same way as in QGIS 2.0. Please follow the instructions in the answer, and ask a new queston if you get stuck somewhere. – AndreJ Apr 1 '14 at 12:14
Tom, I wrote a step-by-step instructions to get the OSM data in a QGIS. Hope this is simple to follow for beginners. – spatialthoughts Apr 14 '14 at 15:43
up vote 29 down vote accepted

In Qgis 2.0, There are 3 steps involved

  1. Get an OSM File, you can get it using josm or overpass or any other source. It has to be a valid xml. You can also download it from qgis Vector > OpenStreetMap > Download OSM Data menu, but sometimes it does not give result. I would recommend using overpass turbo.
  2. Vector > OpenStreetMap > Import Topology from XML, this as you said will produce a spatialite database with non-geometry tables. This i think is the topology.
  3. Finally, you can get data by Vector > OpenStreetMap > Export Topology to Spatialite, here you need to give the db file made above and just like in qgis 1.8 you will have option to choose points, lines or polygons. Below that in exported tags section you can load all the tags contained in the file and select only those which you require. This is additional feature than in 1.8.

The layer gets added to map, if you want all nodes, ways you can repeat step 3 with other options.

share|improve this answer
This feels incredibly complicated, but it does work. For the sake of clarity, after step 3, you still need to add a spatialite layer, connect to the db you created, and choose the layer(s) created in step 3 to finally see the result. Thanks for your help! – Laurent S Oct 4 '13 at 6:18
For me, the layers were automatically created and added. The connection to the database was established in step 2 (unless you unchecked it). – AndreJ Oct 5 '13 at 12:40
surprisingly it works that way too. Looks like osm is converted to gpx using gpsbabel. The attributes get messed up though, only gpx fields show up on attribute table. – neogeomat Oct 5 '13 at 14:24
Strangely enough, it looks like the behaviour is different on linux and windows. Layers were created automatically on linux for me too, but not on my windows box... – Laurent S Oct 6 '13 at 8:27
It worked for me in windows. – neogeomat Oct 6 '13 at 13:14

I found downloading OSM data using the plugin and going through the import and export motions very tedious. That's why I wrote up a different solution:


Raw OSM files can be quite huge. That’s why it’s definitely preferable to download the compressed binary .pbf format instead of the XML .osm format. As a download source, I’d recommend Geofabrik.

For the first preprocessing step: extracting the area of interest, we can use Osmosis:

C:\Users\anita_000\Geodata\OSM_Noirmoutier>..\bin\osmosis.bat --read-pbf pays-de-la-loire-latest.osm.pbf --bounding-box left=-2.59 bottom=46.58 right=-1.44 top=47.07 --write-xml noirmoutier.osm

While QGIS can also load .osm files, I found that performance and access to attributes is much improved if the .osm file is converted to spatialite.

C:\Users\anita_000\Geodata\OSM_Noirmoutier>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES noirmoutier.db noirmoutier.osm

In QGIS, we can load the points, lines, and multipolygons using Add SpatiaLite Layer. When we load the spatialite tables, there are some issues:

  • There is no land polygon. Instead, there are “coastline” line features.
  • Most river polygons are missing. Instead there are “riverbank” line features.

Creating the missing river polygons is not a big deal:

  1. select all the lines where waterway=riverbank.
  2. use the Polygonize tool from the processing toolbox to automatically create polygons from the areas enclosed by the selected riverbank lines. (Note that Processing by default operates only on the selected features but this setting can be changed in the Processing settings.)

Creating the land polygon (or sea polygon if you prefer that for some reason) is a little more involved since most of the time the coastline will not be closed for the simple reason that we are often cutting a piece of land out of the main continent. Therefore, before we can use the Polygonize tools, we have to close the area. To do that, I suggest to first select the coastline using "other_tags" LIKE '%"natural"=>"coastline"%' and create a new layer from this selection (save selection as …) and edit it (don’t forget to enable snapping!) to add lines to close the area. Then polygonize.

share|improve this answer
If you're running a fairly reliable computer, and you want the ogr2ogr stage to complete before the next ice age, add --config OGR_SQLITE_SYNCHRONOUS OFF. – scruss Nov 8 '14 at 12:49
How do you know the bounding box? Is there a quick way to read it (better: copy it) from your QGIS view? Many thanks – Dakatine Apr 29 '15 at 12:36

If you don't like the plugin, fetch the OSM data you need with Overpass API, and add the result to QGIS with Add Vector Layer (enabeling All files filter).

QGIS 2.0 uses GDAL 1.10's ogr2ogr OSM importer which does a good job.

Relation support seems to be better than the plugin does at the moment.

Just make sure you download ways and relations completely, that is all nodes of the ways, and all members of the relations, with all their nodes.

share|improve this answer

You know, you don't need to put the data into SpatialLite. You can just:

1) Download the data (Vector > OpenStreetMap > Download Data, creates an .osm file)

2) Load the data (.osm file) as a vector layer (Layer > Add Vector Layer). After you select the file, it'll ask you which layers you want to add (as GDAL makes separate files for each type: Point, Line, MultiLine, MultiPolygon, GeomCollection). Select what you want and load it up.

share|improve this answer
This works in some way, but it doesn't seem to separate layers based on tags. So basically roads and rivers end up in the same Line layer, which isn't really helpful if you want to run analysis on the resulting data. – Laurent S Apr 1 '14 at 19:55
It wasn't clear from your question what you were doing with the data once it was imported. You can of course select out whatever features you want from the data within QGIS. As mentioned above, if you know you only want certain data (and it's not in too large an area), downloading data with Overpass would probably be better, as you can pre-select for just certain features. I find Overpass Turbo to be a user friendly way to develop queries. Here's an example of all highways in bounding box: – neuhausr Apr 2 '14 at 14:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.