proj4rb 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,61 +1,61 @@
1
- module Proj
2
- # Transformation objects convert {Coordinate Coordinates} from one {Crs} to another.
3
- class Transformation < PjObject
4
- # Transforms a {Coordinate} from the source {Crs} to the target {Crs}. Coordinates should be expressed in
5
- # the units and axis order of the definition of the source CRS. The returned transformed coordinate will
6
- # be in the units and axis order of the definition of the target CRS.
7
- #
8
- # For most geographic Crses, the units will be in degrees. For geographic CRS defined by the EPSG authority,
9
- # the order of coordinates is latitude first, longitude second. When using a PROJ initialization string,
10
- # on contrary, the order will be longitude first, latitude second.
11
- #
12
- # For projected CRS, the units may vary (metre, us-foot, etc..).
13
- #
14
- # For projected CRS defined by the EPSG authority, and with EAST / NORTH directions, the axis order might be
15
- # easting first, northing second, or the reverse. When using a PROJ string, the order will be
16
- # easting first, northing second, except if the +axis parameter modifies it.
17
- #
18
- # @param source [Crs | String] - The source Crs. See the Crs documentation for the string format
19
- # @param target [Crs | String] - The target Crs. See the Crs documentation for the string format
20
- # @param context [Context]
21
- def initialize(source, target, context=nil)
22
- pointer = if source.is_a?(Crs) && target.is_a?(Crs)
23
- if Api.method_defined?(:proj_create_crs_to_crs_from_pj)
24
- Api.proj_create_crs_to_crs_from_pj(context, source, target, nil, nil)
25
- else
26
- Api.proj_create_crs_to_crs(context, source.definition, target.definition, nil)
27
- end
28
- else
29
- Api.proj_create_crs_to_crs(context, source, target, nil)
30
- end
31
-
32
- if pointer.null?
33
- Error.check
34
- end
35
-
36
- super(pointer, context)
37
- end
38
-
39
- # Transforms a {Coordinate} from the source {Crs} to the target {Crs}. Coordinates should be expressed in
40
- # the units and axis order of the definition of the source CRS. The returned transformed coordinate will
41
- # be in the units and axis order of the definition of the target CRS.
42
- #
43
- # @param coord [Coordinate]
44
- # @return [Coordinate]
45
- def forward(coord)
46
- struct = Api.proj_trans(self, :PJ_FWD, coord)
47
- Coordinate.from_coord(struct)
48
- end
49
-
50
- # Transforms a {Coordinate} from the target {Crs} to the source {Crs}. Coordinates should be expressed in
51
- # the units and axis order of the definition of the source CRS. The returned transformed coordinate will
52
- # be in the units and axis order of the definition of the target CRS.
53
- #
54
- # @param coord [Coordinate]
55
- # @return [Coordinate]
56
- def inverse(coord)
57
- struct = Api.proj_trans(self, :PJ_INV, coord)
58
- Coordinate.from_coord(struct)
59
- end
60
- end
1
+ module Proj
2
+ # Transformation objects convert {Coordinate Coordinates} from one {Crs} to another.
3
+ class Transformation < PjObject
4
+ # Transforms a {Coordinate} from the source {Crs} to the target {Crs}. Coordinates should be expressed in
5
+ # the units and axis order of the definition of the source CRS. The returned transformed coordinate will
6
+ # be in the units and axis order of the definition of the target CRS.
7
+ #
8
+ # For most geographic Crses, the units will be in degrees. For geographic CRS defined by the EPSG authority,
9
+ # the order of coordinates is latitude first, longitude second. When using a PROJ initialization string,
10
+ # on contrary, the order will be longitude first, latitude second.
11
+ #
12
+ # For projected CRS, the units may vary (metre, us-foot, etc..).
13
+ #
14
+ # For projected CRS defined by the EPSG authority, and with EAST / NORTH directions, the axis order might be
15
+ # easting first, northing second, or the reverse. When using a PROJ string, the order will be
16
+ # easting first, northing second, except if the +axis parameter modifies it.
17
+ #
18
+ # @param source [Crs | String] - The source Crs. See the Crs documentation for the string format
19
+ # @param target [Crs | String] - The target Crs. See the Crs documentation for the string format
20
+ # @param context [Context]
21
+ def initialize(source, target, context=nil)
22
+ pointer = if source.is_a?(Crs) && target.is_a?(Crs)
23
+ if Api.method_defined?(:proj_create_crs_to_crs_from_pj)
24
+ Api.proj_create_crs_to_crs_from_pj(context, source, target, nil, nil)
25
+ else
26
+ Api.proj_create_crs_to_crs(context, source.definition, target.definition, nil)
27
+ end
28
+ else
29
+ Api.proj_create_crs_to_crs(context, source, target, nil)
30
+ end
31
+
32
+ if pointer.null?
33
+ Error.check
34
+ end
35
+
36
+ super(pointer, context)
37
+ end
38
+
39
+ # Transforms a {Coordinate} from the source {Crs} to the target {Crs}. Coordinates should be expressed in
40
+ # the units and axis order of the definition of the source CRS. The returned transformed coordinate will
41
+ # be in the units and axis order of the definition of the target CRS.
42
+ #
43
+ # @param coord [Coordinate]
44
+ # @return [Coordinate]
45
+ def forward(coord)
46
+ struct = Api.proj_trans(self, :PJ_FWD, coord)
47
+ Coordinate.from_coord(struct)
48
+ end
49
+
50
+ # Transforms a {Coordinate} from the target {Crs} to the source {Crs}. Coordinates should be expressed in
51
+ # the units and axis order of the definition of the source CRS. The returned transformed coordinate will
52
+ # be in the units and axis order of the definition of the target CRS.
53
+ #
54
+ # @param coord [Coordinate]
55
+ # @return [Coordinate]
56
+ def inverse(coord)
57
+ struct = Api.proj_trans(self, :PJ_INV, coord)
58
+ Coordinate.from_coord(struct)
59
+ end
60
+ end
61
61
  end
