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

https://sites.google.com/site/usefulpracticalgeoblog/home/routecalculationexample.

Route_Example_GeoTools.zip 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 http://www.geofabrik.de/data/shapefiles.html), 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 :



5 comments:

  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
    http://download.geofabrik.de/europe/ukraine.html
    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.

    Yuriy.

    ReplyDelete
    Replies
    1. Here is a source I use to create a destinations.shp file from SCV file
      http://docs.geotools.org/latest/userguide/tutorial/feature/csv2shp.html

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

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

      Delete
  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?

    ReplyDelete