0

Thanks in advance.

I have 86 thousand points in lat/long that I need to convert to UTM. A sample of 25 are included herein. I have found a number of help full SO posts, but continue to receive errors with the worked examples as explained below.

The sample data is here:

    locs <- structure(list(LocNum = 1:25, IndID = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L), .Label = c("011_A", "015_A", "034_A"
), class = "factor"), FixDateTimeLocal = structure(1:25, .Label = c("2012-02-16 17:00:00", 
"2012-02-16 23:00:00", "2012-02-17 05:00:00", "2012-02-17 11:00:00", 
"2012-02-17 17:00:00", "2012-02-17 23:00:00", "2012-02-18 05:00:00", 
"2012-02-18 11:00:00", "2012-02-18 17:00:00", "2012-02-18 23:00:00", 
"2012-02-27 14:00:00", "2012-02-27 15:30:00", "2012-02-27 16:00:00", 
"2012-02-27 17:00:00", "2012-02-27 23:00:00", "2012-02-28 05:00:00", 
"2012-02-28 11:00:00", "2012-02-28 17:00:00", "2012-02-28 23:00:00", 
"2012-02-29 05:00:00", "2013-01-19 17:00:00", "2013-01-19 23:00:00", 
"2013-01-20 05:00:00", "2013-01-20 11:00:00", "2013-01-20 17:00:00"
), class = "factor"), Lat = c(45.120814, 45.120802, 45.120761, 
45.116529, 45.105876, 45.104819, 45.104803, 45.104491, 45.103639, 
45.10427, 45.092519, 45.094687, 45.098596, 45.099671, 45.099709, 
45.099422, 45.097036, 45.097139, 45.098102, 45.098099, 44.962221, 
44.962904, 44.967558, 44.968786, 44.973531), Long = c(-110.817359, 
-110.817405, -110.818067, -110.806221, -110.797895, -110.796213, 
-110.795224, -110.795689, -110.799264, -110.799369, -110.783507, 
-110.78943, -110.791256, -110.794017, -110.794075, -110.794205, 
-110.792251, -110.792, -110.791296, -110.791331, -109.85984, 
-109.859536, -109.860217, -109.86568, -109.881313)), .Names = c("LocNum", 
"IndID", "FixDateTimeLocal", "Lat", "Long"), row.names = c(NA, 
-25L), class = "data.frame")

There are IDs for 3 individuals, time stamp (not yet as POSIXct), lat and long.

  LocNum IndID    FixDateTimeLocal      Lat      Long
1      1 011_A 2012-02-16 17:00:00 45.12081 -110.8174
2      2 011_A 2012-02-16 23:00:00 45.12080 -110.8174
3      3 011_A 2012-02-17 05:00:00 45.12076 -110.8181
4      4 011_A 2012-02-17 11:00:00 45.11653 -110.8062
5      5 011_A 2012-02-17 17:00:00 45.10588 -110.7979
6      6 011_A 2012-02-17 23:00:00 45.10482 -110.7962

I followed suggestions made here and used the following code:

library(sp)
library(rgdal)
pts <- SpatialPoints(cbind(locs$Lat,locs$Long), 
                     proj4string = CRS("+proj=longlat +datum=WGS84"))

and got

Error in validityMethod(as(object, superClass)) : 
  Geographical CRS given to non-conformant data: -110.818067

To remove the negative long as suggested here I ran

pts <- SpatialPoints(abs(cbind(locs$Lat,locs$Long)), 
                     proj4string = CRS("+proj=longlat +datum=WGS84"))

and got

Error in validityMethod(as(object, superClass)) : 
  Geographical CRS given to non-conformant data: 110.818067

Lastly, as suggested hereusing a matrix I ran

pts <- project(as.matrix(locs[,c("Lat","Long")]), "+proj=utm +zone=12 ellps=WGS84")

and got

Warning message:
In project(as.matrix(locs[, c("Lat", "Long")]), "+proj=utm +zone=12 ellps=WGS84") :
  25 projected point(s) not finite

Any suggestions on how to convert these lat/long points to UTM would be appreciated. The lat/long are in WGS84 and my UTM zone is 12.

Community
  • 1
  • 1
B. Davis
  • 3,021
  • 4
  • 29
  • 67
  • 2
    You got your longitude and latitude columns reversed. Try `SpatialPoints(cbind(locs$Long,locs$Lat), [...])` in place of what you did. – Josh O'Brien Jan 08 '15 at 16:12
  • Well that is slightly embarrassing and pathetic...Whoops. Usually I find the obvious mistakes when drafting the question. Thanks for your keen eye. The last code using as.matrix seems to run fine although I have not plotted them to confirm. – B. Davis Jan 08 '15 at 16:30
  • Well, I only recognized the error as quickly as I did because I've committed it a time or two myself ;). Glad that fixed it. – Josh O'Brien Jan 08 '15 at 16:33

0 Answers0