@@ -1,54 +1,54 @@
1
- module Proj
2
- class Unit
3
- attr_reader :id, :to_meter, :factor, :name
4
-
5
- def self.list
6
- # First get linear units
7
- pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_units)
8
- result = Array.new
9
- 0.step do |i|
10
- ellipse_info = Api::PJ_UNITS.new(pointer_to_array[i])
11
- break if ellipse_info[:id].nil?
12
- result << self.new(ellipse_info[:id], ellipse_info[:to_meter], ellipse_info[:factor], ellipse_info[:name])
13
- end
14
-
15
- # Now get angular linear units
16
- if Api.method_defined?(:proj_list_angular_units)
17
- pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_angular_units)
18
- 0.step do |i|
19
- ellipse_info = Api::PJ_UNITS.new(pointer_to_array[i])
20
- break result if ellipse_info[:id].nil?
21
- result << self.new(ellipse_info[:id], ellipse_info[:to_meter], ellipse_info[:factor], ellipse_info[:name])
22
- end
23
- end
24
- result
25
- end
26
-
27
- def self.get(id)
28
- self.list.find {|ellipsoid| ellipsoid.id == id}
29
- end
30
-
31
- def initialize(id, to_meter, factor, name)
32
- @id = id
33
- @to_meter = to_meter
34
- @factor = factor
35
- @name = name
36
- end
37
-
38
- def <=>(other)
39
- self.id <=> other.id
40
- end
41
-
42
- def ==(other)
43
- self.id == other.id
44
- end
45
-
46
- def to_s
47
- self.id
48
- end
49
-
50
- def inspect
51
- "#<#{self.class} id=\"#{id}\", to_meter=\"#{to_meter}\", factor=\"#{factor}\", name=\"#{name}\">"
52
- end
53
- end
1
+ module Proj
2
+ class Unit
3
+ attr_reader :id, :to_meter, :factor, :name
4
+
5
+ def self.list
6
+ # First get linear units
7
+ pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_units)
8
+ result = Array.new
9
+ 0.step do |i|
10
+ ellipse_info = Api::PJ_UNITS.new(pointer_to_array[i])
11
+ break if ellipse_info[:id].nil?
12
+ result << self.new(ellipse_info[:id], ellipse_info[:to_meter], ellipse_info[:factor], ellipse_info[:name])
13
+ end
14
+
15
+ # Now get angular linear units
16
+ if Api.method_defined?(:proj_list_angular_units)
17
+ pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_angular_units)
18
+ 0.step do |i|
19
+ ellipse_info = Api::PJ_UNITS.new(pointer_to_array[i])
20
+ break result if ellipse_info[:id].nil?
21
+ result << self.new(ellipse_info[:id], ellipse_info[:to_meter], ellipse_info[:factor], ellipse_info[:name])
22
+ end
23
+ end
24
+ result
25
+ end
26
+
27
+ def self.get(id)
28
+ self.list.find {|ellipsoid| ellipsoid.id == id}
29
+ end
30
+
31
+ def initialize(id, to_meter, factor, name)
32
+ @id = id
33
+ @to_meter = to_meter
34
+ @factor = factor
35
+ @name = name
36
+ end
37
+
38
+ def <=>(other)
39
+ self.id <=> other.id
40
+ end
41
+
42
+ def ==(other)
43
+ self.id == other.id
44
+ end
45
+
46
+ def to_s
47
+ self.id
48
+ end
49
+
50
+ def inspect
51
+ "#<#{self.class} id=\"#{id}\", to_meter=\"#{to_meter}\", factor=\"#{factor}\", name=\"#{name}\">"
52
+ end
53
+ end
54
54
  end
