Class: Proj::Context
- Inherits:
-
Object
- Object
- Proj::Context
- Defined in:
- lib/context.rb
Overview
Proj 4.8 introduced the concept of a thread context object to support multi-threaded programs. The bindings automatically create on context per thread (its stored in local thread storage).
Class Method Summary collapse
-
.current ⇒ Context
The context for the current thread.
- .finalize(pointer) ⇒ Object
Instance Method Summary collapse
-
#database_path ⇒ Object
Gets the path the Proj database.
-
#database_path=(value) ⇒ Object
Sets the path to the Proj database.
-
#errno ⇒ Object
Get the last error number.
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#log_level ⇒ :PJ_LOG_LEVEL
Gets the current log level.
-
#log_level=(value) ⇒ nil
Sets the current log level.
-
#set_database_path ⇒ Object
Helper method that tries to locate the Proj coordinate database (proj.db).
-
#set_log_function(pointer = nil, &proc) ⇒ nil
Sets a custom log function.
- #to_ptr ⇒ Object
-
#use_proj4_init_rules ⇒ Boolean
Gets if proj4 init rules are being used (i.e., support +init parameters).
-
#use_proj4_init_rules=(value) ⇒ nil
Sets if proj4 init rules should be used.
Constructor Details
Class Method Details
.current ⇒ Context
The context for the current thread
8 9 10 |
# File 'lib/context.rb', line 8 def self.current Thread.current[:proj_context] ||= Context.new end |
.finalize(pointer) ⇒ Object
12 13 14 15 16 |
# File 'lib/context.rb', line 12 def self.finalize(pointer) proc do Api.proj_context_destroy(pointer) end end |
Instance Method Details
#database_path ⇒ Object
Gets the path the Proj database
return [String]
47 48 49 |
# File 'lib/context.rb', line 47 def database_path Api.proj_context_get_database_path(self) end |
#database_path=(value) ⇒ Object
Sets the path to the Proj database
52 53 54 55 56 57 |
# File 'lib/context.rb', line 52 def database_path=(value) result = Api.proj_context_set_database_path(self, value, nil, nil) unless result == 1 Error.check(self.errno) end end |
#errno ⇒ Object
Get the last error number
return [Integer]
40 41 42 |
# File 'lib/context.rb', line 40 def errno Api.proj_context_errno(self) end |
#log_level ⇒ :PJ_LOG_LEVEL
Gets the current log level
76 77 78 |
# File 'lib/context.rb', line 76 def log_level Api.proj_log_level(self, :PJ_LOG_TELL) end |
#log_level=(value) ⇒ nil
Sets the current log level
84 85 86 |
# File 'lib/context.rb', line 84 def log_level=(value) Api.proj_log_level(self, value) end |
#set_database_path ⇒ Object
Helper method that tries to locate the Proj coordinate database (proj.db)
26 27 28 29 30 31 |
# File 'lib/context.rb', line 26 def set_database_path return unless Api.method_defined?(:proj_context_get_database_path) return if database_path self.database_path = Config.instance.db_path end |
#set_log_function(pointer = nil, &proc) ⇒ nil
Sets a custom log function
69 70 71 |
# File 'lib/context.rb', line 69 def set_log_function(pointer = nil, &proc) Api.proj_log_func(self, pointer, proc) end |
#to_ptr ⇒ Object
33 34 35 |
# File 'lib/context.rb', line 33 def to_ptr @pointer end |
#use_proj4_init_rules ⇒ Boolean
Gets if proj4 init rules are being used (i.e., support +init parameters)
91 92 93 |
# File 'lib/context.rb', line 91 def use_proj4_init_rules Api.proj_context_get_use_proj4_init_rules(self, 0) end |
#use_proj4_init_rules=(value) ⇒ nil
Sets if proj4 init rules should be used
99 100 101 |
# File 'lib/context.rb', line 99 def use_proj4_init_rules=(value) Api.proj_context_use_proj4_init_rules(self, value ? 1 : 0) end |