proj4rb 2.2.1 → 2.2.2

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.
@@ -1,7 +1,7 @@
1
- module Proj
2
- module Api
3
- attach_function :proj_log_level, [:PJ_CONTEXT, :PJ_LOG_LEVEL], :PJ_LOG_LEVEL
4
- callback :pj_log_function, [:pointer, :int, :string], :void
5
- attach_function :proj_log_func, [:PJ_CONTEXT, :pointer, :pj_log_function], :void
6
- end
1
+ module Proj
2
+ module Api
3
+ attach_function :proj_log_level, [:PJ_CONTEXT, :PJ_LOG_LEVEL], :PJ_LOG_LEVEL
4
+ callback :pj_log_function, [:pointer, :int, :string], :void
5
+ attach_function :proj_log_func, [:PJ_CONTEXT, :pointer, :pj_log_function], :void
6
+ end
7
7
  end
@@ -1,5 +1,5 @@
1
- module Proj
2
- module Api
3
- attach_function :proj_errno_string, [:int], :string
4
- end
1
+ module Proj
2
+ module Api
3
+ attach_function :proj_errno_string, [:int], :string
4
+ end
5
5
  end
@@ -1,43 +1,42 @@
1
- module Proj
2
- module Api
3
- callback :proj_file_finder, [:PJ_CONTEXT, :string, :pointer], :string
4
- attach_function :proj_context_set_file_finder, [:PJ_CONTEXT, :proj_file_finder, :pointer], :void
5
- attach_function :proj_context_set_search_paths, [:PJ_CONTEXT, :int, :pointer], :void
6
-
7
- attach_function :proj_context_use_proj4_init_rules, [:PJ_CONTEXT, :int], :void
8
- attach_function :proj_context_get_use_proj4_init_rules, [:PJ_CONTEXT, :int], :bool
9
- attach_function :proj_list_angular_units, [], :pointer #PJ_UNITS
10
-
11
- # Base methods
12
- attach_function :proj_get_name, [:PJ], :string
13
- attach_function :proj_get_id_auth_name, [:PJ, :int], :string
14
- attach_function :proj_get_id_code, [:PJ, :int], :string
15
- attach_function :proj_get_type, [:PJ], :PJ_TYPE
16
- attach_function :proj_is_deprecated, [:PJ], :bool
17
- attach_function :proj_is_crs, [:PJ], :bool
18
- attach_function :proj_get_area_of_use, [:PJ_CONTEXT, :PJ, :pointer, :pointer, :pointer, :pointer, :pointer], :bool
19
-
20
- # Export to various formats
21
- attach_function :proj_as_wkt, [:PJ_CONTEXT, :PJ, :PJ_WKT_TYPE, :pointer], :string
22
- attach_function :proj_as_proj_string, [:PJ_CONTEXT, :PJ, :PJ_PROJ_STRING_TYPE, :pointer], :string
23
-
24
- # Projection database functions
25
- attach_function :proj_context_set_autoclose_database, [:PJ_CONTEXT, :int], :void
26
- attach_function :proj_context_set_database_path, [:PJ_CONTEXT, :string, :pointer, :pointer], :int
27
- attach_function :proj_context_get_database_path, [:PJ_CONTEXT], :string
28
- attach_function :proj_context_get_database_metadata, [:PJ_CONTEXT, :string], :string
29
-
30
- # CRS methods
31
- attach_function :proj_crs_get_geodetic_crs, [:PJ_CONTEXT, :PJ], :PJ
32
- attach_function :proj_crs_get_horizontal_datum, [:PJ_CONTEXT, :PJ], :PJ
33
- attach_function :proj_crs_get_sub_crs, [:PJ_CONTEXT, :PJ, :int], :PJ
34
- attach_function :proj_crs_get_datum, [:PJ_CONTEXT, :PJ], :PJ
35
- attach_function :proj_crs_get_coordinate_system, [:PJ_CONTEXT, :PJ], :PJ
36
- attach_function :proj_cs_get_type, [:PJ_CONTEXT, :PJ], :PJ_COORDINATE_SYSTEM_TYPE
37
- attach_function :proj_cs_get_axis_count, [:PJ_CONTEXT, :PJ], :int
38
- attach_function :proj_cs_get_axis_info, [:PJ_CONTEXT, :PJ, :int, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :bool
39
- attach_function :proj_get_prime_meridian, [:PJ_CONTEXT, :PJ], :PJ
40
- attach_function :proj_get_ellipsoid, [:PJ_CONTEXT, :PJ], :PJ
41
- attach_function :proj_crs_get_coordoperation, [:PJ_CONTEXT, :PJ], :PJ
42
- end
1
+ module Proj
2
+ module Api
3
+ callback :proj_file_finder, [:PJ_CONTEXT, :string, :pointer], :string
4
+ attach_function :proj_context_set_file_finder, [:PJ_CONTEXT, :proj_file_finder, :pointer], :void
5
+ attach_function :proj_context_set_search_paths, [:PJ_CONTEXT, :int, :pointer], :void
6
+
7
+ attach_function :proj_context_use_proj4_init_rules, [:PJ_CONTEXT, :int], :void
8
+ attach_function :proj_context_get_use_proj4_init_rules, [:PJ_CONTEXT, :int], :bool
9
+ attach_function :proj_list_angular_units, [], :pointer #PJ_UNITS
10
+
11
+ # Base methods
12
+ attach_function :proj_get_name, [:PJ], :string
13
+ attach_function :proj_get_id_auth_name, [:PJ, :int], :string
14
+ attach_function :proj_get_id_code, [:PJ, :int], :string
15
+ attach_function :proj_get_type, [:PJ], :PJ_TYPE
16
+ attach_function :proj_is_deprecated, [:PJ], :bool
17
+ attach_function :proj_is_crs, [:PJ], :bool
18
+ attach_function :proj_get_area_of_use, [:PJ_CONTEXT, :PJ, :pointer, :pointer, :pointer, :pointer, :pointer], :bool
19
+
20
+ # Export to various formats
21
+ attach_function :proj_as_wkt, [:PJ_CONTEXT, :PJ, :PJ_WKT_TYPE, :pointer], :string
22
+ attach_function :proj_as_proj_string, [:PJ_CONTEXT, :PJ, :PJ_PROJ_STRING_TYPE, :pointer], :string
23
+
24
+ # Projection database functions
25
+ attach_function :proj_context_set_database_path, [:PJ_CONTEXT, :string, :pointer, :pointer], :int
26
+ attach_function :proj_context_get_database_path, [:PJ_CONTEXT], :string
27
+ attach_function :proj_context_get_database_metadata, [:PJ_CONTEXT, :string], :string
28
+
29
+ # CRS methods
30
+ attach_function :proj_crs_get_geodetic_crs, [:PJ_CONTEXT, :PJ], :PJ
31
+ attach_function :proj_crs_get_horizontal_datum, [:PJ_CONTEXT, :PJ], :PJ
32
+ attach_function :proj_crs_get_sub_crs, [:PJ_CONTEXT, :PJ, :int], :PJ
33
+ attach_function :proj_crs_get_datum, [:PJ_CONTEXT, :PJ], :PJ
34
+ attach_function :proj_crs_get_coordinate_system, [:PJ_CONTEXT, :PJ], :PJ
35
+ attach_function :proj_cs_get_type, [:PJ_CONTEXT, :PJ], :PJ_COORDINATE_SYSTEM_TYPE
36
+ attach_function :proj_cs_get_axis_count, [:PJ_CONTEXT, :PJ], :int
37
+ attach_function :proj_cs_get_axis_info, [:PJ_CONTEXT, :PJ, :int, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :bool
38
+ attach_function :proj_get_prime_meridian, [:PJ_CONTEXT, :PJ], :PJ
39
+ attach_function :proj_get_ellipsoid, [:PJ_CONTEXT, :PJ], :PJ
40
+ attach_function :proj_crs_get_coordoperation, [:PJ_CONTEXT, :PJ], :PJ
41
+ end
43
42
  end
@@ -1,5 +1,5 @@
1
- module Proj
2
- module Api
3
- attach_function :proj_normalize_for_visualization, [:PJ_CONTEXT, :PJ], :PJ
4
- end
1
+ module Proj
2
+ module Api
3
+ attach_function :proj_normalize_for_visualization, [:PJ_CONTEXT, :PJ], :PJ
4
+ end
5
5
  end
@@ -1,6 +1,7 @@
1
- module Proj
2
- module Api
3
- attach_function :proj_as_projjson, [:PJ_CONTEXT, :PJ, :pointer], :string
4
- attach_function :proj_create_crs_to_crs_from_pj, [:PJ_CONTEXT, :PJ, :PJ, :PJ_AREA, :string], :PJ
5
- end
1
+ module Proj
2
+ module Api
3
+ attach_function :proj_as_projjson, [:PJ_CONTEXT, :PJ, :pointer], :string
4
+ attach_function :proj_create_crs_to_crs_from_pj, [:PJ_CONTEXT, :PJ, :PJ, :PJ_AREA, :string], :PJ
5
+ attach_function :proj_context_set_autoclose_database, [:PJ_CONTEXT, :int], :void
6
+ end
6
7
  end
@@ -1,32 +1,32 @@
1
- module Proj
2
- class Area
3
- attr_reader :name, :west_lon_degree, :south_lat_degree, :east_lon_degree, :north_lat_degree
4
-
5
- def self.for_object(pj_object)
6
- p_name = FFI::MemoryPointer.new(:pointer)
7
- p_west_lon_degree = FFI::MemoryPointer.new(:double)
8
- p_south_lat_degree = FFI::MemoryPointer.new(:double)
9
- p_east_lon_degree = FFI::MemoryPointer.new(:double)
10
- p_north_lat_degree = FFI::MemoryPointer.new(:double)
11
-
12
- result = Api.proj_get_area_of_use(Context.current, pj_object,
13
- p_west_lon_degree, p_south_lat_degree, p_east_lon_degree, p_north_lat_degree,
14
- p_name)
15
- unless result
16
- Error.check
17
- end
18
-
19
- name = p_name.read_pointer.read_string_to_null.force_encoding('utf-8')
20
- self.new(name,
21
- p_west_lon_degree.read_double, p_south_lat_degree.read_double, p_east_lon_degree.read_double, p_north_lat_degree.read_double)
22
- end
23
-
24
- def initialize(name, west_lon_degree, south_lat_degree, east_lon_degree, north_lat_degree)
25
- @name = name
26
- @west_lon_degree = west_lon_degree
27
- @south_lat_degree = south_lat_degree
28
- @east_lon_degree = east_lon_degree
29
- @north_lat_degree = north_lat_degree
30
- end
31
- end
32
- end
1
+ module Proj
2
+ class Area
3
+ attr_reader :name, :west_lon_degree, :south_lat_degree, :east_lon_degree, :north_lat_degree
4
+
5
+ def self.for_object(pj_object)
6
+ p_name = FFI::MemoryPointer.new(:pointer)
7
+ p_west_lon_degree = FFI::MemoryPointer.new(:double)
8
+ p_south_lat_degree = FFI::MemoryPointer.new(:double)
9
+ p_east_lon_degree = FFI::MemoryPointer.new(:double)
10
+ p_north_lat_degree = FFI::MemoryPointer.new(:double)
11
+
12
+ result = Api.proj_get_area_of_use(Context.current, pj_object,
13
+ p_west_lon_degree, p_south_lat_degree, p_east_lon_degree, p_north_lat_degree,
14
+ p_name)
15
+ unless result
16
+ Error.check
17
+ end
18
+
19
+ name = p_name.read_pointer.read_string_to_null.force_encoding('utf-8')
20
+ self.new(name,
21
+ p_west_lon_degree.read_double, p_south_lat_degree.read_double, p_east_lon_degree.read_double, p_north_lat_degree.read_double)
22
+ end
23
+
24
+ def initialize(name, west_lon_degree, south_lat_degree, east_lon_degree, north_lat_degree)
25
+ @name = name
26
+ @west_lon_degree = west_lon_degree
27
+ @south_lat_degree = south_lat_degree
28
+ @east_lon_degree = east_lon_degree
29
+ @north_lat_degree = north_lat_degree
30
+ end
31
+ end
32
+ end
@@ -1,70 +1,70 @@
1
- require 'singleton'
2
-
3
- module Proj
4
- class Config
5
- include Singleton
6
-
7
- def set_search_paths
8
- p_paths = self.search_paths_pointer
9
- items = p_paths.type_size/p_paths.size
10
-
11
- # Set search paths on default context - any new contexts will inherit from this
12
- if Api.method_defined?(:proj_context_set_search_paths)
13
- Api.proj_context_set_search_paths(nil, items, p_paths)
14
- end
15
-
16
- if Api.method_defined?(:pj_set_searchpath)
17
- Api.pj_set_searchpath(items, p_paths)
18
- end
19
- end
20
-
21
- def search_paths
22
- ['/usr/share/proj',
23
- '/usr/local/share/proj',
24
- '/opt/share/proj',
25
- '/opt/local/share/proj',
26
- 'c:/msys64/mingw64/share/proj',
27
- 'c:/mingw64/share/proj',
28
- '/opt/local/lib/proj6/share/proj',
29
- '/opt/local/lib/proj5/share/proj',
30
- '/opt/local/lib/proj49/share/proj']
31
- end
32
-
33
- def data_path
34
- if ENV['PROJ_LIB'] && File.directory?(ENV['PROJ_LIB'])
35
- ENV['PROJ_LIB']
36
- else
37
- result = self.search_paths.detect do |path|
38
- File.directory?(path)
39
- end
40
-
41
- unless result
42
- raise(Error, "Could not find Proj data directory. Please set the PROJ_LIB environmental variable to correct directory")
43
- end
44
-
45
- result
46
- end
47
- end
48
-
49
- def search_paths_pointer
50
- p_path = FFI::MemoryPointer.from_string(self.data_path)
51
- p_paths = FFI::MemoryPointer.new(:pointer, 1)
52
- p_paths[0].write_pointer(p_path)
53
- p_paths
54
- end
55
-
56
- def db_path
57
- result = self.search_paths.map do |path|
58
- File.join(path, 'proj.db')
59
- end.detect do |path|
60
- File.exists?(path)
61
- end
62
-
63
- unless result
64
- raise(Error, "Could not find Proj database (proj.db). Please set the PROJ_LIB environmental variable to directory that contains it")
65
- end
66
-
67
- result
68
- end
69
- end
1
+ require 'singleton'
2
+
3
+ module Proj
4
+ class Config
5
+ include Singleton
6
+
7
+ def set_search_paths
8
+ p_paths = self.search_paths_pointer
9
+ items = p_paths.type_size/p_paths.size
10
+
11
+ # Set search paths on default context - any new contexts will inherit from this
12
+ if Api.method_defined?(:proj_context_set_search_paths)
13
+ Api.proj_context_set_search_paths(nil, items, p_paths)
14
+ end
15
+
16
+ if Api.method_defined?(:pj_set_searchpath)
17
+ Api.pj_set_searchpath(items, p_paths)
18
+ end
19
+ end
20
+
21
+ def search_paths
22
+ ['/usr/share/proj',
23
+ '/usr/local/share/proj',
24
+ '/opt/share/proj',
25
+ '/opt/local/share/proj',
26
+ 'c:/msys64/mingw64/share/proj',
27
+ 'c:/mingw64/share/proj',
28
+ '/opt/local/lib/proj6/share/proj',
29
+ '/opt/local/lib/proj5/share/proj',
30
+ '/opt/local/lib/proj49/share/proj']
31
+ end
32
+
33
+ def data_path
34
+ if ENV['PROJ_LIB'] && File.directory?(ENV['PROJ_LIB'])
35
+ ENV['PROJ_LIB']
36
+ else
37
+ result = self.search_paths.detect do |path|
38
+ File.directory?(path)
39
+ end
40
+
41
+ unless result
42
+ raise(Error, "Could not find Proj data directory. Please set the PROJ_LIB environmental variable to correct directory")
43
+ end
44
+
45
+ result
46
+ end
47
+ end
48
+
49
+ def search_paths_pointer
50
+ p_path = FFI::MemoryPointer.from_string(self.data_path)
51
+ p_paths = FFI::MemoryPointer.new(:pointer, 1)
52
+ p_paths[0].write_pointer(p_path)
53
+ p_paths
54
+ end
55
+
56
+ def db_path
57
+ result = self.search_paths.map do |path|
58
+ File.join(path, 'proj.db')
59
+ end.detect do |path|
60
+ File.exists?(path)
61
+ end
62
+
63
+ unless result
64
+ raise(Error, "Could not find Proj database (proj.db). Please set the PROJ_LIB environmental variable to directory that contains it")
65
+ end
66
+
67
+ result
68
+ end
69
+ end
70
70
  end
@@ -1,103 +1,103 @@
1
- module Proj
2
- # Proj 4.8 introduced the concept of a thread context object to support multi-threaded programs. The bindings
3
- # automatically create on context per thread (its stored in local thread storage).
4
- class Context
5
- # The context for the current thread
6
- #
7
- # @return [Context]
8
- def self.current
9
- Thread.current[:proj_context] ||= Context.new
10
- end
11
-
12
- def self.finalize(pointer)
13
- proc do
14
- Api.proj_context_destroy(pointer)
15
- end
16
- end
17
-
18
- def initialize
19
- @pointer = Api.proj_context_create
20
- ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
21
-
22
- set_database_path
23
- end
24
-
25
- # Helper method that tries to locate the Proj coordinate database (proj.db)
26
- def set_database_path
27
- return unless Api.method_defined?(:proj_context_get_database_path)
28
- return if database_path
29
-
30
- self.database_path = Config.instance.db_path
31
- end
32
-
33
- def to_ptr
34
- @pointer
35
- end
36
-
37
- # Get the last error number
38
- #
39
- # return [Integer]
40
- def errno
41
- Api.proj_context_errno(self)
42
- end
43
-
44
- # Gets the path the Proj database
45
- #
46
- # return [String]
47
- def database_path
48
- Api.proj_context_get_database_path(self)
49
- end
50
-
51
- # Sets the path to the Proj database
52
- def database_path=(value)
53
- result = Api.proj_context_set_database_path(self, value, nil, nil)
54
- unless result == 1
55
- Error.check(self.errno)
56
- end
57
- end
58
-
59
- # Sets a custom log function
60
- #
61
- # @example
62
- # context.set_log_function(data) do |pointer, int, message|
63
- # ... do stuff...
64
- # end
65
- #
66
- # @param pointer [FFI::MemoryPointer] Optional pointer to custom data
67
- # @param proc [Proc] Custom logging procedure
68
- # @return [nil]
69
- def set_log_function(pointer = nil, &proc)
70
- Api.proj_log_func(self, pointer, proc)
71
- end
72
-
73
- # Gets the current log level
74
- #
75
- # @return [:PJ_LOG_LEVEL]
76
- def log_level
77
- Api.proj_log_level(self, :PJ_LOG_TELL)
78
- end
79
-
80
- # Sets the current log level
81
- #
82
- # @param value [:PJ_LOG_LEVEL]
83
- # @return [nil]
84
- def log_level=(value)
85
- Api.proj_log_level(self, value)
86
- end
87
-
88
- # Gets if proj4 init rules are being used (i.e., support +init parameters)
89
- #
90
- # @return [Boolean]
91
- def use_proj4_init_rules
92
- Api.proj_context_get_use_proj4_init_rules(self, 0)
93
- end
94
-
95
- # Sets if proj4 init rules should be used
96
- #
97
- # @param value [Boolean]
98
- # @return [nil]
99
- def use_proj4_init_rules=(value)
100
- Api.proj_context_use_proj4_init_rules(self, value ? 1 : 0)
101
- end
102
- end
1
+ module Proj
2
+ # Proj 4.8 introduced the concept of a thread context object to support multi-threaded programs. The bindings
3
+ # automatically create on context per thread (its stored in local thread storage).
4
+ class Context
5
+ # The context for the current thread
6
+ #
7
+ # @return [Context]
8
+ def self.current
9
+ Thread.current[:proj_context] ||= Context.new
10
+ end
11
+
12
+ def self.finalize(pointer)
13
+ proc do
14
+ Api.proj_context_destroy(pointer)
15
+ end
16
+ end
17
+
18
+ def initialize
19
+ @pointer = Api.proj_context_create
20
+ ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
21
+
22
+ set_database_path
23
+ end
24
+
25
+ # Helper method that tries to locate the Proj coordinate database (proj.db)
26
+ def set_database_path
27
+ return unless Api.method_defined?(:proj_context_get_database_path)
28
+ return if database_path
29
+
30
+ self.database_path = Config.instance.db_path
31
+ end
32
+
33
+ def to_ptr
34
+ @pointer
35
+ end
36
+
37
+ # Get the last error number
38
+ #
39
+ # return [Integer]
40
+ def errno
41
+ Api.proj_context_errno(self)
42
+ end
43
+
44
+ # Gets the path the Proj database
45
+ #
46
+ # return [String]
47
+ def database_path
48
+ Api.proj_context_get_database_path(self)
49
+ end
50
+
51
+ # Sets the path to the Proj database
52
+ def database_path=(value)
53
+ result = Api.proj_context_set_database_path(self, value, nil, nil)
54
+ unless result == 1
55
+ Error.check(self.errno)
56
+ end
57
+ end
58
+
59
+ # Sets a custom log function
60
+ #
61
+ # @example
62
+ # context.set_log_function(data) do |pointer, int, message|
63
+ # ... do stuff...
64
+ # end
65
+ #
66
+ # @param pointer [FFI::MemoryPointer] Optional pointer to custom data
67
+ # @param proc [Proc] Custom logging procedure
68
+ # @return [nil]
69
+ def set_log_function(pointer = nil, &proc)
70
+ Api.proj_log_func(self, pointer, proc)
71
+ end
72
+
73
+ # Gets the current log level
74
+ #
75
+ # @return [:PJ_LOG_LEVEL]
76
+ def log_level
77
+ Api.proj_log_level(self, :PJ_LOG_TELL)
78
+ end
79
+
80
+ # Sets the current log level
81
+ #
82
+ # @param value [:PJ_LOG_LEVEL]
83
+ # @return [nil]
84
+ def log_level=(value)
85
+ Api.proj_log_level(self, value)
86
+ end
87
+
88
+ # Gets if proj4 init rules are being used (i.e., support +init parameters)
89
+ #
90
+ # @return [Boolean]
91
+ def use_proj4_init_rules
92
+ Api.proj_context_get_use_proj4_init_rules(self, 0)
93
+ end
94
+
95
+ # Sets if proj4 init rules should be used
96
+ #
97
+ # @param value [Boolean]
98
+ # @return [nil]
99
+ def use_proj4_init_rules=(value)
100
+ Api.proj_context_use_proj4_init_rules(self, value ? 1 : 0)
101
+ end
102
+ end
103
103
  end