@@ -1,33 +1,33 @@
1
- Gem::Specification.new do |spec|
2
- spec.name = 'proj4rb'
3
- spec.version = '2.2.1'
4
- spec.summary = 'Ruby bindings for the Proj.4 Carthographic Projection library'
5
- spec.description = <<-EOF
6
- Proj4rb is a ruby binding for the Proj.4 Carthographic Projection library, that supports conversions between a very large number of geographic coordinate systems and datumspec.
7
- EOF
8
- spec.platform = Gem::Platform::RUBY
9
- spec.authors = ['Guilhem Vellut', 'Jochen Topf', 'Charlie Savage']
10
- spec.homepage = 'https://github.com/cfis/proj4rb'
11
- spec.required_ruby_version = '>= 2.4.1'
12
- spec.license = 'MIT'
13
-
14
- spec.requirements << 'Proj (Proj4) Library'
15
- spec.require_path = 'lib'
16
- spec.files = Dir['ChangeLog',
17
- 'Gemfile',
18
- 'MIT-LICENSE',
19
- 'proj4rb.gemspec',
20
- 'Rakefile',
21
- 'README.rdoc',
22
- 'lib/**/*.rb',
23
- 'test/*.rb']
24
-
25
- spec.test_files = Dir["test/test_*.rb"]
26
-
27
- spec.add_dependency "ffi"
28
-
29
- spec.add_development_dependency('bundler')
30
- spec.add_development_dependency('rake')
31
- spec.add_development_dependency('minitest')
32
- spec.add_development_dependency('yard')
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'proj4rb'
3
+ spec.version = '2.2.2'
4
+ spec.summary = 'Ruby bindings for the Proj.4 Carthographic Projection library'
5
+ spec.description = <<-EOF
6
+ Proj4rb is a ruby binding for the Proj.4 Carthographic Projection library, that supports conversions between a very large number of geographic coordinate systems and datumspec.
7
+ EOF
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.authors = ['Guilhem Vellut', 'Jochen Topf', 'Charlie Savage']
10
+ spec.homepage = 'https://github.com/cfis/proj4rb'
11
+ spec.required_ruby_version = '>= 2.4.1'
12
+ spec.license = 'MIT'
13
+
14
+ spec.requirements << 'Proj (Proj4) Library'
15
+ spec.require_path = 'lib'
16
+ spec.files = Dir['ChangeLog',
17
+ 'Gemfile',
18
+ 'MIT-LICENSE',
19
+ 'proj4rb.gemspec',
20
+ 'Rakefile',
21
+ 'README.rdoc',
22
+ 'lib/**/*.rb',
23
+ 'test/*.rb']
24
+
25
+ spec.test_files = Dir["test/test_*.rb"]
26
+
27
+ spec.add_dependency "ffi"
28
+
29
+ spec.add_development_dependency('bundler')
30
+ spec.add_development_dependency('rake')
31
+ spec.add_development_dependency('minitest')
32
+ spec.add_development_dependency('yard')
33
33
  end
