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.
|This tutorial is being written by some geogeeks from Perth, Western Australia at their fortnightly hacknights. Feel free to edit it (of course), and come to our next meeting if you are around!|
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.
Re-export topology to SpatiaLite, selecting all tags, and not loading the resultant layer onto the canvas (don't select "Load into canvas when finished").
(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.