osgb 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # OSGB
2
2
 
3
- Osgb is a library that converts between British (and Irish) grid references and latitude and longitude co-ordinates. It is theoretically precise to about 1m, which is to say it's good for WGS84 and most GPS use but not up to surveying with ITRS or ETRS89. So don't do that.
3
+ 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.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,14 +22,15 @@ Early days: activerecord interface hasn't settled down, some refactoring likely,
22
22
 
23
23
  ## Usage
24
24
 
25
- You don't need to make any explicit reference to the gem. It adds conversion methods to the String class:
25
+ You don't need to make any explicit reference to the gem. It adds conversion and utility methods to the String class:
26
26
 
27
27
  "SD28687846".is_gridref? # -> true
28
- "SD28687846".to_latlng # -> [54.196763, -3.093320]
28
+ "SD28687846".to_latlng # -> [54.196915, -3.094684]
29
29
  "SD28687846".to_wgs84 # -> [54.196915, -3.094684]
30
+ "SD28687846".to_osgb36 # -> [54.196763, -3.093320]
30
31
  "1.056789, 55.98978607".is_latlng? # -> true
31
-
32
- and provides some (tentative) help for your ActiveRecord classes:
32
+
33
+ There is a Point class that's quite useful for geodetic calculations, and we provides some (tentative) help for your ActiveRecord classes:
33
34
 
34
35
  class Checkpoint < ActiveRecord::Base
35
36
  has_gridref :lat => 'lat',
@@ -40,6 +41,14 @@ and provides some (tentative) help for your ActiveRecord classes:
40
41
 
41
42
  The :lat, :lng and :gridref keys should pass in the names of the relevant columns if they don't match these defaults.
42
43
 
44
+ ## Geodesy
45
+
46
+ 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:
47
+
48
+ "SD28687846".to_latlng(:osgb36)
49
+
50
+ 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.
51
+
43
52
  ## Bugs and features
44
53
 
45
54
  [Github issues](http://github.com/spanner/osgb/issues) please, or for little things an email or github message is fine.
@@ -1,9 +1,11 @@
1
+ require 'osgb/exceptions' # specific error conditions we might want to catch
1
2
  require 'osgb/angle_conversions' # converts degrees to radians and back again
2
3
  require 'osgb/ellipsoid' # standard approximations to the squashed-circle shape of the earth
3
4
  require 'osgb/projection' # the geometrical distortions required by a map projection
4
5
  require 'osgb/helmert' # 3d transformation algorithm for mapping between cartesian and ellipsoidal polar coordinates
5
6
  require 'osgb/point' # versatile coordinate pair
6
7
  require 'osgb/gridref' # parse grid references and returns lat/long pairs
8
+ require 'osgb/has_gridref' # ActiveRecord helpers
7
9
  require 'osgb/string_conversions' # add conversion methods to String
8
10
  require 'osgb/railtie' if defined? Rails # add useful methods to ActiveRecord
9
11
 
@@ -0,0 +1,5 @@
1
+ module Osgb
2
+ class OsgbError < StandardError; end
3
+ class OsgbConfigurationError < Osgb::OsgbError; end
4
+ class OsgbConversionError < Osgb::OsgbError; end
5
+ end
@@ -12,7 +12,7 @@ module Osgb
12
12
  module ClassMethods
13
13
  def has_gridref name, options = {}
14
14
  include Osgb::InstanceMethods
15
- osgb_options = {
15
+ self.osgb_options = {
16
16
  :lat => 'lat',
17
17
  :lng => 'lng',
18
18
  :gridref => 'gridref',
@@ -30,16 +30,23 @@ module Osgb
30
30
  end
31
31
 
32
32
  def convert_between_gridref_and_latlng
33
- cols = self.class.osgb_options
34
- if columns.include?(cols[:lat], cols[:lng], cols[:gridref])
35
- if send("#{cols[:gridref]}_changed?") || !send("#{cols[:lat]}?") || !send("#{cols[:lng]}?")
36
- latlng = gridref.coordinates
37
- send("#{cols[:lat]}=", latlng[0])
38
- send("#{cols[:lng]}=", latlng[1])
39
- elsif send("#{cols[:lat]}_changed?") || send("#{cols[:lng]}_changed?") || !send("#{cols[:gridref]}?")
40
- send("#{cols[:gridref]}=", Osgb::Gridref.from(send(cols[:lat]), send(cols[:lng])))
33
+ options = self.class.osgb_options
34
+ cols = self.class.column_names
35
+ if cols.include?(options[:lat]) && cols.include?(options[:lng]) && cols.include?(options[:gridref])
36
+
37
+ if send("#{options[:gridref]}_changed?") || !send("#{options[:lat]}?") || !send("#{options[:lng]}?")
38
+ point = gridref.to_latlng
39
+ send("#{options[:lat]}=", point.lat)
40
+ send("#{options[:lng]}=", point.lng)
41
+
42
+ elsif send("#{options[:lat]}_changed?") || send("#{options[:lng]}_changed?") || !send("#{options[:gridref]}?")
43
+ send("#{options[:gridref]}=", Osgb::Gridref.from(send(options[:lat]), send(options[:lng])))
41
44
  end
45
+
46
+ else
47
+ raise Osgb::OsgbConfigurationError "OSGB was expecting to see #{options[:lat]}, #{options[:lng]} and #{options[:gridref]} columns."
42
48
  end
43
49
  end
50
+
44
51
  end
45
52
  end
@@ -9,9 +9,6 @@ module Osgb
9
9
  Osgb::Railtie.insert
10
10
  end
11
11
  end
12
- rake_tasks do
13
- load "tasks/osgb.rake"
14
- end
15
12
  end
16
13
  end
17
14
 
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :osgb do
3
+ # # Task goes here
4
+ # end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osgb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - William Ross
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-25 00:00:00 Z
18
+ date: 2013-04-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -33,23 +33,7 @@ dependencies:
33
33
  version: 2.6.0
34
34
  type: :development
35
35
  version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rails
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 21
45
- segments:
46
- - 3
47
- - 0
48
- - 9
49
- version: 3.0.9
50
- type: :development
51
- version_requirements: *id002
52
- description: Supports the use of Ordnance Survey Grid References in place of lat/lng pairs. Includes activerecord plugin.
36
+ description: Converts between Ordnance Survey grid references and lat/long points, including transformation between datums so that you can turn grid references into GPS points.
53
37
  email: will@spanner.org
54
38
  executables: []
55
39
 
@@ -60,6 +44,7 @@ extra_rdoc_files: []
60
44
  files:
61
45
  - lib/osgb/angle_conversions.rb
62
46
  - lib/osgb/ellipsoid.rb
47
+ - lib/osgb/exceptions.rb
63
48
  - lib/osgb/gridref.rb
64
49
  - lib/osgb/has_gridref.rb
65
50
  - lib/osgb/helmert.rb
@@ -68,6 +53,7 @@ files:
68
53
  - lib/osgb/railtie.rb
69
54
  - lib/osgb/string_conversions.rb
70
55
  - lib/osgb.rb
56
+ - lib/tasks/osgb_tasks.rake
71
57
  - spec/point_spec.rb
72
58
  - spec/spec_helper.rb
73
59
  - spec/string_spec.rb