Can I edit the OSM ID in JOSM?

I’m importing building outlines into OSM through JOSM by opening a GeoJSON file, deleting any old overlapping buildings from OSM, merging the layers and uploading. If there’s already a building outline for some outline, I would like to replace it with the new outline but I want the new outline to keep the same way OSM ID to preserve history.

Do we have the technology to do this?

as I understand it, this should be possible using utilsplugin2 “Replace Geometry” tool: JOSM/Plugins/utilsplugin2 - OpenStreetMap Wiki

edit to quote from the wiki to explain the functionality:

Replace geometry (Ctrl+Shift+G)

Substitutes the geometry of one object for another retaining as much metadata and history as possible. There are currently two supported modes:

Replace one way with another way

In some cases it may be faster or more convenient to draw a new way rather than adjust the existing one, but you want to retain the history. Some or all nodes of the old way are moved to positions of the new ones, and some nodes are transferred between ways. Then the new way is deleted, having played its role. This is done to preserve way and node history as much as possible. For example:

  1. Choose a poorly drawn way in OSM database that you want to fix.
  2. Draw a new way, neat and correct, with all the correct angles.
  3. Select both ways.
  4. Use Replace geometry action. This transfers tags & history of the old way to the new way and as much as possible re-uses the nodes of the old way.
  5. After uploading to OSM, it will appear as if the old object was simply adjusted a bit, rather than entirely replaced.

the history diff in JOSM (before uploading) then looks like this:

the OSM way is still the old one, all its nodes were reused (in this case it was possible), nodes were added and reordered within the way

1 Like

But AFAIK, that would also erase the old history?

I don’t think there’s any way of replacing buildings while keeping history, which is why they usually say to just modify the old outlines if they overlap.

1 Like

The “Replace Geometry” function in JOSM mentioned by @Jarek will definitely keep history on the building polygon. That is the way to go if updating a building by importing. Even for hand editing I sometimes find it is just easier to draw a new outline then use the replace geometry function to move the tags and history to my new outline and remove the old outline.

Also, if you have a situation where the object is a single node, maybe with just an address, and you do a replace geometry to move the tags to the new outline polygon it will actually use that old single node as one on the polygon to retain the history.

3 Likes

Is it possible to do it in the GeoJSON file? Like if it has a column like @id or something, will JOSM use that as the ID?

I tried downloading some data as GeoJSON from overpass-turbo.eu and opening it with JOSM and it didn’t work. I can see the @id column, but if I inspect the way with Ctrl-i it has a negative ID, meaning would be uploaded as a new element.

This doesn’t really answer your question about GeoJSON, but if all you are doing is downloading stuff from Overpass, you can just do it directly in JOSM (“Download from Overpass API” tab of the Download dialog) and then it’ll have the OSM IDs.

Another way to do the “edit the OSM ID” could be to save the data from JOSM as an .osm file, edit it manually (it’s XML), then reopen in JOSM. But I presume you would have to be very careful about not breaking history when subsequently uploading that

1 Like

I would note that you should try to retain the history of the nodes too (as far as possible) and trying to do that manually is going to be impractical.

2 Likes

The answer to my underlying question of how to Replace Geometry efficiently when importing data is JOSM’s conflation plugin

https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Conflation