Sunday, December 18, 2011

The Most Interesting Mapper

The Most Interesting Mapper in the World


In case you live under a rock, this particular meme has its origins in a set of beer commercials that I find kind of amusing. Here is a decent compilation of them.

<sorry to interrupt this completely awesome post but quick note: This plugin has been turned into a core JOSM feature. See "Update 2" at the bottom of this post>

But seriously, the ImproveWayAccuracy plugin is a wonderful tool. Perhaps the prime use case to show it off is a smoothly curving road that was originally either mapped from low resolution imagery or (around here) imported from TIGER data that may have used far too few nodes to make a smooth curve. To fix this by hand is highly annoying. You have to drag nodes around and then grab the + between two existing nodes to create a new one and drag it to where you want it, repeating that as often as needed to achieve a smooth enough curve. Each node requires several precise mouse movements. 

It is much easier to draw a way from scratch where you just move your mouse along the curve and click as needed to form a smooth looking curve. Well, the ImproveWayAccuracy plugin makes this possible to do with existing nodes/ways!

For basic usage you can look at the plugin's wiki page: http://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImproveWayAccuracy

The first thing you will want to do after installing the plugin is to change JOSM's "highlight" color to something that has a high contrast to whatever the "selected" color is. By default they are both shades of red which makes the plugin harder to use. I changed mine to a bright green (#66FF33). 

Basically you activate the plugin by pressing k and selecting a way. Then if you move the mouse around you will see that the node that is closest to your mouse cursor is highlighted and there are temporary lines going from your cursor to the two nodes next to that one. If you click, the highlighted node will be moved to your cursor's current location. It is kind of hard to describe but pretty easy to get the hang of if you try it.

Holding down CTRL and clicking will add a new node to the way between the two nearest nodes. Holding down SHIFT will lock the node selection to the current node even if you move the mouse so that another node is now closer to the cursor. This can be helpful while trying to fix some weird geometries.

Here is a short clip of me aligning and smoothing out a curve using this plugin. You can tell when I am holding down CTRL because the cursor gets a small + symbol added to it:


Now... I do have one beef with this plugin. The wiki page states that deleting nodes is not a feature and that you should re-use nodes whenever possible. While I generally agree that as much history as possible should be preserved while editing, it is not always practical. Especially with the TIGER imports that I am frequently editing. Sometimes imported ways have too many nodes along them. This makes editing them more of a pain and the correct way to handle it really is to delete nodes.

Of course the source code for this plugin is available in the OSM SVN repository (see here) so I hacked this feature in myself. Just like the CTRL key adds nodes to the way, the ALT key removes them in my version. However it performs a sanity checks first. If you try to delete a node that is a member of two different ways (a junction node) then the plugin will throw up an error message. The ImproveWayAccuracy plugin is only intended to modify the geometry of a way. If you want to change the topology of the data, you should not be in the IWA mode. 

One gotacha: Some linux window managers use ALT plus a mouse drag to move windows. So my window manager was swallowing my ALT+click event and it never got passed on to JOSM so the plugin just didn't do anything. But I don't use ALT+drag to move my windows around so I just disabled it. I looked at trying to use a different key but the way the existing code was written, it was easiest to just use another meta key and since CTRL and SHIFT were already taken... I guess I could have maybe used CTRL+SHIFT.

Update: Turns out window managers only listen for the left ALT key but JOSM will take the left or right one. So you can use the meta keys on the right side of the keyboard without problems. Oh and CTRL+SHIFT is already used by the plugin although I have never actually used this feature.

If you want to use my version of the plugin, the easiest way is to first install the "official" plugin through the JOSM plugin options. Then close JOSM and copy my ImproveWayAccuracy.jar file over the one in the JOSM plugin directory (~/.josm/plugins/ on linux or C:\Documents and Settings\<username>\Application Data\JOSM\plugins\ on windows) You can download the jar file here. Or if you want to see the code, here is the svn diff for the IWAMode.java file. (as of revision 27186)

I submitted the patch to the original author of the plugin so at some point this might get rolled in to the real plugin. But he said he is very busy right now and probably won't get a chance to look at it any time soon. So I decided to just put it out there in this form for now. The only problem is that letting JOSM update plugins may overwrite the custom .jar file in the future.

Update: I submitted a patch to the JOSM trac system. There was some discussion about keys and other checks to do before deleting nodes. But at the end of the day my changes (plus a tweak or two) have been incorporated into the live code and a new version of the plugin has been released. So just update your plugins and you will be able to take advantage of this feature!

Update 2: Turns out, this code is useful! The JOSM developers saw fit to pull this functionality into JOSM core. They even rearranged some keyboard shortcuts to make room for it on W instead of K. So no more plugin required. Just hit "W" and go! You can see the discussion in ticket #7184 over on the JOSM trac.

Enjoy.

No comments:

Post a Comment