Created
June 28, 2014 16:01
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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