@@ -1,7 +1,7 @@
1
- require 'bundler/setup'
2
- require 'minitest/autorun'
3
- require 'proj'
4
-
5
- class AbstractTest < Minitest::Test
6
- end
7
-
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'proj'
4
+
5
+ class AbstractTest < Minitest::Test
6
+ end
7
+
@@ -1,82 +1,82 @@
1
- # encoding: UTF-8
2
-
3
- require_relative './abstract_test'
4
-
5
- class ContextTest < AbstractTest
6
- def test_create
7
- context = Proj::Context.new
8
- assert(context.to_ptr)
9
- end
10
-
11
- def test_finalize
12
- 500.times do
13
- context = Proj::Context.new
14
- assert(context.to_ptr)
15
- GC.start
16
- end
17
- assert(true)
18
- end
19
-
20
- def test_one_per_thread
21
- context_1 = Proj::Context.current
22
- context_2 = Proj::Context.current
23
- assert_same(context_1, context_2)
24
- end
25
-
26
- def test_database_path
27
- refute_nil(Proj::Context.current.database_path)
28
- end
29
-
30
- def test_log_level
31
- assert_equal(:PJ_LOG_NONE, Proj::Context.current.log_level)
32
- end
33
-
34
- def test_set_log_level
35
- context = Proj::Context.new
36
- context.log_level = :PJ_LOG_ERROR
37
- assert_equal(:PJ_LOG_ERROR, context.log_level)
38
- end
39
-
40
- def test_invalid_database_path
41
- path = '/wrong'
42
- error = assert_raises(Proj::Error) do
43
- Proj::Context.current.database_path = path
44
- end
45
- # TODO - if you run this test on its own you get a useful error message, if you run all tests
46
- # at once you get a useless error message. Not sure what is causing the difference
47
- assert_match(/No such file or directory|generic error of unknown origin/, error.to_s)
48
- end
49
-
50
- def test_set_log_function
51
- context = Proj::Context.new
52
- called = false
53
-
54
- data = FFI::MemoryPointer.new(:int)
55
- data.write_int(5)
56
-
57
- context.set_log_function(data) do |pointer, int, message|
58
- called = true
59
- refute(pointer.null?)
60
- assert_equal(5, pointer.read_int)
61
- assert_equal(1, int)
62
- assert_equal('proj_context_set_database_path: Open of /wrong failed', message)
63
- end
64
-
65
- begin
66
- context.database_path = '/wrong'
67
- rescue
68
- end
69
-
70
- assert(called)
71
- end
72
-
73
- def test_use_proj4_init_rules
74
- refute(Proj::Context.current.use_proj4_init_rules)
75
-
76
- Proj::Context.current.use_proj4_init_rules = true
77
- assert(Proj::Context.current.use_proj4_init_rules)
78
-
79
- Proj::Context.current.use_proj4_init_rules = false
80
- refute(Proj::Context.current.use_proj4_init_rules)
81
- end
1
+ # encoding: UTF-8
2
+
3
+ require_relative './abstract_test'
4
+
5
+ class ContextTest < AbstractTest
6
+ def test_create
7
+ context = Proj::Context.new
8
+ assert(context.to_ptr)
9
+ end
10
+
11
+ def test_finalize
12
+ 500.times do
13
+ context = Proj::Context.new
14
+ assert(context.to_ptr)
15
+ GC.start
16
+ end
17
+ assert(true)
18
+ end
19
+
20
+ def test_one_per_thread
21
+ context_1 = Proj::Context.current
22
+ context_2 = Proj::Context.current
23
+ assert_same(context_1, context_2)
24
+ end
25
+
26
+ def test_database_path
27
+ refute_nil(Proj::Context.current.database_path)
28
+ end
29
+
30
+ def test_log_level
31
+ assert_equal(:PJ_LOG_NONE, Proj::Context.current.log_level)
32
+ end
33
+
34
+ def test_set_log_level
35
+ context = Proj::Context.new
36
+ context.log_level = :PJ_LOG_ERROR
37
+ assert_equal(:PJ_LOG_ERROR, context.log_level)
38
+ end
39
+
40
+ def test_invalid_database_path
41
+ path = '/wrong'
42
+ error = assert_raises(Proj::Error) do
43
+ Proj::Context.current.database_path = path
44
+ end
45
+ # TODO - if you run this test on its own you get a useful error message, if you run all tests
46
+ # at once you get a useless error message. Not sure what is causing the difference
47
+ assert_match(/No such file or directory|generic error of unknown origin/, error.to_s)
48
+ end
49
+
50
+ def test_set_log_function
51
+ context = Proj::Context.new
52
+ called = false
53
+
54
+ data = FFI::MemoryPointer.new(:int)
55
+ data.write_int(5)
56
+
57
+ context.set_log_function(data) do |pointer, int, message|
58
+ called = true
59
+ refute(pointer.null?)
60
+ assert_equal(5, pointer.read_int)
61
+ assert_equal(1, int)
62
+ assert_equal('proj_context_set_database_path: Open of /wrong failed', message)
63
+ end
64
+
65
+ begin
66
+ context.database_path = '/wrong'
67
+ rescue
68
+ end
69
+
70
+ assert(called)
71
+ end
72
+
73
+ def test_use_proj4_init_rules
74
+ refute(Proj::Context.current.use_proj4_init_rules)
75
+
76
+ Proj::Context.current.use_proj4_init_rules = true
77
+ assert(Proj::Context.current.use_proj4_init_rules)
78
+
79
+ Proj::Context.current.use_proj4_init_rules = false
80
+ refute(Proj::Context.current.use_proj4_init_rules)
81
+ end
82
82
  end