lonlat

# lonlat - temp <- cbind(rep(mx, 2), range(y)) sy <-...

This preview shows pages 1–2. Sign up to view the full content.

M. Fuentes ST790 #function to calculate the geodesic distance in km rdist.earth<-function(loc1, loc2) { if(missing(loc2)) loc2 <- loc1 R <- 6371 lat <- loc1[, 2] lon <- loc1[, 1] coslat1 <- cos((lat * pi)/180) sinlat1 <- sin((lat * pi)/180) coslon1 <- cos((lon * pi)/180) sinlon1 <- sin((lon * pi)/180) lat <- loc2[, 2] lon <- loc2[, 1] coslat2 <- cos((lat * pi)/180) sinlat2 <- sin((lat * pi)/180) coslon2 <- cos((lon * pi)/180) sinlon2 <- sin((lon * pi)/180) PP1 <- cbind(coslat1 * coslon1, coslat1 * sinlon1, sinlat1) PP2 <- cbind(coslat2 * coslon2, coslat2 * sinlon2, sinlat2) pp <- (PP1 %*% t(PP2)) R * acos(ifelse(pp > 1, 1, pp)) } #function to convert lon/lat into kilometers lon.lat.to.xy<-function(lon.lat) { x <- lon.lat[, 1] y <- lon.lat[, 2] mx <- mean(x) my <- mean(y)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: temp <- cbind(rep(mx, 2), range(y)) sy <- rdist.earth(temp)[2, 1] temp <- cbind(range(x), rep(my, 2)) sx <- rdist.earth(temp)[2, 1] temp <- list(x = sx/(max(x) - min(x)), y = sy/(max(y) - min(y))) cbind((x - mx) * temp\$x, (y - my) * temp\$y) } loc<-matrix(c(87.63,41.88,93.22,44.89, 73.97,40.78,90.25,29.98),ncol=2,byrow=T) #geodesic distance(km) rdist.earth(loc) [,1] [,2] [,3] [,4] Chicago [1,] 0.0000 561.9947 1145.894 1343.890 Minneapolis [2,] 561.9947 0.0000 1630.386 1678.205 New York [3,] 1145.8941 1630.3855 0.000 1897.215 New Orleans [4,] 1343.8897 1678.2050 1897.215 0.000 #Euclidian distance (degress)*R*pi/180 R<-6371 dist(loc)*R*pi/180 1 2 3 2 705.9626 3 1523.8396 2188.7461 4 1354.9110 1690.4884 2172.3698...
View Full Document

## This note was uploaded on 08/01/2008 for the course ST 790M taught by Professor Fuentes during the Fall '07 term at N.C. State.

### Page1 / 2

lonlat - temp <- cbind(rep(mx, 2), range(y)) sy <-...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online