This is a step-by-step tutorial about how to use OpenStreetMap data in the popular open-source GIS application QGIS.
It assumes little familiarity with OpenStreetMap and none at all of QGIS.
Get some data
.osm file with the data you want.
This can be done in many different ways, but the most common in this scenario are:
- the export feature of the main OSM website. Browse to the map view you want (e.g.), click the 'Export' button at the top, and then the other 'Export' button at the left, and it will prompt you to save a
.osmfile. (There is a limit to the size of map you can export this way.)
- the built-in QGIS method: Vector (menu) → OpenStreetMap → Download Data…. This method requires you to know the extents of the region you want to map.
- using JOSM: download a layer as normal, and save it as a local file.
- Start QGIS Desktop.
- Go to: Vector (menu) → OpenStreetMap → Import Topology from XML.
- Select the
.osmfile, and it'll suggest a name for the SpatiaLite database that will be created from this data.
- The data will be copied into this database (which is just a single file database).
- At this stage, you should also elect to create a database connection after import. Close the importing window.
- In the data browser pane you'll now see one item under 'SpatiaLite'
- (if not, click the refresh button in that pane),
- and you'll have two files: a
.osm.dbin your working directory.
- Now convert this database to SpatiaLite:
- Vector (menu) → OpenStreetMap → Export Topology to SpatiaLite....
- Select the
.osm.dbfile as the 'Input DB file'
- Now, for each of the three types of geometry (to create three layers, one of each type):
- select the geometry type (points/nodes, polylines/open ways, or polygons/closed ways);
- get the list of available tags ('Load from DB' in the Exported tags section);
- and select all tags.
- Then click 'Ok' (note that the dialog window doesn't close between each of the above three steps).
Updating the data
Re-download using JOSM.
Re-import topology from XML, overwriting the existing
.db file as you do so.
Don't select to create a SpatiaLite connection after import.
Re-export topology to SpatiaLite, and for each of points, polylines, and polygons:
- Load from DB
- Select all tags
- Don't load the resultant layer onto the canvas (i.e. don't select 'Load into canvas when finished')
- click 'OK' to import
(If you get a 'duplicate column' warning, it is because there are two tags that are the same but differ in letter-case only, e.g. 'FIXME' and 'fixme'.)
.qgs project file can be shared as-is (and added to GitHub etc.)
because all references in it to the data are relative,
and so as long as it resides in the same directory as the
.db file everything will work
— regardless of what area of the planet you have data loaded for.