Skip to content

arussell/osgb_wgs84

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

osgb_wgs84

Ordnance Survey National Grid to WGS84 co-ordinate converter

Intro

This gem converts Ordnance Survey National Grid co-ordinates to and from WGS84 co-ordinates. It is based on a JavaScript implementation originally by Chris Veness, which was then ported to Ruby by Harry Wood and bundled into a gem by Aaron B. Russell.

Getting Started

If you're not using Bundler, run this in a terminal:

$ gem install osgb_wgs84

If you are using Bundler, just add this line to your project's Gemfile:

gem 'osgb_wgs84'

Usage

# Example WGS84 lat/lon to convert
lon = -0.10322
lat = 51.52237

# Set height to 0 if you don't have one
height = 0

osgb36point = OSGB_WGS84::WGS84_to_OSGB36(lat,lon, height)
oslat = osgb36point[0]
oslon = osgb36point[1]
osh = osgb36point[2]

osUKgridPoint = OSGB_WGS84::OSGB36_to_OSNG(oslat,oslon)
easting  = osUKgridPoint[0].round
northing = osUKgridPoint[1].round

gridrefLetters = OSGB_WGS84::OSNG_numbers_to_letters(easting,northing, 8)

puts "WGS84 lat:" + lat.to_s + ", WGS84 lon:" + lon.to_s
puts "http://www.openstreetmap.org/?mlat=" + lat.to_s + "&mlon=" + lon.to_s + "&zoom=16"
puts "\nConverts to:";
puts "OSGB36 lat:" + oslat.to_s + ", OSGB36 lon:" + oslon.to_s
puts "\nConverts to:";
puts "OS Easting:" + easting.to_s + ", OS Northing:" + northing.to_s + "  OS grid ref:" + gridrefLetters
puts "http://streetmap.co.uk/grid/" + easting.to_s + "_" + northing.to_s + "_106"

Output from the above example:

WGS84 lat:51.52237, WGS84 lon:-0.10322
http://www.openstreetmap.org/?mlat=51.52237&mlon=-0.10322&zoom=16

Converts to:
OSGB36 lat:51.5218609279112, OSGB36 lon:-0.101610123646581

Converts to:
OS Easting:531691, OS Northing:182090  OS grid ref:TQ31698209
http://streetmap.co.uk/grid/531691_182090_106

License

The code was originally written in JavaScrpt by Chris Veness:
http://www.movable-type.co.uk/scripts/latlong-convert-coords.html
http://www.movable-type.co.uk/scripts/latlong-gridref.html
And was originally realeased on the above site under LGPL license:
(c) Chris Veness 2005-2010
But is now released on the above site under CC-BY
(c) Chris Veness 2005-2012

Here the code has been ported to ruby by Harry Wood. Harry waives all intelectual property rights which may apply to the porting process, meaning the code is (c) Chris Veness as above.

Bundled into a RubyGem by Aaron B. Russell, who also waives any copyright claims to this code. Thanks to Chris and Harry for saving me from having to try and implement this from scratch! :)

WGS84 lat/lons -> OSGB64 lat/lons-> OS Eastings & Northings
http://www.movable-type.co.uk/scripts/latlong-convert-coords.html

About

Ordnance Survey National Grid to WGS84 co-ordinate converter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages