# how to calculate cumulative cost of movement, accounting for wind direction, in R?

I am trying to reproduce the calculation of the duration of sail-powered navigation as described in an academic article (http://www.tandfonline.com/doi/full/10.1080/15230406.2017.1403376), but using R instead of ArcGIS.

Following this nice guide (https://mgimond.github.io/Spatial/raster-operations-in-r.html), I am planning to use the R package ‘gdistance’ to calculate cumulative distances, but I am stuck in the very early steps of the procedure. Following the mentioned website, first one should have a cost raster, which in my case would be the inverse of the wind speed (i.e., the pace of the navigation speed; let’s say hours/km). The ‘gdistance’ package (https://cran.r-project.org/web/packages/gdistance/vignettes/gdistance1.pdf) allows to calculate:

• (1) a transition matrix (using the ‘transition()’ command) that defines a traversing cost,
• (2) a geocorrection that adjusts the cost for 'true' local distance, and
• (3) an accumulated cost.

What is not clear to me is how an horizontal factor (http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-the-horizonal-and-vertical-factors-affect-path-distance.htm) can be put to work here.

In essence, the ideal procedure should be able to take into account a wind direction raster and to increase or reduce the cost of traveling (i.e., the sailing time) according to whether or not the movement along adjacent cells is (for instance) against or in the same direction of the wind. In other words, what is not clear to me is how a second cost, different from a wind pace raster, can be taken into account using ‘gdistance’.

• I think the answers you seek are in the `gdistance` vignette. See "asymmetric matrices", and "Example 1". I seems like you can swap slope for wind direction and elevation for wind speed and you are mostly there in solving your second question regarding "whether or not the movement along adjacent cells is (for instance) against or in the same direction of the wind". – JMT2080AD Dec 27 '17 at 20:02