[R-sig-Geo] create data frame after spDists (re-posted)

Rolf Turner r.turner at auckland.ac.nz
Fri Aug 24 22:42:21 CEST 2012


I believe that you would find the tools in the "spatstat" package
(e.g. crossdist()) useful.

     cheers,

         Rolf Turner

On 25/08/12 00:24, swagath navin wrote:
> Hello all, sorry for re-posting, but i got a scrub message for my first mail.
>
> I have two spatial points data frame df1 showing sample locations and df2
> meteorological stations. I am interested in finding met stations closer to
> the sample stations and creating a separate data frame with sample
> locations and the nearest met station.
>
> I calculated the distances between the stations:
>
> library(sp)
>
> df1<-data.frame(x=seq(5.1,5.5, 0.1), y=seq(51,55,1))
> df2<-data.frame(x=seq(5,5.3, 0.1), y=seq(50,53,1))
>
> coordinates(df1)=~ x + y
> coordinates(df2)=~ x + y
>
> dist=spDists(df1, df2, longlat = FALSE)
>
> but  how can i create a data frame with sample locations and nearest met
> station as shown below:
>
> Sample location | Nearest Met station
>
> (5.1, 51)             | (5.1,51)
>
> for small number of stations i can do manually, but i have around 400
> sample locations and 100 met stations.
>
> Thanks a lot for your time.



More information about the R-sig-Geo mailing list