KISS

Keep It Simple Stupid

Aligning complex ways in JOSM

| comments

OpenStreetMaps is an outstanding project to create free and open maps of the entire world, created and updated by people. I’ve been improving OSM for several years, mostly doing small edits in the default editor iD. It’s a good and easy choice for the beginners. Recently I tried JOSM and it blew my mind! There is so much functionality there to make mapping faster, more correct and even more fun, including the support for plugins, presets and themes!

Today I’d like to share a guide on how I aligned a part of a polygon with another polyline consisting of a bunch of nodes. To help with the explanations, several screenshots and one screen recording are provided.

Note before we start: expert mode should be enabled in JOSM’s settings.

Initial setup

This is the initial state of the map (I hid the typical JOSM UI panels and made the window smaller than fullscreen to be free of distractions and have lighter images). The selected polygon (aka closed way) in red shows the relevant part of the area of a hotel. Red Sea is in the bottom-right corner and there is a polyline (aka way) of the shoreline; you can see a translucent blue shadow on its right side. Since the hotel owns that land, I want to expand the area up to the water to include the beaches, meaning the area should also follow the shoreline, and that fenced green area in the bottom-left corner.

This is the same area as on the first screenshot, but without the satellite imagery and with the unnecessary objects hidden. That is accomplished with the tourism=hotel or natural~"coastline|beach" or barrier=fence filter, enabling “Hiding” and “Inverse” options in the Filter Window:

More on filters: https://blog.mapbox.com/using-filters-in-josm-99a7415f6235 and https://josm.openstreetmap.de/wiki/Help/Dialog/Filter.

As you notice, that shoreline is not straight, but consists of about 60 nodes, so tracing it manually by clicking on every node in order to extend that hotel’s polygon would be too slow.

My plan:

  1. move existing bottom hotel’s nodes onto the future path and merge them with some nodes there;
  2. remove the bottom part of the polygon;
  3. draw a new polyline that follows the shoreline that I need;
  4. combine the top part of the hotel with the new polyline to close the polygon.

A geeky interlude

An .osm file (a data layer saved by JOSM) is an XML file, so one way to accomplish the task faster is to edit the file directly and copy/paste the nodes into the target way. But you need to be careful to know where which nodes should go. The relevant parts of my .osm file look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  <way id='25687905' >
    <nd ref='280068326' />
    <nd ref='280068145' />
    <nd ref='1077359337' />
    <nd ref='5500192026' />
    <nd ref='1077359265' />
    <nd ref='9205454246' />
    <nd ref='280068327' />
    <nd ref='280068147' />
    <nd ref='1077359302' />
    <nd ref='280068326' />
  </way>

  <way id='893884370' >
    <nd ref='7245733445' />
    <nd ref='7245737698' />
    <nd ref='7245733289' />
    <nd ref='7245732021' />
    <nd ref='7245732103' />
    <nd ref='7245733903' />
    <nd ref='7245735142' />
    <nd ref='7245739525' />
    <nd ref='7245734496' />
    <nd ref='7245738878' />
    <nd ref='7245699652' />
    <nd ref='7245732674' />
  <way />

Here you can copy and paste the node references from the second way to the first one at the correct place, reload the file in JOSM and it should work. However this post is about a more GUI-friendly way to do this.

Removing the bottom part

Back to JOSM. First I move the four bottom nodes to the coastline and merge them with some nodes there. In that case the hotel’s history is better preserved, but the coastline may be changed because a few of its nodes may be replaced with the historically hotel’s nodes; however this doesn’t guarantee that the hotel’s nodes will be preserved (as I initially thought):

The object id and object history of the oldest node with at least one parent will be preserved. If no parent object exists, the oldest node with lowest, positive id will be used (see #17866).

https://josm.openstreetmap.de/wiki/Help/Action/MergeNodes

So after moving the nodes, I click on each one and press m. I also move the bottom-left node of the hotel and merge it with the top node of the fence:

Alternative approach for the previous section

I started with this one on the first attempt, but then realized that the other approach would likely preserve the history better. Here I removed the four nodes along the beaches, they would be replaced by the existing nodes of the coastline. To do that, I picked the two “corner” nodes and pressed p to separate that bottom part into a new way.

JOSM asked me, “Which way segment should reuse the history of 25687905?” — this is an important dialog in this case because the bottom part has 6 nodes whereas the top one has only 5 nodes, so JOSM would pick the bottom one to save the history if I were not in expert mode (it’s a coincidence that I’d left it on and then noticed this dialog when splitting ways). This doesn’t make sense because I knew I’d remove that part, so I needed to select the top part to reuse the history. Then I picked the bottom part and deleted it.

Undo all this.

Drawing a small way

Now I select the two nodes between which I’ll need to insert all those coastline nodes…

… and press p. I need to make sure the history is reused by the top part of the area, which will stay as it is:

After this I can select the bottom part and remove it; note that some of its nodes will remain because they are attached to other ways.

I press Esc to remove selection. After pressing a, I can select the left node to continue it on top of the fence way — but JOSM doesn’t continue the hotel’s way, it starts a new way instead, probably because that starting node terminates two ways, so the editor doesn’t know which one to continue. No worries, I need a new way anyway. I click the nodes one by one to add them to the new way… and then it disappeared. Well, I need to update the show filter to include or new: tourism=hotel or natural~"coastline|beach" or barrier=fence or new.

Following lines

Now to the meat of the post! I noticed this “Follow line” menu item in “Tools” — that’s exactly what I need. The brief guide is at https://josm.openstreetmap.de/wiki/Help/Action/FollowLine. Also:

The menu item is shown in Expert mode only.

Hmm, the Expert mode is definitely worth it!

How it works is you need to enter the “Draw” mode by pressing a, add at least two adjacent points of an existing way to tell the “Follow line” where to go next, then press f to add one more point, press f to add another one, and so on. In fact, you can hold the f key to add more points very quickly! When one way ends and you need to continue with the next, click on the second way’s next point, then hold f again. See the screen recording on how I followed the coastline with for a new way:

After that I have all the parts, i.e. the three ways. Select them and press c to combine into a closed way.

Done! Now the area’s history contains a few dozens more nodes, but all of them are the existing ones (there are no nodes with negative ids).

The end

And finally, I need to upload the changes to the server. It’s a great practice to write good changeset comments (just like good commit messages), which is especially true for more complicated edits.

ps. Since it’s a post about an advanced usage of JOSM, I can recommend this document: Advanced Mapping Using JOSM by Missing Maps. I’ve learned about a couple of interesting plugins (building_tools, FastDraw), shortcuts (Ctrl+Shift to rotate an object, Shift+i to add nodes at intersections) and techniques (how to draw a building with a complex shape).

Comments