[R-sig-Geo] create data frame after spDists (re-posted)
O'Hanlon, Simon J
simon.ohanlon at imperial.ac.uk
Sat Aug 25 10:02:11 CEST 2012
Hi Navin,
As Rolf said spatstat does what you need, but I think for your application nncross() would be most suitable:
>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
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))
sample <- ppp( df1$x , y = df1$y , xrange = range(df1$x) , yrange = range( df1$y) )
met <- ppp( df2$x , y = df2$y , xrange = range(df2$x) , yrange = range( df2$y ) )
nncross( sample , met )
dist which
1 0.000000e+00 2
2 8.881784e-16 3
3 0.000000e+00 4
4 1.004988e+00 4
5 2.009975e+00 4
HTH,
Simon
________________________________________
From: r-sig-geo-bounces at r-project.org [r-sig-geo-bounces at r-project.org] on behalf of Rolf Turner [r.turner at auckland.ac.nz]
Sent: 24 August 2012 21:42
To: swagath navin
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] create data frame after spDists (re-posted)
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.
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list