https://github.com/cran/fields
Raw File
Tip revision: e41cdb90fbcc54695ce1724284e5b3f3abcf643a authored by Doug Nychka on 21 October 2008, 16:58:57 UTC
version 5.01
Tip revision: e41cdb9
lonlat2xy.R
# fields, Tools for spatial data
# Copyright 2004-2007, Institute for Mathematics Applied Geosciences
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html

"lonlat2xy" <-
function (lnlt, miles = FALSE) 
{
    n <- nrow(lnlt)
    ctr <- c(mean(lnlt[, 1]), mean(lnlt[, 2]))
    ctx <- cbind(lnlt[, 1], rep(ctr[2], n))
    cty <- cbind(rep(ctr[1], n), lnlt[, 2])
    dstx <- c(rdist.earth(matrix(ctr, 1, 2), ctx, miles = FALSE))
    dsty <- c(rdist.earth(matrix(ctr, 1, 2), cty, miles = FALSE))
    cbind(dstx * (2 * (lnlt[, 1] > ctr[1]) - 1), dsty * (2 * 
        (lnlt[, 2] > ctr[2]) - 1))
}
back to top