global_convert 0.0.1
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 +15 -0
- data/LICENSE +24 -0
- data/README.rdoc +47 -0
- data/Rakefile +28 -0
- data/lib/global_convert/location.rb +37 -0
- data/lib/global_convert/projection.rb +16 -0
- data/lib/global_convert/version.rb +9 -0
- data/lib/global_convert.rb +18 -0
- data/test/data/projections.yml +9 -0
- data/test/test_helper.rb +8 -0
- data/test/units/global_convert/location_test.rb +45 -0
- data/test/units/global_convert/projection_test.rb +16 -0
- data/test/units/global_convert_test.rb +14 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzIwNGU0NDc3YzYwZmI1YzY3MDVhZjIwMDhkYWM0YjRlY2U0YWY2Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2UyYmUwY2RhYWY4NmRiYWI1ZjFkMDI2ODgzYjk0ZWNmZGE5Mjg2Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjRhMzhlMjI0NmI5NDNiYmQ4ZDFkNGZhNDQ0ODBkZWEyNWJjMTI5NWZmMDk0
|
10
|
+
NmMxMzc3NTIzNGVmOTRkNTYxMWFiOWE1ZjAyNjhiMGZlZWJhODY3ZDc0Y2Y4
|
11
|
+
M2MxZGI1NDU1OGMwMTllNTZiZDFlMGFhMjljNzkyOTgwOTJkYzE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjEwYTc1NjdkMWJjN2JiMWFjOGU1YTFjYTNjMTYxNzVhN2IyNGE2MDAxZjNi
|
14
|
+
NGYxNmVkODA0MGU4NGVlYzAxYzIyMzM2MGRjZDAyOTgzMzBhNjJhODliMTdi
|
15
|
+
ZmJlMmE3YWJmZjg4ZTgxYjI0NjEyMmIzZmRmYmI0ZTJjMThhZWM=
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Global Convert
|
2
|
+
|
3
|
+
Copyright (c) 2014 Rob Nichols
|
4
|
+
|
5
|
+
MIT License
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= Global Convert
|
2
|
+
|
3
|
+
Tool for converting coordinates between different global charting systems.
|
4
|
+
|
5
|
+
This tool uses {PROJ.4}[http://trac.osgeo.org/proj/]
|
6
|
+
via the {proj4rb gem}[https://github.com/cfis/proj4rb]
|
7
|
+
to convert coordinates between global charting systems with different projections.
|
8
|
+
|
9
|
+
Global Convert was greatly influenced by Peter Hick's blog:
|
10
|
+
{Converting OSGB36 (Eastings/Northings) to WGS84 (Longitude/Latitude) in Ruby}[http://blog.poggs.com/index.php/2010/09/converting-osgb36-eastingsnorthings-to-wgs84-longitudelatitude-in-ruby/]
|
11
|
+
|
12
|
+
== UK Ordinance Survey National Grid references to Longitude / Latitude
|
13
|
+
|
14
|
+
require 'global_convert'
|
15
|
+
|
16
|
+
easting = 529978
|
17
|
+
northing = 186491
|
18
|
+
|
19
|
+
location = Location.new(
|
20
|
+
input: {
|
21
|
+
projection: :osgb36,
|
22
|
+
lon: easting,
|
23
|
+
lat: northing
|
24
|
+
},
|
25
|
+
output: {
|
26
|
+
projection: :wgs84
|
27
|
+
}
|
28
|
+
)
|
29
|
+
|
30
|
+
puts "Latitude = #{location.lat} in radians."
|
31
|
+
puts "Longitude = #{location.lon} in radians."
|
32
|
+
|
33
|
+
== Projections
|
34
|
+
|
35
|
+
Projections are defined via /data/projections.yml. This contains a labelled list of
|
36
|
+
PROJ.4 projection configurations. To use an alternative set of projections, define
|
37
|
+
your own projections using the same format as projections.yml and register that
|
38
|
+
with GlobalConvert.
|
39
|
+
|
40
|
+
GlobalConvert.projection_file_path = 'path/to/alternative/projections.yml'
|
41
|
+
|
42
|
+
Additional projection configurations can be found at:
|
43
|
+
|
44
|
+
* http://spatialreference.org/
|
45
|
+
* http://www.remotesensing.org/geotiff/proj_list/
|
46
|
+
|
47
|
+
The options are documented on the {PROJ.4 site}[http://trac.osgeo.org/proj/].
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rdoc/task'
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
Rake::RDocTask.new do |rdoc|
|
10
|
+
files =['README.rdoc', 'LICENSE', 'lib/**/*.rb']
|
11
|
+
rdoc.rdoc_files.add(files)
|
12
|
+
rdoc.main = "README.rdoc" # page to start on
|
13
|
+
rdoc.title = "Global Convert Docs"
|
14
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
15
|
+
rdoc.options << '--line-numbers'
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::TestTask.new do |t|
|
19
|
+
t.test_files = FileList['test/**/*.rb']
|
20
|
+
end
|
21
|
+
|
22
|
+
task :console do
|
23
|
+
require 'irb'
|
24
|
+
require 'irb/completion'
|
25
|
+
require 'global_convert'
|
26
|
+
ARGV.clear
|
27
|
+
IRB.start
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module GlobalConvert
|
2
|
+
class Location
|
3
|
+
attr_reader :input_projection_name, :output_projection_name, :input_lon, :input_lat
|
4
|
+
|
5
|
+
def initialize(args = {})
|
6
|
+
@input_projection_name = args[:input][:projection]
|
7
|
+
@output_projection_name = args[:output][:projection]
|
8
|
+
@input_lon = args[:input][:lon]
|
9
|
+
@input_lat = args[:input][:lat]
|
10
|
+
end
|
11
|
+
|
12
|
+
def lat
|
13
|
+
output_point.lat
|
14
|
+
end
|
15
|
+
|
16
|
+
def lon
|
17
|
+
output_point.lon
|
18
|
+
end
|
19
|
+
|
20
|
+
def input_projection
|
21
|
+
@input_projection ||= Projection.new input_projection_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def output_projection
|
25
|
+
@output_projection ||= Projection.new output_projection_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def input_point
|
29
|
+
@point ||= Proj4::Point.new(input_lon, input_lat)
|
30
|
+
end
|
31
|
+
|
32
|
+
def output_point
|
33
|
+
@outpoint_point ||= input_projection.transform(output_projection, input_point)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module GlobalConvert
|
4
|
+
class Projection < Proj4::Projection
|
5
|
+
def initialize(name)
|
6
|
+
raise 'Projection not found' unless settings = projections[name.to_s]
|
7
|
+
super(settings['projection'])
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def projections
|
12
|
+
YAML::load_file(GlobalConvert.projection_file_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'proj4rb'
|
3
|
+
require 'proj4'
|
4
|
+
|
5
|
+
require_relative 'global_convert/projection'
|
6
|
+
require_relative 'global_convert/location'
|
7
|
+
|
8
|
+
module GlobalConvert
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_writer :projection_file_path
|
12
|
+
|
13
|
+
def projection_file_path
|
14
|
+
@projection_file_path ||= File.expand_path('../data/projections.yml', File.dirname(__FILE__))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
wgs84:
|
2
|
+
name: WGS84 (Longitude/Latitude)
|
3
|
+
projection: +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
|
4
|
+
output_units: radians
|
5
|
+
|
6
|
+
osgb36:
|
7
|
+
name: OSGB36 (UK Ordinance Survey Eastings/Northings)
|
8
|
+
projection: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs
|
9
|
+
output_units: metres
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'global_convert'
|
5
|
+
|
6
|
+
GLOBAL_CONTRACT_PROJECTION_PATH = File.join(File.dirname(__FILE__),'data','projections.yml')
|
7
|
+
|
8
|
+
GlobalConvert.projection_file_path = GLOBAL_CONTRACT_PROJECTION_PATH
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module GlobalConvert
|
4
|
+
class LocationTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_easting_northing_to_lat_long
|
7
|
+
location = Location.new(
|
8
|
+
input: {
|
9
|
+
projection: :osgb36,
|
10
|
+
lon: easting,
|
11
|
+
lat: northing
|
12
|
+
},
|
13
|
+
output: {
|
14
|
+
projection: :wgs84
|
15
|
+
}
|
16
|
+
)
|
17
|
+
assert_equal dst_point.lat, location.lat
|
18
|
+
assert_equal dst_point.lon, location.lon
|
19
|
+
end
|
20
|
+
|
21
|
+
def long_lat_projection
|
22
|
+
Projection.new :wgs84
|
23
|
+
end
|
24
|
+
|
25
|
+
def os_projection
|
26
|
+
Projection.new :osgb36
|
27
|
+
end
|
28
|
+
|
29
|
+
def dst_point
|
30
|
+
@dst_point ||= os_projection.transform(long_lat_projection, src_point)
|
31
|
+
end
|
32
|
+
|
33
|
+
def src_point
|
34
|
+
Proj4::Point.new(easting, northing)
|
35
|
+
end
|
36
|
+
|
37
|
+
def easting
|
38
|
+
529978
|
39
|
+
end
|
40
|
+
|
41
|
+
def northing
|
42
|
+
186491
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module GlobalConvert
|
4
|
+
class ProjectionTest < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_new
|
7
|
+
assert_equal proj4_projection.to_s, Projection.new(:wgs84).to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def proj4_projection
|
12
|
+
@proj4_projection ||= Proj4::Projection.new('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class GlobalConvertTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def teardown
|
6
|
+
GlobalConvert.projection_file_path = GLOBAL_CONTRACT_PROJECTION_PATH
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_projection_file_path
|
10
|
+
path = 'foo/bar'
|
11
|
+
GlobalConvert.projection_file_path = path
|
12
|
+
assert_equal path, GlobalConvert.projection_file_path
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: global_convert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Nichols
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: proj4rb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Simplifies converting from longitudes and latitudes, to eastings and
|
28
|
+
northings.
|
29
|
+
email:
|
30
|
+
- rob@undervale.co.uk
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/global_convert/location.rb
|
36
|
+
- lib/global_convert/version.rb
|
37
|
+
- lib/global_convert/projection.rb
|
38
|
+
- lib/global_convert.rb
|
39
|
+
- LICENSE
|
40
|
+
- Rakefile
|
41
|
+
- README.rdoc
|
42
|
+
- test/units/global_convert_test.rb
|
43
|
+
- test/units/global_convert/projection_test.rb
|
44
|
+
- test/units/global_convert/location_test.rb
|
45
|
+
- test/data/projections.yml
|
46
|
+
- test/test_helper.rb
|
47
|
+
homepage: https://github.com/reggieb/global_convert
|
48
|
+
licenses:
|
49
|
+
- LICENSE
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.1.10
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Tool for converting coordinates between different global charting systems
|
71
|
+
test_files:
|
72
|
+
- test/units/global_convert_test.rb
|
73
|
+
- test/units/global_convert/projection_test.rb
|
74
|
+
- test/units/global_convert/location_test.rb
|
75
|
+
- test/data/projections.yml
|
76
|
+
- test/test_helper.rb
|