[R-sig-Geo] Finding distances between points and contour lines

rhodes.uor r.rhodes at pgr.reading.ac.uk
Fri Jul 11 13:18:11 CEST 2014


Hi Barry,

Thanks for the reply, my apologies for the HTML code. I think you've hit 
the nail on the head though even without the example. A simple bit of 
Pythagorus on the vertices has done the job perfectly well for now, 
although I'll bear gDistance in mind as I'm certain it will be of use 
later in this project.

Thanks for your help!
Ruari


On 07/11/14 08:45, Barry Rowlingson [via R-sig-geo] wrote:
> Couple of clarifications:
>
>  * I think you sent an HTML email which stripped out your example. Its
> visible here:
>
> http://r-sig-geo.2731867.n2.nabble.com/Finding-distances-between-points-and-contour-lines-tp7586733.html
>
> but you shouldn't send HTML emails to the mailing list.
>
>  * Do you want the minimal distance between the *vertices* of the
> lines or the minimal distance between the lines themselves?
>
>  For the former its just a question of extracting the vertex
> coordinates from the spatial data structure and doing a distance
> calculation between all pairs from each item. If you've transformed
> your data to a regular cartesian coordinate system then Pythagoras
> will help you.
>
>  For the latter just turn your track into a SpatialLines object and
> use gDistance from package rgeos:
>
> trackSL = SpatialLines(LinesList=list(Lines(Line(coords=track.pts),1)))
> gDistance(trackSL,contourSL)
> [1] 0.02220655
>
> this will return zero if the track defined by the points crosses the
> contour, whereas the vertex distance method will return zero only if a
> vertex is exactly on the contour.
>
> # fiddle the track to cross the contour:
>
>  track.pts[1,1]=.1
>
> # rebuild the lines:
>
>  trackSL = SpatialLines(LinesList=list(Lines(Line(coords=track.pts),1)))
>
> # plot and check:
>
>  lines(trackSL)
>
> # distance should be zero:
>
>  gDistance(trackSL,contourSL)
>  # returns [1] 0
>
>
>
> On Thu, Jul 10, 2014 at 10:23 PM, rhodes.uor <[hidden email] 
> </user/SendEmail.jtp?type=node&node=7586734&i=0>> wrote:
>
> > Hi all,
> >
> > I have two sets of data; a dataframe of lon/lat pairs which 
> correspond to
> > storm track locations, and a gridded rainfall dataset. I've taken 
> contours
> > of the rainfall dataset at a single level and saved them as a
> > SpatialLinesDataFrame. I'm attempting to determine the distance 
> between each
> > of the storm track coordinates and each of the contours. Below is an 
> example
> > of what I have so far, but I can't figure out the next step:
> >
> >
> >
> > For each entry in track.pts I want to return a distance to the 
> nearest point
> > of each entry in contourSL (or in contours, for that matter). Can 
> anyone
> > recommend a way to do this?
> > Thanks very much!
> >
> >
> >
> > --
> > View this message in context: 
> http://r-sig-geo.2731867.n2.nabble.com/Finding-distances-between-points-and-contour-lines-tp7586733.html
> > Sent from the R-sig-geo mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > [hidden email] </user/SendEmail.jtp?type=node&node=7586734&i=1>
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email] </user/SendEmail.jtp?type=node&node=7586734&i=2>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:
> http://r-sig-geo.2731867.n2.nabble.com/Finding-distances-between-points-and-contour-lines-tp7586733p7586734.html 
>
> To unsubscribe from Finding distances between points and contour 
> lines, click here 
> <http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7586733&code=ci5yaG9kZXNAcGdyLnJlYWRpbmcuYWMudWt8NzU4NjczM3wtMTkwNzI5ODU5OA==>.
> NAML 
> <http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> 
>




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Finding-distances-between-points-and-contour-lines-tp7586733p7586735.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list