I'm trying to convert Latlong to UTM but, for some reason, the results coming from R are very different from what I looking for.
The dataset is just one observation (the city of São Paulo):
LatLong
Longitude of São Paulo: -46.633309
Latitude of São Paulo: -23.550520
UTM coordinates (WGS84) of São Paulo
The UTM coordinates (WGS84) of São Paulo are: Zone 23K E: 333287.02 N: 7394586.09
Source: http://www.gps-latitude-longitude.com/gps-coordinates-of-sao-paulo
library(rgdal)
x<-c(-46.633309)
y<-c(-23.550520)
zone<-23
xy<-data.frame(ID = 1:length(x), X = x, Y = y)
coordinates(xy)<-c("X", "Y")
proj4string(xy)<-CRS("+proj=longlat +datum=WGS84") ## for example
res<-spTransform(xy, CRS(paste("+proj=utm +zone=",zone,"ellps=WGS84",sep='')))
res
> res
coordinates ID
1 (333287, -2605414) 1
Easting term seems to be right, but Northing is very diferent from the expected value (7394586.09 not equal to -2605414).
Can anyone tell me what is going on? Thanks in advance.
The issue is that you are in the southern hemisphere and the origin for Northing is no longer the equator but the south pole. Therefore, use
res<-spTransform(xy, CRS(paste("+proj=utm +south +zone=",zone,"ellps=WGS84",sep='')))
## coordinates ID
##1 (333287, 7394586) 1
Note the +south
addition to the CRS
specification.
Hope this helps.