Converting UTM's to Lat/Long in R
Asked Answered
I

2

6

I have a .csv file of 9,000+ UTM coordinates that I would like to convert into decimal degrees and I am having a bit of trouble. I have searched through several of the posts that have been posted here and elsewhere and I can't seem find a solution that transforms my set of UTM's into usable and accurate lat/long's.

I essentially have two questions: 1) does anyone see any issues with my code; and 2) is anyone familiar with forgoing transformation of UTM's into lat/long's and just using UTM's in the Rgooglemaps package?

Here are some examples of my code and data:

Data:

>head(utm)
-Northing Easting
1  4236576  615805
2  4236576  615805
3  4236576  615805
4  4236576  615805
5  4236576  615805
6  4236576  615805

Code thus far:

utm <- read.csv(file="utm.csv", header=TRUE, sep=",")
library(rgdal)
utm <- utm[complete.cases(utm),]
utm1 <- data.frame(x=utm$Northing,y=utm$Easting) 
coordinates(utm1) <- ~x+y 
class(utm1)
proj4string(utm1) <- CRS("+proj=utm +zone=10 +datum=WGS84 +units=m +ellps=WGS84") 
utm2 <- spTransform(utm1,CRS("+proj=longlat +datum=WGS84"))

Results

> head(utm2)
SpatialPoints:
             x        y
[1,] -91.08516 4.727323
[2,] -91.08516 4.727323
[3,] -91.08516 4.727323
[4,] -91.08516 4.727323
[5,] -91.08516 4.727323
[6,] -91.08516 4.727323
Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84 +ellps=WGS84
+towgs84=0,0,0 

So, I am getting some output, but I am not getting sensible output. Is there something I am missing here? Also, for what its worth, I was planning on using the "Rgooglemaps" package for creating some heat maps and kernel density plots.

Iey answered 9/4, 2016 at 18:25 Comment(1)
are you sure about you utm zone? Is zone=10 the right one?Llovera
K
7

I'm using the following code to convert from UTM to Lat/Long. It's working for the London area

wgs84 = "+init=epsg:4326"
bng = '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 
+ellps=airy +datum=OSGB36 +units=m +no_defs'

ConvertCoordinates <- function(easting,northing) {
out = cbind(easting,northing)
mask = !is.na(easting)
sp <-  sp::spTransform(sp::SpatialPoints(list(easting[mask],northing[mask]),proj4string=sp::CRS(bng)),sp::CRS(wgs84))
out[mask,]=sp@coords
out
}
Kiker answered 10/4, 2016 at 7:55 Comment(2)
If you want to compute the UTM zone and if you know the lat/long then the following link can help #9186996Kiker
This works really well and quick. I found 900,000 lon/lat values from easting/northing grid references. Thanks.Aldehyde
U
1

I think you just need to swap X and Y--Northing as Y, Easting as X. The original code worked for me with this change.

Ulick answered 12/5, 2020 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.