os_map_ref 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +47 -3
- data/Rakefile +3 -1
- data/lib/os_map_ref/location.rb +23 -23
- data/lib/os_map_ref/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ae3fcaaf973eec7b4724150197b0ab202538be
|
4
|
+
data.tar.gz: 08a5ebe1a235a599ea73648a2b0a8718134f3b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de6195a4927e318ebc2c00cf8c61677ee3a9d144cbbf1cd3a76ce80920e5768ff4a2810272d979917e90a39841f2866d4e55dbcc360c65513231be3b93b4b322
|
7
|
+
data.tar.gz: e21af0b63498777aa48e6ec7b2e6ab6dc1ac5dc6ece9f94b9eb9c3e7fc397f2fb8e409adf3a219fdbb52be4441a7a7fa6a25e29c83c7280a267accf733d826f2
|
data/README.md
CHANGED
@@ -41,15 +41,59 @@ location.northing == 171043
|
|
41
41
|
location.map_reference == 'ST 58801 71043'
|
42
42
|
```
|
43
43
|
|
44
|
+
### From OS Map Reference to Longitude and Latitude
|
45
|
+
|
46
|
+
If your end result needs to be longitude and latitude, you can combine the
|
47
|
+
OsMapRef output with that of another gem:
|
48
|
+
[global_convert](https://github.com/reggieb/global_convert)
|
49
|
+
|
50
|
+
For example
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
require 'global_convert'
|
54
|
+
require 'os_map_ref'
|
55
|
+
|
56
|
+
os_location = OsMapRef::Location.for 'ST 58801 71043'
|
57
|
+
|
58
|
+
location = GlobalConvert::Location.new(
|
59
|
+
input: {
|
60
|
+
projection: :osgb36,
|
61
|
+
lon: os_location.easting,
|
62
|
+
lat: os_location.northing
|
63
|
+
},
|
64
|
+
output: {
|
65
|
+
projection: :wgs84
|
66
|
+
}
|
67
|
+
)
|
68
|
+
|
69
|
+
puts "Latitude = #{location.lat} in radians."
|
70
|
+
puts "Longitude = #{location.lon} in radians."
|
71
|
+
```
|
72
|
+
|
44
73
|
## Development
|
45
74
|
|
46
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
47
|
-
Then, run `rake test` to run the tests. You can also run `bin/console`
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
76
|
+
Then, run `rake test` to run the tests. You can also run `bin/console`
|
48
77
|
for an interactive prompt that will allow you to experiment.
|
49
78
|
|
50
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
51
80
|
|
52
81
|
## Contributing
|
53
82
|
|
54
83
|
Bug reports and pull requests are welcome on GitHub at https://github.com/reggieb/os_map_ref.
|
55
84
|
|
85
|
+
## License
|
86
|
+
|
87
|
+
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
|
88
|
+
|
89
|
+
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
|
90
|
+
|
91
|
+
The following attribution statement MUST be cited in your products and applications when using this information.
|
92
|
+
|
93
|
+
> Contains public sector information licensed under the Open Government license v3
|
94
|
+
|
95
|
+
### About the license
|
96
|
+
|
97
|
+
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
|
98
|
+
|
99
|
+
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.
|
data/Rakefile
CHANGED
data/lib/os_map_ref/location.rb
CHANGED
@@ -1,92 +1,92 @@
|
|
1
1
|
require 'matrix'
|
2
2
|
module OsMapRef
|
3
3
|
class Location
|
4
|
-
|
4
|
+
|
5
5
|
def self.for(text)
|
6
6
|
input_processor = InputProcessor.new(text)
|
7
7
|
new input_processor.params
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(args={})
|
11
11
|
@map_reference = args[:map_reference].freeze if args[:map_reference]
|
12
12
|
@easting = args[:easting].to_i if args[:easting]
|
13
13
|
@northing = args[:northing].to_i if args[:northing]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def map_reference
|
17
17
|
@map_reference ||= build_map_reference.freeze
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def build_map_reference
|
21
21
|
[grid_reference_prefix, short_easting, short_northing].join(' ')
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def grid_easting
|
25
25
|
easting.to_s[0].to_i
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def short_easting
|
29
29
|
easting.to_s[1..-1].to_i
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def long_northing?
|
33
33
|
northing.to_s.length >= 7
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def grid_northing
|
37
37
|
northing.to_s[0..(chars_in_northing_start - 1)].to_i
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def short_northing
|
41
41
|
northing.to_s[chars_in_northing_start..-1].to_i
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def chars_in_northing_start
|
45
45
|
long_northing? ? 2 : 1
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def grid_reference_prefix
|
49
49
|
grid[grid_northing][grid_easting]
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def easting
|
53
53
|
@easting ||= easting_from_map_reference.to_i
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def northing
|
57
57
|
@northing ||= northing_from_map_reference.to_i
|
58
|
-
end
|
59
|
-
|
58
|
+
end
|
59
|
+
|
60
60
|
def northing_from_map_reference
|
61
61
|
northing_easting_from_map_reference[0].to_s + map_reference_parts[2]
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def easting_from_map_reference
|
65
65
|
northing_easting_from_map_reference[1].to_s + map_reference_parts[1]
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# The parts should be a pair of letters then two sets of numbers
|
69
|
-
# 'ST 58901 71053' becomes ['ST', '58901', '71053']
|
69
|
+
# 'ST 58901 71053' becomes ['ST', '58901', '71053']
|
70
70
|
def map_reference_parts
|
71
71
|
@map_reference_parts ||= map_reference.split
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# Returns array of [grid_northing, grid_easting] for the gird element
|
75
75
|
# matching the map reference start. So 'ST 58901 71053' will return [1, 3]
|
76
76
|
def northing_easting_from_map_reference
|
77
77
|
@northing_easting_from_map_reference ||= matrix.index map_reference_parts[0]
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def matrix
|
81
81
|
@matrix ||= Matrix[*grid]
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
# Grid of 100km squares as they are arranged over the UK.
|
85
|
-
# The grid is reversed so that the origin (0,0) is the
|
85
|
+
# The grid is reversed so that the origin (0,0) is the
|
86
86
|
# bottom left corner ('SV').
|
87
87
|
def grid
|
88
88
|
@grid ||= [
|
89
|
-
%w[HL HM HN HO HP JL JM
|
89
|
+
%w[HL HM HN HO HP JL JM JN JO JP],
|
90
90
|
%w[HQ HR HS HT HU JQ JR JS JT JU],
|
91
91
|
%w[HV HW HX HY HZ JV JW JX JY JZ],
|
92
92
|
%w[NA NB NC ND NE OA OB OC OD OE],
|
data/lib/os_map_ref/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: os_map_ref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Nichols
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|