Loading OpenStreetMap data in QGIS?
Update for QGIS 3.x: The old OSM importer from QGIS 2 was dropped in QGIS 3 due to lots of unresolved bugs. The QuickOSM plugin also enables to read osm raw files. You can use user Layer - Add Layer - Add Vector Layer instead. In that case, OSM data are opened with GDAL as documented by http://gdal.org/drv_osm.html
In QGIS 2.x, There are 3 steps involved
- 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.
- 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.
- 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.
http://wiki.openstreetmap.org/wiki/QGIS#QGIS2_OpenStreetMap_Vectors
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: http://anitagraser.com/2014/05/31/a-guide-to-googlemaps-like-maps-with-osm-in-qgis/
Summary:
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:
- select all the lines where waterway=riverbank.
- 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.
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.