# How to join the Least Cost Path with Optimal Destination?

I have the following problem which can be solved in 2 stages:

The first stage is to calculate the least cost path for transporting the produce from a pixel on the field to the edge of the road, for this I used Cost Path Analysis which gives me a raster of minimum transport cost from the pixel in the field to the road. The problem is that I do not know how to identify explicitly the pixel on the road at the end of the optimal path for each pixel on the field (or save its coordinates or use any other identifier). That is, as a result I need both the raster of minimum cost value and the ID of the destination pixel on the road.

In a second stage I must choose the optimal destination where to sell the products produced in each pixel on the field, that is, there are many factories that pay different prices but that are at different distances, so the cost of transport causes those prices vary (Price paid at destination factory minus transport cost gives prices at road side). I have calculated road side price by using Cost Path Analysis considering as source the several factories (points) and the road network as a destination, so that for each pixel on the road there is an optimal destination factory that provides the best selling price.

My problem is that I need to connect the 2 steps in one, so that for each pixel on the field I 've got an optimal factory (that provides the highest stumpage price) to send the production. Since I have obtained an optimal path from the pixel on the field to one pixel on the road, then continue from that pixel on the road to the optimal destination. Any light of shed on how identifying the pixel on the road that connect the two optimal paths? This, in ArcGIS 10.3 or a script that could help in Python…