Quality control with Python script in JOSM
Why
Since Fietsnet.be announced they wanted to start using our data for their routing utility, I started to have a look at what we have and I started to think about how fragile it all is.
Contributors can remove ways, which were part of routes and not readd the way they (or somebody else) put(s) in instead. Or they can (re)combine ways that were split before, which results in 'overshoots', if one of those wasn't already part of the route relation.
If you want to do routing on the ways of a route relation, it is probably helpful to have a continuous string of ways.
So I created a Python script, which runs in JOSM (so technically it's Jython, since JOSM is written in JAVA), which can be run at regular intervals to do some quality control.
This same script also helps while preparing a network relation to be ready for the end goal of performing this QC.
Where (to find the latest version of the script)
CheckRouteOrNetworkOrCollectionOfRoutes.jy
How
You need to install the scripting plugin in JOSM:
Instructions for installing the scripting plugin
Then you also need to download [Jython http://www.jython.org/], install it and refer the scripting plugin to its .jar file
Then restart JOSM and there should be a new menu item 'scripting'. Select "Show scripting console" and load the text file with the code with File/Open.
So what are the steps involved in using the script?
First you have to decide what you want to let the script do for you and what you prefer to do manually.
This can be achieved by changing the sideEffects variable. Simply put # in front of the lines that seem to be doing something terrible.
It's probably best to set it more or less as follows:
sideEffects = {
'addRouteToNetwork': None, 'removeNameRefKey_xx-yyAndcreated_by': None, 'modifyNoteTo_xx-yy': None, 'flipOrderOfMembers': None, # such that ways go from lower rcn_ref to higher rcn_ref 'sortRouteRelations': None, 'selectObjects': None, 'zoomToSelection': None, #'downloadReferrersForNodes': None, # This will download all ways and relations for nodes with an rcn_ref #'downloadReferrersForWays': None, # This will download all relations for ways that have an endnode with an rcn_ref #'downloadIncompleteMembers': None, 'createWikiReport': None, #'createGarminGPX': None, # not implemented yet #'checkOneWays = False, # not implemented yet }
Never mind the ": None," Lookups in a dictionary are the quickest in Python and this dictionary variable is used a lot in the script.
You need to download the whole network in JOSM before using the script to get useful results. The easiest is to make an overpass query using the mirrored_downloads plugin that adds the File > Download from Overpass API command.
The overpass query should be something like this :
( relation["name"="Name_of_the_rcn_network_to_download"]; node(r)->.nodes; rel(r); way(r); node(w); ); out meta;
This query will download all the members, networks, routes and nodes pertaining to the specified rcn.
Alternativelay, you may follow the manual way :
Go and find a node of the cycle node network, one tagged with an rcn_ref, preferably a member of a network relation tagged with network=rcn. RMB (right mouse button) Download incomplete members. Now select the network relation and RMB Select members. Select all the route relations in the Selection pane and RMB Download incomplete members.
Select the network relation and press Ctrl+F: o Find in selection, type:node rcn_ref
File/Download parent ways/relations
Ctrl+F: o Replace selection, parent selected
File/Download parent ways/relations
Now go in the Pane with the relations list and select all the rcn route relations, RMB Download incomplete members.
Now you're ready to run the script. Select the network relation and hit Run on the Scripting Console. If all goes well, there shouldn't be any errors.
A file with wiki syntax will be created in C:\wikireport.txt Let me know if you want to run this on Linux, then I'll add support for saving it in the home directory. I'll have to find out how to know on what OS the script is run. This might be tricky since it's run inside the JVM.
I usually copy/paste the content of that file into a wiki page. Then you can see what problems still remain for this network. The script will also have added route relations to the network relation.
The script is smart enough to figure out what you selected, so it can check one single route, a group of routes, one network, or a group of networks, or a (group of) collection relation(s).
I'll add to this, as I go. Work in progress