Thanks to the attention my paper on the cost of Somali piracy has received, a lot of people have approached me to ask how I computed the maritime routes. It is not a very difficult task using R. The key ingredient is a map of the world, that can be rasterized into a grid; all the landmass needs to be assigned an infinite cost of crossing and last but not least -- one needs to compute the actual routes.

What packages do I need?

The package gdistance does most of the actual work of computing the routes. The wrld_simpl map provides what is needed to generate a raster.

Generating a Raster

After the raster is generated, we can proceed by making landmass impassable for vessels.

There are a few more things to do, such as opening up the Suez Canal and some other maritime passages -- one needs to find the right grid cells for this task. In the next step we can transform the raster into a transition layer matrix, that comes from the gdistance package. It is a data construct that essentially tells us how one can move from one cell to the other -- you can allow diagonal moves by allowing the vessel to move into all 8 adjacent grid cells. There is also a geo-correction necessary, as the diagonals are longer distances than the straight-line moves.

Well -- and thats basically it -- of course, there are a few bits and pieces that need additional work -- like adding heterogenuous costs as one can imagine exist due to maritime currents and so on. Furthermore, there is a whole logic surrounding the handling of the output and the storing in a local database for further use and so on.

But not to bore you with that -- how can I obtain the distance between A and B? This uses Dijkstra's Algorithm and is called through the gdistance function "shortestPath".

Using this output, you can then generate fancy graphs such as ...

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.