I have loaded some data from openstreetmap using osmosis and its pg_snapshot schema. This results in a table wayswhich contains a list of nodesreferenced by their ids:

select w.nodes from ways as w where w.tags->'railway'='rail' limit 1;

and in a separate table you have a geometry column for each node:

select st_astext(nodes.geom) from nodes where id = 358482292;
POINT(6.1253475 45.9259597)

My question what query could give me a LINESTRING for each way created from the node list?

2 Answers 2


When creating the database you want to apply the osmosis/script/pgsnapshot_schema_0.6_linestring.sql script before importing. This will cause osmosis to generate the linestrings. If you didn't do this before importing, it's possible to add a linestring column and use the SQL in the bulk load script to populate it, but this is very slow when operating on a full planet.


while creating the schema, one should execute:


to have a linestring for each way

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.