You will find the route relations in the planet_osm_line
table, with a negative osm_id field value corresponding to the OSM relation ID.
Once you have loaded the table, you can set a filter on the table with rightclick on the layer entry:
"osm_id" = '-51855'
to get only the trail you want, and then export the result to the format you want.
If you want a multiline out of it, perform Vector -> Geometry Tools -> Single part to Multipart
. The only thing that QGIS can not provide (yet) is a single continuos line out of the OSM data.
I was able to get this to work using the administrative boundaries dataset available here: https://mapzen.com/data/borders/
$ wget http://s3.amazonaws.com/osm-polygons.mapzen.com/planet_geojson.tgz
$ tar -zxvf planet_geojson.tgz
Since we want administrative level 2, use the file planet/admin_level_2.geojson
for the next steps.
To import the GeoJSON file into PostGIS, use the ogr2ogr
tool:
$ ogr2ogr -f "PostgreSQL" PG:"dbname=my_database user=postgres" "planet/admin_level_2.geojson"
To specify the destination table use -nln destination_table
. To append the data to an existing database use -append
.
By default, the data is imported into a table called ogrgeojson
, and the border geometry is contained in a field called wkb_geometry
.
To see this, connect to your database using psql
:
$ psql --host=<db host> --port=5432 --dbname=<db name> --username <username> --password
And run some queries:
gis_countries=> SELECT count(*) FROM ogrgeojson;
count
-------
367
(1 row)
gis_countries=> SELECT "name:en" FROM ogrgeojson WHERE ST_Contains("wkb_geometry", ST_GeometryFromText('POINT(-74.003334 40.741431)', 4326));
name:en
--------------------------
United States of America
(1 row)
Best Answer
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:
http://www.openstreetmap.org/api/0.6/relation/1027806/full
Vector -> Openstreetmap -> Import Topology from XML
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.