Skip to content

Instantly share code, notes, and snippets.

@geotheory
Created June 28, 2014 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geotheory/02f70a95ecdd98d435b4 to your computer and use it in GitHub Desktop.
Save geotheory/02f70a95ecdd98d435b4 to your computer and use it in GitHub Desktop.
Script to convert csv of British National Grid coordinates (OSBG36) to lat-longs (WGS84)
# read in csv file with headings labelled 'e' and 'n' and output latlons
# call script by command-line: 'RScript bng_to_latlon.R {bng_filename.csv}'
require(rgdal)
args=(commandArgs(TRUE))
datain = read.csv(args[1])
bng = datain
coordinates(bng) = ~ e + n
bng@proj4string = CRS("+init=epsg:27700")
latlon = spTransform(bng, CRS("+proj=longlat +datum=WGS84"))
out = cbind(datain, coordinates(latlon))
colnames(out) = c(names(datain),'lon','lat')
write.table(out, 'latlon.csv', row.names=F, col.names=T, sep=',')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment