User:Moreati

From OpenStreetMap

Jump to: navigation, search

Hi,

I'm Alex Willmer. When I can I'm mapping Birmingham (map) and various Motorways.

I'm also interested in Open Source GIS.

I've written osm2pgsql.py, a python script to load OSM data into PostGIS.

To use osm2pgsql.py you will need:

  • Python
  • PyXML
  • A Postgresql instance with PostGIS
  • A dump of OpenStreetMap ala planet.osm

Follow these directions:

  • Download osm2pgsql.py, be sure to save the file as osm2pgsql.py.
  • Create the nodes and segments tables in your database, use eg psql or pgadmin3:
create table nodes(id int4 primary key);
select addgeometrycolumn('nodes','geom', 4326, 'POINT', 2);
create table segments (id int4 primary key, nfrom int4, nto int4);
select addgeometrycolumn('segments','geom', 4326, 'LINESTRING', 2);
  • Run the script passing the OSM dump on stdin, the DML will be presented on stdout:
cat planet.osm | python osm2pgsql.py > osm-planet.sql

Warning: this will take > 500MB of RAM and several minutes to complete

  • Pass the DML to psql to insert the data:
cat osm-planet.sql | psql [-h HOSTNAME] [-U USERNAME] [-d DBNAME]

This will take saveral minutes to complete

  • Create spatial indexes and analyze them:
create index segments_gidx on segments using gist(geom);
vacuum analyze segments geom;
create index nodes_gidx on nodes using gist(geom);
vacuum analyze segments geom;
  • View the tables in QGIS.
Personal tools
recent changes