[R-sig-Geo] dist2Line with mtm projection

Bastien.Ferland-Raymond at mrnf.gouv.qc.ca Bastien.Ferland-Raymond at mrnf.gouv.qc.ca
Wed Apr 18 15:34:49 CEST 2012


Dear R people,

I have a code that was using the function dist2Line() from the geosphere package.  The function worked find and did exactly what I was looking for which is to find the distance between a point (from a SpatialPointDataFrame object) and a line (from a SpatialLinesDataFrame object) and give me the coordinates on the line where the distance is the shortest.  However, I've add to change my code to start using MTM coordinates system instead on lat/long and now, the dist2Line() function doesn't work anymore as it requires Lat/Long.

So, I've tried the function gDistance() in the rgeos package as it is using MTM.  This calculated the distance properly, but didn't give me the coordinates on the line that is the closest to my point (which is what I really need).

Do any of you know any function similar to dist2Line() but that works in MTM projection?  I don't really feel like reprojecting into lat/long as it will slow down my code too much.

Finally, here is a bonus question: Even better than the dist2Line() function would be a function that gives me the same result as dist2Line, but by calculating a costDistance like it is done by the gdistance package instead of the traditional Euclidean distance.  A function like : costDist2Line() which sadly I couldn't find anywhere.  I doubt this function exists and I'm expecting it to be very hard to program, so that is why it's only a bonus question...

Best regards,

Bastien Ferland-Raymond, M.Sc. Stat., M.Sc. Biol.
Division des orientations et projets spéciaux
Direction des inventaires forestiers
Ministère des Ressources naturelles et de la Faune



More information about the R-sig-Geo mailing list