Hello German,

The technique you propose is unorthodox, but it works perfectly!  Very fast and 
easy, it's exactly what I needed.

Thanks!

Bastien


-----Message d'origine-----
De : geotux_tux...@linuxmail.org [mailto:geotux_tux...@linuxmail.org]
Envoyé : 18 avril 2012 13:24
À : Ferland-Raymond, Bastien (DIF); r-sig-geo@r-project.org
Objet : Re: [R-sig-Geo] dist2Line with mtm projection

Hi Bastien,

unfortunately I won't go for the bonus :-/,  but regarding the distance 
calculation you can have a look at [1]. There is some code for snapping points 
to lines, from which you can reuse the functions you consider. They work with 
sp objects.

Regards,

Germán Carrillo

------------------------
[1] 
http://geotux.tuxfamily.org/index.php/en/geo-blogs/item/296-snapping-points-to-lines-in-r

----- Original Message -----
From: bastien.ferland-raym...@mrnf.gouv.qc.ca
Sent: 04/18/12 03:34 PM
To: r-sig-geo@r-project.org
Subject: [R-sig-Geo] dist2Line with mtm projection


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

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

 --
-----------
    \__
(:>__)(
    /

Soluciones Geoinformáticas Libres

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to