proj4rb 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +66 -61
- data/Gemfile +4 -4
- data/Rakefile +27 -27
- data/lib/api/api.rb +110 -83
- data/lib/api/api_4_9.rb +30 -30
- data/lib/api/api_5_0.rb +300 -300
- data/lib/api/api_5_1.rb +6 -6
- data/lib/api/api_5_2.rb +4 -4
- data/lib/api/api_6_0.rb +41 -42
- data/lib/api/api_6_1.rb +4 -4
- data/lib/api/api_6_2.rb +6 -5
- data/lib/area.rb +32 -32
- data/lib/config.rb +69 -69
- data/lib/context.rb +102 -102
- data/lib/coordinate.rb +197 -197
- data/lib/crs.rb +204 -204
- data/lib/ellipsoid.rb +41 -41
- data/lib/error.rb +17 -17
- data/lib/operation.rb +42 -42
- data/lib/pj_object.rb +80 -80
- data/lib/point.rb +72 -72
- data/lib/prime_meridian.rb +39 -39
- data/lib/proj.rb +30 -30
- data/lib/projection.rb +206 -206
- data/lib/transformation.rb +60 -60
- data/lib/unit.rb +53 -53
- data/proj4rb.gemspec +32 -32
- data/test/abstract_test.rb +7 -7
- data/test/context_test.rb +81 -81
- data/test/coordinate_test.rb +34 -34
- data/test/crs_test.rb +372 -372
- data/test/ellipsoid_test.rb +34 -34
- data/test/operation_test.rb +29 -29
- data/test/prime_meridians_test.rb +33 -33
- data/test/proj_test.rb +16 -16
- data/test/projection_test.rb +223 -223
- data/test/transformation_test.rb +67 -67
- data/test/unit_test.rb +47 -47
- metadata +2 -2
data/lib/ellipsoid.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
module Proj
|
2
|
-
class Ellipsoid
|
3
|
-
attr_reader :id, :major, :ell, :name
|
4
|
-
|
5
|
-
def self.list
|
6
|
-
pointer_to_array = FFI::Pointer.new(Api::PJ_ELLPS, Api.proj_list_ellps)
|
7
|
-
result = Array.new
|
8
|
-
0.step do |i|
|
9
|
-
ellipse_info = Api::PJ_ELLPS.new(pointer_to_array[i])
|
10
|
-
break result if ellipse_info[:id].nil?
|
11
|
-
result << self.new(ellipse_info[:id], ellipse_info[:major], ellipse_info[:ell], ellipse_info[:name])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.get(id)
|
16
|
-
self.list.find {|ellipsoid| ellipsoid.id == id}
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(id, major, ell, name)
|
20
|
-
@id = id
|
21
|
-
@major = major
|
22
|
-
@ell = ell
|
23
|
-
@name = name
|
24
|
-
end
|
25
|
-
|
26
|
-
def <=>(other)
|
27
|
-
self.id <=> other.id
|
28
|
-
end
|
29
|
-
|
30
|
-
def ==(other)
|
31
|
-
self.id == other.id
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
self.id
|
36
|
-
end
|
37
|
-
|
38
|
-
def inspect
|
39
|
-
"#<#{self.class} id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module Proj
|
2
|
+
class Ellipsoid
|
3
|
+
attr_reader :id, :major, :ell, :name
|
4
|
+
|
5
|
+
def self.list
|
6
|
+
pointer_to_array = FFI::Pointer.new(Api::PJ_ELLPS, Api.proj_list_ellps)
|
7
|
+
result = Array.new
|
8
|
+
0.step do |i|
|
9
|
+
ellipse_info = Api::PJ_ELLPS.new(pointer_to_array[i])
|
10
|
+
break result if ellipse_info[:id].nil?
|
11
|
+
result << self.new(ellipse_info[:id], ellipse_info[:major], ellipse_info[:ell], ellipse_info[:name])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get(id)
|
16
|
+
self.list.find {|ellipsoid| ellipsoid.id == id}
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(id, major, ell, name)
|
20
|
+
@id = id
|
21
|
+
@major = major
|
22
|
+
@ell = ell
|
23
|
+
@name = name
|
24
|
+
end
|
25
|
+
|
26
|
+
def <=>(other)
|
27
|
+
self.id <=> other.id
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(other)
|
31
|
+
self.id == other.id
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
self.id
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
"#<#{self.class} id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
|
40
|
+
end
|
41
|
+
end
|
42
42
|
end
|
data/lib/error.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
module Proj
|
2
|
-
class Error < StandardError
|
3
|
-
def self.check(errno=nil)
|
4
|
-
unless errno
|
5
|
-
errno = Context.current.errno
|
6
|
-
end
|
7
|
-
|
8
|
-
if errno != 0
|
9
|
-
message = if Api.method_defined?(:proj_errno_string)
|
10
|
-
Api.proj_errno_string(errno)
|
11
|
-
else
|
12
|
-
Api.pj_strerrno(errno)
|
13
|
-
end
|
14
|
-
raise(self, message)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module Proj
|
2
|
+
class Error < StandardError
|
3
|
+
def self.check(errno=nil)
|
4
|
+
unless errno
|
5
|
+
errno = Context.current.errno
|
6
|
+
end
|
7
|
+
|
8
|
+
if errno != 0
|
9
|
+
message = if Api.method_defined?(:proj_errno_string)
|
10
|
+
Api.proj_errno_string(errno)
|
11
|
+
else
|
12
|
+
Api.pj_strerrno(errno)
|
13
|
+
end
|
14
|
+
raise(self, message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
data/lib/operation.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
module Proj
|
2
|
-
class Operation
|
3
|
-
attr_reader :id, :description
|
4
|
-
|
5
|
-
def self.list
|
6
|
-
pointer_to_array = FFI::Pointer.new(Api::PJ_OPERATIONS, Api.proj_list_operations)
|
7
|
-
result = Array.new
|
8
|
-
0.step do |i|
|
9
|
-
operation_info = Api::PJ_OPERATIONS.new(pointer_to_array[i])
|
10
|
-
break result if operation_info[:id].nil?
|
11
|
-
id = operation_info[:id]
|
12
|
-
description = operation_info[:descr].read_pointer.read_string.force_encoding('UTF-8')
|
13
|
-
result << self.new(id, description)
|
14
|
-
end
|
15
|
-
result
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.get(id)
|
19
|
-
self.list.find {|operation| operation.id == id}
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(id, description)
|
23
|
-
@id = id
|
24
|
-
@description = description
|
25
|
-
end
|
26
|
-
|
27
|
-
def <=>(other)
|
28
|
-
self.id <=> other.id
|
29
|
-
end
|
30
|
-
|
31
|
-
def ==(other)
|
32
|
-
self.id == other.id
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_s
|
36
|
-
self.id
|
37
|
-
end
|
38
|
-
|
39
|
-
def inspect
|
40
|
-
"#<#{self.class} id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
|
41
|
-
end
|
42
|
-
end
|
1
|
+
module Proj
|
2
|
+
class Operation
|
3
|
+
attr_reader :id, :description
|
4
|
+
|
5
|
+
def self.list
|
6
|
+
pointer_to_array = FFI::Pointer.new(Api::PJ_OPERATIONS, Api.proj_list_operations)
|
7
|
+
result = Array.new
|
8
|
+
0.step do |i|
|
9
|
+
operation_info = Api::PJ_OPERATIONS.new(pointer_to_array[i])
|
10
|
+
break result if operation_info[:id].nil?
|
11
|
+
id = operation_info[:id]
|
12
|
+
description = operation_info[:descr].read_pointer.read_string.force_encoding('UTF-8')
|
13
|
+
result << self.new(id, description)
|
14
|
+
end
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get(id)
|
19
|
+
self.list.find {|operation| operation.id == id}
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(id, description)
|
23
|
+
@id = id
|
24
|
+
@description = description
|
25
|
+
end
|
26
|
+
|
27
|
+
def <=>(other)
|
28
|
+
self.id <=> other.id
|
29
|
+
end
|
30
|
+
|
31
|
+
def ==(other)
|
32
|
+
self.id == other.id
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
self.id
|
37
|
+
end
|
38
|
+
|
39
|
+
def inspect
|
40
|
+
"#<#{self.class} id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
|
41
|
+
end
|
42
|
+
end
|
43
43
|
end
|
data/lib/pj_object.rb
CHANGED
@@ -1,80 +1,80 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module Proj
|
3
|
-
class PjObject
|
4
|
-
def self.finalize(pointer)
|
5
|
-
proc do
|
6
|
-
Api.proj_destroy(pointer)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(pointer, context=nil)
|
11
|
-
@pointer = pointer
|
12
|
-
@context = context
|
13
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_ptr
|
17
|
-
@pointer
|
18
|
-
end
|
19
|
-
|
20
|
-
def context
|
21
|
-
@context || Context.current
|
22
|
-
end
|
23
|
-
|
24
|
-
def proj_type
|
25
|
-
Api.proj_get_type(self)
|
26
|
-
end
|
27
|
-
|
28
|
-
def info
|
29
|
-
Api.proj_pj_info(self)
|
30
|
-
end
|
31
|
-
|
32
|
-
def id
|
33
|
-
self.info[:id]
|
34
|
-
end
|
35
|
-
|
36
|
-
def name
|
37
|
-
Api.proj_get_name(self).force_encoding('UTF-8')
|
38
|
-
end
|
39
|
-
|
40
|
-
def auth_name(index=0)
|
41
|
-
Api.proj_get_id_auth_name(self, index).force_encoding('UTF-8')
|
42
|
-
end
|
43
|
-
|
44
|
-
def auth_code(index=0)
|
45
|
-
Api.proj_get_id_code(self, index)
|
46
|
-
end
|
47
|
-
|
48
|
-
def auth(index=0)
|
49
|
-
"#{self.auth_name(index)}:#{self.auth_code(index)}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def description
|
53
|
-
self.info[:description] ? self.info[:description].force_encoding('UTF-8') : nil
|
54
|
-
end
|
55
|
-
|
56
|
-
def definition
|
57
|
-
self.info[:definition] ? self.info[:definition].force_encoding('UTF-8') : nil
|
58
|
-
end
|
59
|
-
|
60
|
-
def has_inverse?
|
61
|
-
self.info[:has_inverse] == 1 ? true : false
|
62
|
-
end
|
63
|
-
|
64
|
-
def accuracy
|
65
|
-
self.info[:accuracy]
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_proj_string(string_type=:PJ_PROJ_4)
|
69
|
-
Api.proj_as_proj_string(self.context, self, string_type, nil).force_encoding('UTF-8')
|
70
|
-
end
|
71
|
-
|
72
|
-
def to_json
|
73
|
-
Api.proj_as_projjson(self.context, self, nil).force_encoding('UTF-8')
|
74
|
-
end
|
75
|
-
|
76
|
-
def to_wkt(wkt_type=:PJ_WKT2_2018)
|
77
|
-
Api.proj_as_wkt(self.context, self, wkt_type, nil).force_encoding('UTF-8')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Proj
|
3
|
+
class PjObject
|
4
|
+
def self.finalize(pointer)
|
5
|
+
proc do
|
6
|
+
Api.proj_destroy(pointer)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(pointer, context=nil)
|
11
|
+
@pointer = pointer
|
12
|
+
@context = context
|
13
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_ptr
|
17
|
+
@pointer
|
18
|
+
end
|
19
|
+
|
20
|
+
def context
|
21
|
+
@context || Context.current
|
22
|
+
end
|
23
|
+
|
24
|
+
def proj_type
|
25
|
+
Api.proj_get_type(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def info
|
29
|
+
Api.proj_pj_info(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def id
|
33
|
+
self.info[:id]
|
34
|
+
end
|
35
|
+
|
36
|
+
def name
|
37
|
+
Api.proj_get_name(self).force_encoding('UTF-8')
|
38
|
+
end
|
39
|
+
|
40
|
+
def auth_name(index=0)
|
41
|
+
Api.proj_get_id_auth_name(self, index).force_encoding('UTF-8')
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_code(index=0)
|
45
|
+
Api.proj_get_id_code(self, index)
|
46
|
+
end
|
47
|
+
|
48
|
+
def auth(index=0)
|
49
|
+
"#{self.auth_name(index)}:#{self.auth_code(index)}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def description
|
53
|
+
self.info[:description] ? self.info[:description].force_encoding('UTF-8') : nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def definition
|
57
|
+
self.info[:definition] ? self.info[:definition].force_encoding('UTF-8') : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def has_inverse?
|
61
|
+
self.info[:has_inverse] == 1 ? true : false
|
62
|
+
end
|
63
|
+
|
64
|
+
def accuracy
|
65
|
+
self.info[:accuracy]
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_proj_string(string_type=:PJ_PROJ_4)
|
69
|
+
Api.proj_as_proj_string(self.context, self, string_type, nil).force_encoding('UTF-8')
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_json
|
73
|
+
Api.proj_as_projjson(self.context, self, nil).force_encoding('UTF-8')
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_wkt(wkt_type=:PJ_WKT2_2018)
|
77
|
+
Api.proj_as_wkt(self.context, self, wkt_type, nil).force_encoding('UTF-8')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/point.rb
CHANGED
@@ -1,72 +1,72 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module Proj
|
4
|
-
# @deprecated This class is *DEPRECATED.* It will be removed when Proj 7 is released and removes the
|
5
|
-
# underlying API's this class uses. Code should be ported to use Coordinate objects.
|
6
|
-
class Point
|
7
|
-
def self.from_pointer(pointer)
|
8
|
-
result = self.allocate
|
9
|
-
result.instance_variable_set(:@struct, pointer)
|
10
|
-
result
|
11
|
-
end
|
12
|
-
|
13
|
-
# Create new Point object from coordinates.
|
14
|
-
def initialize(x, y)
|
15
|
-
@struct = Api::ProjUV.new
|
16
|
-
@struct[:u] = x
|
17
|
-
@struct[:v] = y
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_ptr
|
21
|
-
@struct.to_ptr
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_radians
|
25
|
-
self.class.new(Api.proj_torad(self.x), Api.proj_torad(self.y))
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_degrees
|
29
|
-
self.class.new(Api.proj_todeg(self.x), Api.proj_todeg(self.y))
|
30
|
-
end
|
31
|
-
|
32
|
-
# Get x coordinate.
|
33
|
-
def x
|
34
|
-
@struct[:u]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Set x coordinate.
|
38
|
-
def x=(value)
|
39
|
-
@struct[:u] = value
|
40
|
-
end
|
41
|
-
|
42
|
-
# Get y coordinate.
|
43
|
-
def y
|
44
|
-
@struct[:v]
|
45
|
-
end
|
46
|
-
|
47
|
-
# Set y coordinate.
|
48
|
-
def y=(value)
|
49
|
-
@struct[:v] = value
|
50
|
-
end
|
51
|
-
|
52
|
-
# Get longitude/x coordinate.
|
53
|
-
def lon
|
54
|
-
@struct[:u]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Set longitude/x coordinate.
|
58
|
-
def lon=(value)
|
59
|
-
@struct[:u] = value
|
60
|
-
end
|
61
|
-
|
62
|
-
# Get latitude/y coordinate.
|
63
|
-
def lat
|
64
|
-
@struct[:v]
|
65
|
-
end
|
66
|
-
|
67
|
-
# Set latitude/y coordinate.
|
68
|
-
def lat=(value)
|
69
|
-
@struct[:v] = value
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Proj
|
4
|
+
# @deprecated This class is *DEPRECATED.* It will be removed when Proj 7 is released and removes the
|
5
|
+
# underlying API's this class uses. Code should be ported to use Coordinate objects.
|
6
|
+
class Point
|
7
|
+
def self.from_pointer(pointer)
|
8
|
+
result = self.allocate
|
9
|
+
result.instance_variable_set(:@struct, pointer)
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
13
|
+
# Create new Point object from coordinates.
|
14
|
+
def initialize(x, y)
|
15
|
+
@struct = Api::ProjUV.new
|
16
|
+
@struct[:u] = x
|
17
|
+
@struct[:v] = y
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_ptr
|
21
|
+
@struct.to_ptr
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_radians
|
25
|
+
self.class.new(Api.proj_torad(self.x), Api.proj_torad(self.y))
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_degrees
|
29
|
+
self.class.new(Api.proj_todeg(self.x), Api.proj_todeg(self.y))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get x coordinate.
|
33
|
+
def x
|
34
|
+
@struct[:u]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Set x coordinate.
|
38
|
+
def x=(value)
|
39
|
+
@struct[:u] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get y coordinate.
|
43
|
+
def y
|
44
|
+
@struct[:v]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set y coordinate.
|
48
|
+
def y=(value)
|
49
|
+
@struct[:v] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get longitude/x coordinate.
|
53
|
+
def lon
|
54
|
+
@struct[:u]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Set longitude/x coordinate.
|
58
|
+
def lon=(value)
|
59
|
+
@struct[:u] = value
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get latitude/y coordinate.
|
63
|
+
def lat
|
64
|
+
@struct[:v]
|
65
|
+
end
|
66
|
+
|
67
|
+
# Set latitude/y coordinate.
|
68
|
+
def lat=(value)
|
69
|
+
@struct[:v] = value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|