Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting UTM's to Lat/Long in R

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.

like image 404
jlemanski915 Avatar asked Apr 09 '16 18:04

jlemanski915


People also ask

Does UTM use Lat Long?

Instead of using latitude and longitude coordinates, each 6° wide UTM zone has a central meridian of 500,000 meters. This central meridian is an arbitrary value convenient for avoiding any negative easting coordinates.

Is UTM more accurate than lat long?

One system is no more or less accurate than the other. They are just two different ways of positioning a point. Many experienced users prefer UTM over latitude/longitude when using 7.5' topographic quadrangle maps.

What is UTM XY coordinates?

The Universal Transverse Mercator (UTM) grid is an X-Y coordinate system used as a reference on medium- to small-scale maps for representing the three-dimensional curved surface of the earth on a 2-D plane (e.g. a map or computer screen).


2 Answers

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
}
like image 154
Erwan LE PENNEC Avatar answered Sep 30 '22 11:09

Erwan LE PENNEC


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.

like image 23
lloo443322 Avatar answered Sep 30 '22 11:09

lloo443322