UTM needs a +zone and +south marker for the southern hemisphere, so
your PROJ.4 specification is incomplete, probably assuming +zone=1
which is completely wrong for longitude=126.
http://en.wikipedia.org/wiki/File:Utm-zones.jpg
Longitude 126.59 suggests zone 51 or 52, but it really depends on your
local usage and could be for the northern or southern hemisphere, and
the appropriate datum to be used. You should find out these details to
ensure you are targetting the right projection. It won't matter for
this simple example, but it might when you start sharing the data with
others. This is also important for the datum used for the
longitude/latitude values, you really should find out whether WGS84 is
a sensible assumption (probably ok for GDA94, but not older Australian
datums for example). These details really matter and you will save
pain if you ensure that you know them. (There are Australian datums
that a default GDAL build cannot transform between by name and
requires explicit parameters, as an example).
You could try the R-Sig-Geo mailing list as a better group for this
topic, and please declare your use of contributed packages, here sp
and rgdal. Here's an example that can work:
library(sp)
library(rgdal)
SP <- SpatialPoints(cbind(126.59,-14.30), proj4string CRS("+proj=longlat
+datum=WGS84"))
coordinatesUTM <- spTransform(SP, CRS("+proj=utm +south +zone=52
+datum=WGS84"))
coordinatesUTM
SpatialPoints:
coords.x1 coords.x2
[1,] 240015.6 8417744
Coordinate Reference System (CRS) arguments: +proj=utm +south +zone=52
+datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
Also note that the rgdal function project() can be used to do simpler
transformations on matrices, though it cannot do datum conversions
(not relevant here but worth knowing).
Cheers, Mike.
On Tue, Jun 5, 2012 at 6:28 PM, Boris Beranger <borisberanger at
gmail.com> wrote:> Dear all,
>
> I have been trying to convert coordinates from longitude/latitude to utm
> but I got an error. As soon as the longitude coordinate is greater than 90,
> I get the folloowing error message: ?"error in pj_transform: latitude
or
> longitude exceeded limits"
>
> Here is what I did:
>
>
?SP<-SpatialPoints(cbind(126.59,-14.30),proj4string=CRS("+proj=longlat"))
> coordinatesUTM<-spTransform(SP,CRS("+proj=utm"))
>
> Error in spTransform(SP, CRS("+proj=utm")) :
> ?error in pj_transform: latitude or longitude exceeded limits
>
> Can someone explain me what I did wrong? I am using coordinates of
> Australia so the range of my longitudes is around [110,150] and the one of
> my latitudes [-10,-45].
>
> Thanks in advance,
>
> Cheers,
> Boris
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com