Skip to content

Importing geographical coordinates in R

2 messages · Manuel Spínola, Roger Bivand

#
Dear list members (I am a new member),

How do I import geographical coordinates data into R?

ref1                       ref2
N10 41 08.7     W84 10 46.3
N10 41 06.8     W84 10 46.4
N10 41 06.4     W84 10 44.6
N10 41 05.6     W84 10 46.0

Best,

Manuel
#
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