Sunday, September 2, 2012

Updated GeoTools Routing Example

I have updated the code example for the GeoTools routing that I had earlier on this blog. You can find the code and example datasets below is the latest code example. It contains a folder with the necessary Java classes and two .shp files. One file contains the network dataset for Vienna, Austria (available from, the other contains two destinations for the example code. It requires Geotools 2.7 libraries to run. I have tried to comment it heavily to make it clear. It uses only the distance information to calculate the weights of the edges, but that can easily be changed to incorporate anything else, such as travel time etc. This code example calculates the route from one origin to two destinations (green points on screenshot below).

Here is a screenshot of the output :


  1. Hi and thank You for the tutorial. There are not so much information about using shape files in the net and your is a best one.
    Now, as I am a beginner with Geo tools I have a problem: I download a road shape for my country here
    I draw all roads successfully. Now I need to specify a destination(s) in shape file. I also use a specification how to convert SCV file with data format of LAT, LON, CITY, NUMBER into shape file. But when I use your tutorial the
    Path path = shortestPathFinder.getPath(destination);
    always return null for me. I am guess that destination shape file form incorrectly.
    Could You please specify - how U did a destination.shp

    Thank You in advance.


    1. Here is a source I use to create a destinations.shp file from SCV file

    2. I have got an answer ... to calculate routes we need to use Routable Shapefiles!

    3. I guess from the above comments that you solved the problem yourself...well done! :-)

  2. Hi,

    I need to create a new routing algorithm and i selected Geotools to play with. I have been trying for a long time to find info, in order to get started, but for the life of me i do not find anything that could help me. Could you please give me some tips on how to start and with what to start?