Importing Planet.osm into QGIS
From OpenStreetMap
| | Software described on this page or in this section is unlikely to be compatible with API version 0.5 deployed on 8 October, 2007. If you have fixed the software, or concluded that this notice does not apply, remove it. |
Converting OSM to GML has a script that can convert API 0.5 data to GML, which can then be imported into QGIS
The easiest way to import the planet.osm into QGIS is to convert it into mapinfo format. It is very simple and does not require any bizarre tools. Parsing the tags and splitting into the layers is left as an exercise for the reader. If the layers are split, then you can produce the "point" and "linestring" shapefiles with ogr2ogr:
ogr2ogr -f "esri shapefile" nodes.shp nodes.mif ogr2ogr -f "esri shapefile" segments.shp segments.mif
#!/bin/bash
awk -F\" 'BEGIN{
i=-1;j=-1;
system("rm -f planet.mi?");
printf("version 300\ncharset \"utf-8\"\n\
coordsys earth projection 1, 104\n\
delimiter \",\"\n\
columns 1\n\
cat integer\n\
data\n") >"planet.mif";
}
{
if ($1 == " <node id=")
{
nodes[i++]=$2; nodelat[$2]=$4;
nodelon[$2]=$6;
}
if ($1 == " <segment id=")
{
seg[j++]=$2; seg_start[j]=$4;
seg_end[j]=$6;
}
}
END{
for(k=0;k<i;k++)
{
print "point",nodelat[nodes[k]],nodelon[nodes[k]] >>"planet.mif"
print nodes[k] >> "planet.mid"
}
for(k=0;k<j;k++)
{
print "line",nodelon[seg_start[k]],nodelat[seg_start[k]],nodelon[seg_end[k]],nodelat[seg_end[k]]>>"planet.mif"
print seg[k] >> "planet.mid"
}
}' planet.osm
This recipe from a posting to the talk list by Johnny Doe on April 15, 2006.
Warning: This script will eat all your memory. If you can provide a script that does not use more memory when the dataset becomes larger, please post it here.
alternative version in perl
I wrote this version to convert the osm-data to an mif-file for usage this in Oziexplorer. Try this version with "./convert_osm2mif data.osm > data.mif" .
#!/usr/bin/perl
# Filename convert_osm2mif
print "version 300
charset \"utf-8\"
coordsys earth projection 1, 104
delimiter \",\"
columns 1
cat integer
data\n";
my $p=1000000;
while (<>) {
$line = $_;
chomp($line);
if ($line =~ /<node id=["'](.*?)["'].*?lat=["'](.*?)["'].*?lon=["'](.*?)["']/) {
$lat{ $1 +$p} = $2;
$lon{ $1 +$p} = $3;
} elsif ($line =~ /<segment id=["'](.*?)["'].*?from=["'](.*?)["'].*?to=["'](.*?)["']/) {
printf "line %f %f %f %f \n" ,$lon{$2+$p} ,$lat{$2+$p} ,$lon{$3+$p} ,$lat{$3+$p};
}
}

