NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hello,

I have a big osm file and I have the ids of 430 relations (in a text file) and I want to extract the data related to them from the osm file (I understand the hierarchy ( x relation -> x.y0, x.y1...x.yn ways -> x.y[0...n].z[0...t] nodes )) to make my osm file smaller.

But I don't know where to begin ? I think that I need to import the osm file into postgis and then run queries ? I thought also to use the openstreetmap API and queries for each relations their ways and ... queries for each ways their nodes ... Then merge all of it. But it isn't very powerful...

Is there a better way to create my custom osm file ?

Thanks for your help, best regards,

asked 06 Mar '16, 15:40

syskaw's gravatar image

syskaw
21112
accept rate: 0%

edited 06 Mar '16, 15:42


You can use the osmium command line tool for this. The "add-refs" subcommand does what you need. You'll have to use the master version from github, the released versions don't have this command yet. Use it like this:

osmium add-refs -s large-osm-file.osm.pbf -i relation-ids -o extract.osm.pbf

with relation-ids file containing one relation id per line preceded by the letter 'r'.

permanent link

answered 07 Mar '16, 21:11

Jochen%20Topf's gravatar image

Jochen Topf
5.2k55074
accept rate: 31%

it works like a charm, thanks you :)

(08 Mar '16, 00:49) syskaw

You should not use the OpenStreetMap api to fetch the relations.

It may work to fetch them from Overpass API. It's possible to query by object id, so you could use something like

(
rel(firstid);
rel(secondid);
);
(._;>;);
out meta;

(look at the Overpass QL documentation for more information, especially the sections on "Union" and "By Element Id")

I'm not sure that it would be acceptable to query so many relations, if they are large, the query would have a large result.

Another approach that doesn't need a database is to use whatever programming tools you are familiar with to read through the large file 3 times. The first time, when you encounter a desired relation, extract it and also make a list of the ways that are members of the relation. The second time, extract the list of ways and make a list of the nodes that are members. The third time, extract the list of nodes.

permanent link

answered 06 Mar '16, 16:28

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×290
×236
×134

question asked: 06 Mar '16, 15:40

question was seen: 3,960 times

last updated: 08 Mar '16, 00:49

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum