[R-sig-Geo] Importing geographical coordinates in R

Roger Bivand Roger.Bivand at nhh.no
Sat Sep 11 12:06:08 CEST 2010


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

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

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



>
> Best,
>
> Manuel
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list