# [R-sig-Geo] Convert LatLong to UTM

Pierre Roudier pierre.roudier at gmail.com
Wed Aug 3 05:23:43 CEST 2011

```Dear Colin,

Using sp and rgdal:

library(rgdal)

LatLong <- data.frame(X = c(56.85359, 56.85478), Y = c(-118.4109, -118.4035))
names(LatLong) <- c("X","Y")

# Convert it to a sp object
coordinates(LatLong) <- ~ Y + X # longitude first

# Add a coordinate reference system
proj4string(LatLong) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")

> LatLong
SpatialPoints:
Y        X
[1,] -118.4109 56.85359
[2,] -118.4035 56.85478
Coordinate Reference System (CRS) arguments: +proj=longlat +ellps=WGS84
+datum=WGS84 +towgs84=0,0,0

# Project using spTransform
Utm <- spTransform(LatLong, CRS("+proj=utm +zone=11 ellps=WGS84"))

> Utm
SpatialPoints:
Y       X
[1,] 413958 6301976
[2,] 414412 6302099
Coordinate Reference System (CRS) arguments: +proj=utm +zone=11
+ellps=WGS84

HTH,

Pierre

2011/8/3 Colin Bergeron <cb1 at ualberta.ca>:
> Dear rSigGeo,
>
> I tried to convert a list of LatLong coordinates (in DD format) into UTM
> zone 11 NAD 27. I first tried this from PBSmapping:
>
> library(PBSmapping)
> LatLong<-cbind(c(56.85359, 56.85478),c(-118.4109, -118.4035))
> colnames(LatLong)<-c("X","Y")
>
> attr(LatLong, "projection") <- "LL"
> attr(LatLong, "zone") <-11
> UTM<-convUL(LatLong)
>
>
> #and that's what I get
>> UTM
>         X         Y
> 1 14088.69 -16092.76
> 2 14082.61 -16096.32
>
> Now, the UTM values are supposed to be around:
>    X    Y
> 1 414040     6301764.2
> 2 414493           6301888.39
>
> So, I then tried with rgdal
> library(rgdal)
>
> UTM<-project(LatLong, "+proj=utm +zone=11 ellps=WGS84")
>
> #and that's what i get:
>
> projected point not finite
> projected point not finite
>
> # The possible errors I see are DD format in the LatLong file. Maybe I
> should be able to specify that it is zone 11 north or I think NAD 27 should
> also be specified somewhere. What do you think?
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Scientist
Landcare Research, New Zealand

```