I am struggling to convert with R coordinates from British National Grid (BNG) to WGS84 Lat Lon.
Here an example of data:
df = read.table(text = 'Easting Northing
320875 116975
320975 116975
320975 116925
321175 116925
321175 116875
321275 116875', header = TRUE)
How can I convert the Easting and Northing to WGS84 Lat Lon?
There is a function called spTransform
from rgdal
package but the documentation is very confusing.
Any suggestion?
Here is a way to do it with the sf
package in R. We take the table and convert to point geometries, specifying that these values are in the BNG coordinate reference system. Then we transform to WGS84, extract the coordinates as a matrix, and return a data frame.
I believe from a quick google that the British National Grid has EPSG code 27700, though if this is not the right projection then you can modify the crs =
argument in st_as_sf
. The points as given appear to be in some fields in the Blackdown Hills AONB south of Taunton; I would check the georeferencing yourself.
df = read.table(text = 'Easting Northing
320875 116975
320975 116975
320975 116925
321175 116925
321175 116875
321275 116875', header = TRUE)
library(tidyverse)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
df %>%
st_as_sf(coords = c("Easting", "Northing"), crs = 27700) %>%
st_transform(4326) %>%
st_coordinates() %>%
as_tibble()
#> # A tibble: 6 x 2
#> X Y
#> <dbl> <dbl>
#> 1 -3.13 50.9
#> 2 -3.13 50.9
#> 3 -3.13 50.9
#> 4 -3.12 50.9
#> 5 -3.12 50.9
#> 6 -3.12 50.9
Created on 2018-05-11 by the reprex package (v0.2.0).