McClatchie, Sam (PIRSA-SARDI)
2005-Jan-19 01:52 UTC
[R] looking for a basic spatial diff function
Background: OS: Linux Mandrake 10.1 release: R 2.0.0 editor: GNU Emacs 21.3.2 front-end: ESS 5.2.3 --------------------------------- Colleagues Is there a function to calculate distances between adjacent latitude/ longitude pairs in a matrix? It is basically a spatial diff() function that I have in mind. Data: long1, lat1 long2, lat2 long3, lat3 looking for: diff(data$long, data$lat) function Result long1, lat1 long2, lat2, distance = long/lat2 - long/lat1 long3, lat3, distance = long/lat3 - long/lat2 I've probably missed it but a search of the maillist archives and quick scan of the packages (map*) did not solve my query. For this simple task I don't really want to get into GRASS. Best fishes Sam ---- Sam McClatchie, Sub-program leader, Pelagic Fisheries South Australian Aquatic Sciences Centre PO Box 120, Henley Beach 5022 Adelaide, South Australia email <mcclatchie.sam at saugov.sa.gov.au> Telephone: (61-8) 8207 5448 FAX: (61-8) 8200 2481 Research home page <http://www.members.iinet.net.au/~s.mcclatchie/> /\ ...>><xX(?> //// \\\\ <?)Xx><< ///// \\\\\\ ><(((?> >><(((?> ...>><xX(?>O<?)Xx><<
On Wed, 19 Jan 2005, McClatchie, Sam (PIRSA-SARDI) wrote:> Background: > OS: Linux Mandrake 10.1 > release: R 2.0.0 > editor: GNU Emacs 21.3.2 > front-end: ESS 5.2.3 > --------------------------------- > > Colleagues > > Is there a function to calculate distances between adjacent latitude/ > longitude pairs in a matrix? It is basically a spatial diff() function that > I have in mind. > > Data: > > long1, lat1 > long2, lat2 > long3, lat3 > > looking for: diff(data$long, data$lat) > > function Result > > long1, lat1 > long2, lat2, distance = long/lat2 - long/lat1 > long3, lat3, distance = long/lat3 - long/lat2A distance matrix can be got from the rdist.earth() function in the fields package:> lon <- seq(-10,10,5) > lat <- seq(-10,10,5) > rdist.earth(cbind(lon, lat), miles=FALSE)[,1] [,2] [,3] [,4] [,5] [1,] 1.344145e-04 783.6868 1570.3395 2357.0091 3.140679e+03 [2,] 7.836868e+02 0.0000 786.6784 1573.3568 2.357009e+03 [3,] 1.570339e+03 786.6784 0.0000 786.6784 1.570339e+03 [4,] 2.357009e+03 1573.3568 786.6784 0.0000 7.836868e+02 [5,] 3.140679e+03 2357.0091 1570.3395 783.6868 1.344145e-04 from which you need to get the values below the diagonal.> > I've probably missed it but a search of the maillist archives and quick scan > of the packages (map*) did not solve my query. For this simple task I don't > really want to get into GRASS. > > Best fishes > > Sam > ---- > Sam McClatchie, > Sub-program leader, Pelagic Fisheries > South Australian Aquatic Sciences Centre > PO Box 120, Henley Beach 5022 > Adelaide, South Australia > email <mcclatchie.sam at saugov.sa.gov.au> > Telephone: (61-8) 8207 5448 > FAX: (61-8) 8200 2481 > Research home page <http://www.members.iinet.net.au/~s.mcclatchie/> > > /\ > ...>><xX(?> > //// \\\\ > <?)Xx><< > ///// \\\\\\ > ><(((?> > >><(((?> ...>><xX(?>O<?)Xx><< > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no