JOSM script/action for combining loaded highways

This is an extension to this thread in search for a way to (semi automatically) combine highway pairs. Meanwhile I have been able to select not just pairs but complete sets of highways that can be combined.

Just to make things clear I will use 3 sets of highways for this example. One set with 2, one with 3 and one with 4 highways.

If I load these 3 sets (with 9 ways in total) in JOSM from this Overpass query I want to combine all ways in each set so that I am left with 3 sets each containing 1 way.

Is there a way to script this type of action? I have looked into the scripting plugin but I find this hard to understand.

So, yes you can script this. What I would recommend is to structure your script into three separate components:

  • Sourcing tasks
  • Resolving tasks to changes
  • Uploading changes

A task would be something abstract that needs to be done, in this case the task would be something like: MergeHighway

You can source these tasks using overpass or using a local OSM database. Then you add one or multiple tasks to a local changeset.

Next you need to resolve the tasks, meaning that you look at the input and return a list of all the changes (additions/modification and deletions) necessary for the completion of the task.

After that you can upload the changeset, you do this by sorting the changes. By node → way → relation and reverse for deletion.

Ideally you would validate the changeset making sure there are no changes in it that will not be accepted.

After sorting and validating you make a remote changeset and upload all changes. Making sure to replace the temporary ids for the real ids.

I have implemented such a process for my building import/update tool. And I have written that in C# .net core with OsmApiClient for the OSM API wrapper:

And OsmSharp:

For the processing.

But I would recommend you make something in a language that you are familiar with.

1 Like

Thanks for your answer. If I understand correctly you are suggesting to do something without using JOSM. My idea was that I provide local mappers a spreadsheet with sets of highways that can be merged (e.g. based on their municipality). See these 3 sets each with their own (fictive) set_id an osm_way_id.

set_id way_id
123787 7047948
123787 7047961
123787 1077687769
123787 1077687798
126492 7144144
126492 7144145
126492 7144146
221740 1093750578
221740 1158838826

These mappers can load lets say 20 of these sets in JOSM via Overpass query and check if it is a good idea (or not) to merge highways. See this video in which the 3 sets are merged in JOSM.

What I was looking for is a way to merge these sets automatically without having to select every set separately. Kind of a looping through sets. I was hoping for a JOSM plugin or something similar.

Another reason I want to use JOSM is to take advantage of it error handling. Although I am very confident the sets can be merged you never know wat might have happend to highways between my analysis and the actual time of uploading the changeset.