Guide To Adding Turn Based Restrictions in JOSM

 

As the new Open Street Map API 0.5/0.6 supports turn based restrictions in JOSM, this blog will show how to add these restrictions to the OSM database.

A turn based restriction is made up of two nodes/ways a, to value, from value and via node. Basically you will need to select which is the node/way with the restriction starts (the from value), the node/way where the restriction ends (to value) and the node/way where you could normally cross at (via).

JOSM

Open JOSM and click on the relations button at the bottom of the side bar (highlighted in green) and the relations bar appears in the bottom right pane (blue).

 

To create a new restriction (which is a relation) click new (Orange) where you will be presented with the screen below,

From here add the tag ‘restriction’ (orange) with the value of that restriction say a ‘no_left_turn’ or ‘no_right_turn’ (for a full list see here:   http://wiki.openstreetmap.org/index.php/Relation:restriction )

 

Then add the members (yellow) to the relation ie. the to, from and via segments. Click on the way/node where you want to add the member then enter, do this for all the ways and their assoiciated restrictions then click OK and then upload it to OSM.

Here is the web page of the relation that I uploaded from JOSM as part of this example… (The webpage is here: http://openstreetmap.org/browse/relation/22104)

From XML to XPath via Sax

The past week has been interesting, with breakneck speed in getting the initial DOM XML parsing working then when coming to selectively choosing information and needing XPath to query the XML file, it becomes a different kettle of fish. 

Installed with a sense of confidence from earlier XML success, it rapidly became apparent that the OSM data model wasn’t going to be compatible with a basic DOM parser, so moving onto XPath yesterday was a frank nightmare, with nothing going right, then in true fashion in 5 minutes I was up and compiling within 5 minutes of starting this morning using a SAX parser instead of my DOcument Model. 

The problem now is moving onto making the OSM data model fit with the XPath query language, possibly doing XLST transformations or at worst placing the data in a temporary SQL database and then pulling the data out then, time is of the essence!

For those interested here is the code to query XPath in Java…

import java.io.IOException;

import org.w3c.dom.*;

import org.xml.sax.SAXException;

import javax.xml.parsers.*;

import javax.xml.xpath.*;


public class XPathExample {


  public static void main(String[] args)  throws ParserConfigurationException, SAXException,  

          IOException, XPathExpressionException {


    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();

    domFactory.setNamespaceAware(true);

    DocumentBuilder builder = domFactory.newDocumentBuilder();

    Document doc = builder.parse(/*Name of XML Document*/);


    XPathFactory factory = XPathFactory.newInstance();

    XPath xpath = factory.newXPath();

    XPathExpression expr = xpath.compile(/*XPATH QUERY HERE*/);

 

    Object result = expr.evaluate(doc, XPathConstants.NODESET);

    NodeList nodes = (NodeList) result;

    for (int i = 0; i < nodes.getLength(); i++) {

        System.out.println(nodes.item(i).getNodeValue()); 

    }

  }

}

Beginning Routing with Dijkstra

ROSM – Routing with Open Street Map, at the moment the project is in a high gear, though is being brought together. For example routing across the different nodes is done by the algorithm by Dijstkra with a scope for A* and possibly D* (dependent on it’s implementation requirements)An XML Parser is inherent to the source, though needs to be integrated and changed to select relationships, not nodes. A UML Class diagram of the system is also included in the SVN repository.The system uses the JGrapht java graph library to model and simulate the graph, and on this we abstract the map from OSM data. What is handy about this approach, if it enables us to use a well defined (and open source) graphing solution.

The output from routing from the Montreal Place to Southampton Street

“The route from Montreal Place to Southampton Street is as follows…

[(Montreal Place : Strand), (Strand : Wellington Street), (Wellington Street : Tavistock Street), (Tavistock Street : Southampton Street)]

The routing algorithm is ‘Dijksta’s Algorithm’ and the next step will be to integrate my XML parser into selecting the ways and their intersections…

This is the junction at the Strand…

Routing from Montreal Place to Southampton Street
Routing from Montreal Place to Southampton Street