[R-sig-Geo] British national grid to long lat

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Feb 28 20:29:57 CET 2013


On Thu, Feb 28, 2013 at 6:26 PM, Ross Ahmed <rossahmed at googlemail.com> wrote:
> This might well be an FAQ, so apologies, but I couldnt find an answer
> through googling.
>
> I have the following OS grid references, which are from the British national
> grid system: http://en.wikipedia.org/wiki/Ordnance_Survey_National_Grid
>
> gridRefs <- c('NU13366133','NU13366808','NU13369308','NU14361713')
>
> How can I convert these to lat-long WGS84?
>

The grid square gets you 100km resolution, the the first four numbers
are x coordinate in 10m steps and the second four numbers are y coords
in 10m steps...

You have to lookup the grid square offset from the map of grid square.
For NU, thats 4 along and 6 up.

 For your example, extract the coordinates thus:

 > x=as.numeric(substr(gridRefs,3,6))
 > y=as.numeric(substr(gridRefs,7,10))

then create a spatial data frame with the coordinates. We multiply
your four-figures to get metres, and add the X and Y grid offset (also
in metres)

 > xy = data.frame(x=400000+x*10,y=600000+y*10)
 > coordinates(xy)=~x+y
 > proj4string(xy)=CRS("+init=epsg:27700")

 - this is the epsg code for OSgrid references in metres. To convert
to lat-long WGS84 coords:

 > spTransform(xy,CRS("+init=epsg:4326"))
SpatialPoints:
             x        y
[1,] -1.788218 55.84500
[2,] -1.787888 55.90565
[3,] -1.786655 56.13026
[4,] -1.774539 55.44783
Coordinate Reference System (CRS) arguments: +init=epsg:4326
+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0

 Check the points are where you expect them to be.

 If you have more than one grid square, you can extract that with
substr and compute or lookup the correct x and y offsets.

 You need the sp and rgdal packages for all this.

Barry



More information about the R-sig-Geo mailing list