# R or ArcGis: average per polygon of the shortest distance to a river from each point in that polygon

All the shapefiles necessary can be found here. These are shapefiles of lakes, and rivers. Downloading one shapefile as an example should be enough to get me on the right track.

What I want is to calculate the distance from each possible point in one nuts3-polygon to the nearest river. If all the distances are calculated from each point, I want to determine per nuts3-polygon what the average, minimum and maximum distance is to the nearest river, together with the standard deviation (if possible).

My paint skills are probably not the best ever, but the idea is something like this picture below (for each of the dots). Then I would calculate the average of all the brown lines that originates from a point in the polygon.

I can work a bit with R and ArcGis. Online I do not find a solution that matches what I am looking for. • Given there's an infinite number of points in a polygon I think the way to do it is to simulate a large number of points in the polygon with uniform density and average the distance to the nearest line. Have you used the `rgeos` package? That will compute point-line distances. – Spacedman Jul 12 '16 at 15:57
• This is most basic task using euclidian distance in and zonal statistics in arcgis – FelixIP Jul 12 '16 at 19:37
• Hey @FelixIP. Thanks for the hint. I have only access to ArcGis on Thursday but I will test it and keep you up to date. However, I already tried earlier in ArcGis and remember that I didn't get it to work. So if you know the specific steps that would help a lot. Otherwise, I'll let you know on Thursday! – user33125 Jul 12 '16 at 19:59
• @Spacedman Thank you as well for your fast reaction and hint. I follow the logic in your comment. However, I have no experience with both suggestions. However, since I like working with R, I will try to make it work. If you could give me a hint on how to make the points in the polygon, you would help me again a lot! – user33125 Jul 12 '16 at 20:05
• I think you should focus your question on where you are stuck using ArcGIS for Desktop. You can always research/ask about R separately. – PolyGeo Jul 12 '16 at 20:24 