## Converting latitude and longitude to x-y coordinates
if (FALSE) ltln2xy <- function(latlon,latlon0) {
lat <- latlon[,1]*pi/180; lon <- latlon[,2]*pi/180
lt0 <- latlon0[1]*pi/180; ln0 <- latlon0[2]*pi/180
x <- cos(lt0)*sin(lon-ln0); y <- sin(lat-lt0)
cbind(x,y)
}
data(LakeAcidity)
latlon <- as.matrix(LakeAcidity[,c("lat","lon")])
m.lat <- (min(latlon[,1])+max(latlon[,1]))/2
m.lon <- (min(latlon[,2])+max(latlon[,2]))/2
ltln2xy(latlon,c(m.lat,m.lon))
## Clean up
rm(ltln2xy,LakeAcidity,latlon,m.lat,m.lon)
Run the code above in your browser using DataLab