map2lonlat: Convert from x-y to longitude and latitude
Description
Convert from x-y coordinates to longitude and latitude
Usage
map2lonlat(x, y, init=c(0,0))
Arguments
x
a vector containing the x component of points in the projected
space, or a list containing items named x and y, in which
case the next argument is ignored.
y
a vector containing the y coordinate of points in the projected
space (ignored if x is a list, as described above).
init
a vector containing the initial guesses for longitude and
latitude, used only for mapproj-style projections (see
mapPlot. If the default produces inaccurate results, try
sett
Value
A list containing longitude and latitude, with NA
values indicating points that are off the globe as displayed.
Bugs
The mapproj-style case can yield NA for longitude
and latitude, even for what would seem to be perfectly benign conditions.
Since map2lonlat is called by many mapping functions, this can yield
errors of various types, e.g. unaesthetic axis labelling. In many cases
those errors can be circumvented by switching to the equivalent
proj4-style projection.
Details
A projection must already have been set up, by a call to
mapPlot or lonlat2map.
The values of x and y have a clear meaning for
proj4-style projections. This is not true for mapproj-style
projections, since mapproject in the mapproj package shifts
the x component of its return value to have mean value equal to 0,
up to a calculation error.
The accuracy of map2lonlat tends to be higher for proj4-style
projections than for mapproj-style projections. This is because the
proj4 package provides inverse functions, while mapproj does
not, so that in the latter case the longitude and latitude are determined
by a minimization procedure using optim. See Bugs.
References
http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system,
downloaded May 31, 2014.
library(oce)
## Cape Split, in the Minas Basin of the Bay of Fundycs <- list(longitude=-64.49657,latitude=45.33462)
xy <- lonlat2map(cs, projection="+proj=merc")
map2lonlat(xy)