Dear all,

I am new to GIS. I am working with OSM.PBF files for a country, which I downloaded from geofabrik.de. I have a list of nodes, identified by their corresponding coordinates which I would like to remove from the file - basically these nodes correspond to roads and I want to measure travel times for past periods, before these roads were build. If deleting nodes is too difficult, editing their tag to something like "avoid" should also do the trick. I would then like to save these edited files in OSM.PBF format (the program I am using in the next stage requires the files in this format).

Currently I am using Python to do this, but am a bit stuck. Would appreciate if somebody could point me to some samples of code editing tags of a node, or deleting nodes. Also, are there easier ways to do this than Python?

Thank you very much in advance! I can provide some more info if this is not very clear.

Ana

asked 29 Jan, 13:54

Ana%20Moura's gravatar image

Ana Moura
11114
accept rate: 0%


You cannot simply remove nodes as this would have undesirable consequences for the ways (roads) using these nodes. You will have to find the IDs of the ways you want to remove.

One possible option to remove certain ways from an .osm.pbf file is:

  • use osmium-tool to convert the .osm.pbf into a .opl file which is a plain text file containing one line for each way
  • use a text editor to remove the lines corresponding to ways you do not want (or alternatively, you could also add something like maxspeed=1 or access=no to make your routing engine disregard these roads). The line corresponding to OSM way 1234 will beginn with "w1234"
  • again with osmium-tool, convert the modified .opl file back into .osm.pbf
permanent link

answered 29 Jan, 14:30

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
70.9k826431106
accept rate: 24%

edited 29 Jan, 14:36

Thank you very much @Frederik Ramm, that makes a lot of sense! I will try to implement it. Just one follow-up question: is there a smart way to go from node coordinates to way IDs? I collected all these nodes that I wanted to remove. I understand that instead I should remove the ways that they compose. These are identified by an OSM ID but it is not straightforward to me how to obtain the ID. Thanks again!

(29 Jan, 16:33) Ana Moura

In the .opl file, for each way there will be a list of all the nodes it uses. This list looks like so: Nn1234,n2345,n3456 - so if you know you want to kick out the street that contains Node 12345, just use "grep" or your text editor's search function to identify the way that contains "n12345".

(29 Jan, 17:15) Frederik Ramm ♦
1

Osmium also has the handy "osmium getparents" command which allows you, among other things, to find all ways referencing some nodes. Of course, if you know Python, you can also use PyOsmium to do these things. This example: https://github.com/osmcode/pyosmium/blob/master/examples/filter_coastlines.py should give you some hints.

(30 Jan, 06:57) Jochen Topf
Your answer
toggle preview

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:

×155
×43
×3
×2

question asked: 29 Jan, 13:54

question was seen: 496 times

last updated: 30 Jan, 06:57

powered by OSQA