Project

osgb

0.0
No commit activity in last 3 years
No release in over 3 years
Converts between Ordnance Survey grid references and lat/long points, including transformation between datums so that you can turn grid references into GPS points.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.6.0
 Project Readme

OSGB

This is a library that converts between British (and Irish) grid references and latitude and longitude co-ordinates. It is theoretically accurate to about 1m, but realistically you can expect precision of about 10m. Good for google map and GPS use, not recommended for surveying nuclear power plants. I don't suppose people often use grid references for that.

Installation

In Rails 3, add this to your Gemfile and run bundle install.

gem "osgb"

In Rails 2, add this to your environment.rb file.

config.gem "osgb"

Alternatively, you can install it as a plugin.

rails plugin install git://github.com/spanner/osgb.git

Status

Early days: activerecord interface hasn't settled down, some refactoring likely, bugs entirely possible. The basic algorithms are ancient and sound, though.

Usage

You don't need to make any explicit reference to the gem. It adds conversion and utility methods to the String class:

"SD28687846".is_gridref?                # -> true
"SD28687846".to_latlng                  # -> [54.196915, -3.094684]
"SD28687846".to_wgs84                   # -> [54.196915, -3.094684]
"SD28687846".to_osgb36                  # -> [54.196763, -3.093320]
"1.056789, 55.98978607".is_latlng?      # -> true

There is a Point class that's quite useful for geodetic calculations, and we provides some (tentative) help for your ActiveRecord classes:

class Checkpoint < ActiveRecord::Base
  has_gridref :lat => 'lat', 
              :lng => 'lng', 
              :gridref => 'gridref',
              :validation => false,
              :converstion => true

The :lat, :lng and :gridref keys should pass in the names of the relevant columns if they don't match these defaults.

Geodesy

By default we place our lat/long points on the WGS84 datum, since that's most relevant for online use. You can specify :osgb36 to keep them local:

"SD28687846".to_latlng(:osgb36)

which involves a bit less processing since that's the datum used by the grid. If you want to use some other datum you will need to define a Helmert transformation from OSGB36 to that ellipsoid.

Bugs and features

Github issues please, or for little things an email or github message is fine.

Author & Copyright

Copyright 2008-2011 Will at spanner.org.

Released under the same terms as Ruby