QGIS tutorial

From OpenStreetMap Wiki
Jump to navigation Jump to search

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.

information sign

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

Get an .osm file with the data you want.

This can be done in many different ways, but the most common in this scenario are:

  1. 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 .osm file. (There is a limit to the size of map you can export this way.)
  2. the built-in QGIS method: Vector (menu) → OpenStreetMapDownload Data…. This method requires you to know the extents of the region you want to map.
  3. using JOSM: download a layer as normal, and save it as a local file.

Import data

  1. Start QGIS Desktop.
  2. Go to: Vector (menu) → OpenStreetMapImport Topology from XML.
  3. Select the .osm file, 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.
  4. 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 and a .osm.db in your working directory.
  5. Now convert this database to SpatiaLite:
    1. Vector (menu) → OpenStreetMapExport Topology to SpatiaLite....
    2. Select the .osm.db file as the 'Input DB file'
  6. Now, for each of the three types of geometry (to create three layers, one of each type):
    1. select the geometry type (points/nodes, polylines/open ways, or polygons/closed ways);
    2. get the list of available tags ('Load from DB' in the Exported tags section);
    3. and select all tags.
    4. Then click 'Ok' (note that the dialog window doesn't close between each of the above three steps).

Cartography

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:

  1. Load from DB
  2. Select all tags
  3. Don't load the resultant layer onto the canvas (i.e. don't select 'Load into canvas when finished')
  4. 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'.)

Sharing

The .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.