Skip to content
Prev 9274 / 29559 Next

Importing geographical coordinates in R

On Fri, 10 Sep 2010, Manuel Sp?nola wrote:

            
You need to convert the degree and minute signs because they need - for 
this function - to be different:

library(sp)
intext <- c("N10 41 08.7", "N10 41 06.8", "N10 41 06.4", "N10 41 05.6")
t1 <- substring(intext, 2, nchar(intext))
t2 <- sub(" ", "d", t1)
# sub() substitutes the first " " with "d"
t3 <- sub(" ", "'", t2)
# and the second with "'"
t4 <- paste(t3, "\"", substring(intext, 1, 1), sep="")
# and we append "\"" and the axis letter
char2dms(t4)
as.numeric(char2dms(t4))

For W, you'll also need to change the sign of the degree value, and set 
"E", not "W" - the same would apply to "S" if given - should be "N". The 
numeric output does not have an axis tag, in all downstream functions the 
order is (x, y), (longitude, latitude), so the axis is given implicitly.

See also ?char2dms.

Hope this helps,

Roger