I am trying to import Polygons from OSM to QGIS 2.0, but so far I have no idea how to do that. E. g.: Kisterseg auf Tatabanya in HU: http://www.openstreetmap.org/?relation=1027806

Is there any fast way to get the polygon into qgis?

  • Have you tried the OSM Plugin? Sep 30 '13 at 9:46
  • The behavior of the OSM plugin in 2.xx is totally different from previous versions, I am too stucked on how to use the new osm integration of the vector menu. Sep 30 '13 at 22:16

Unfortunately, the new OSM import in QGIS 2.0 does not support multipolygon relations from OSM in an easy way. So you have to use a workaround:

  • load the relation from OSM database:


  • load the data in JOSM
  • Join the different parts of the border line (for your case 45 lines) to a single one. JOSM does this better than QGIS.
  • Save as .osm file and DO NOT UPLOAD THE DATA TO THE OSM SERVER on exiting JOSM.
  • Open the OSM file in QGIS with Vector -> Openstreetmap -> Import Topology from XML
  • Save as spatialite database with Vector -> Openstreetmap -> Export to Spatialite

selecting the database you created in the step before, and polygons for output.

If you want all border polygons from a country, you might be quicker with a postgis database filled with osm2pgsql. This will create polygons from multipolygon and border relations automatically. You can then load the data into QGIS.

  • Wouldn't spatialite_osm_map/spatialite_osm_raw (depending on preference for GIS-like or OSM-like relations) do the same in one step?
    – scruss
    Oct 5 '13 at 12:24
  • With spatialite_osm_map, I only get the bunch of lines, which QGIS can not make into a polygon; and spatialite_osm_raw only delivers points.
    – AndreJ
    Oct 5 '13 at 14:05
  • Ah, good point; closing polygons isn't done by spatialite_osm_*. Oh, for an osm2spatialite tool …
    – scruss
    Oct 6 '13 at 16:14

Use JOSM and load according relation id. JOSM allows to save as *.gpx which can be opened by QGIS

  • This will give you a bunch of lines, which QGIS might not be able to create a single polygon from. So better join the lines to a single one in JOSM before exporting.
    – AndreJ
    Oct 5 '13 at 12:21

Another alternative is to use OpenJump which, from the PLUS version 1.6.4, is able to read OpenStreeMap XML files natively using JOSM code for its OSM driver. From there export and import to QGIS is a trivial task.


Yet another way, this time using gdal:

  1. Download the relation data (as per André's guidance):
    curl -o Tatabányai_kistérség.osm http://www.openstreetmap.org/api/0.6/relation/1027806/full
  2. Import it into a temporary SpatiaLite database:
    ogr2ogr -f SQLite -dsco spatialite=yes Tatabányai_kistérség.sqlite Tatabányai_kistérség.osm --config OGR_SQLITE_SYNCHRONOUS OFF --config OSM_USE_CUSTOM_INDEXING NO
  3. Export the multipolygons layer from the database to a GeoJSON file:
    ogr2ogr -f GeoJSON -dsco spatialite=yes Tatabányai_kistérség.geojson Tatabányai_kistérség.sqlite -sql 'select * from multipolygons'

I chose GeoJSON as an output format as it can handle longer field names than a shape file. You might also want to modify your system's osmconf.ini if you need custom field mappings. This approach works with all of the data sets I've tried. It builds tidy polygons, and isn't troubled by ID issues like the old QGIS plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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