Class: Proj::Context

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



18
19
20
21
22
23
# File 'lib/context.rb', line 18

def initialize
  @pointer = Api.proj_context_create
  ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))

  set_database_path
end

Class Method Details

.currentContext

The context for the current thread

Returns:



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_pathObject

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

#errnoObject

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

Returns:

  • (:PJ_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

Parameters:

  • value (:PJ_LOG_LEVEL)

Returns:

  • (nil)


84
85
86
# File 'lib/context.rb', line 84

def log_level=(value)
  Api.proj_log_level(self, value)
end

#set_database_pathObject

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

Examples:

context.set_log_function(data) do |pointer, int, message|
  ... do stuff...
end

Parameters:

  • pointer (FFI::MemoryPointer) (defaults to: nil)

    Optional pointer to custom data

  • proc (Proc)

    Custom logging procedure

Returns:

  • (nil)


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_ptrObject



33
34
35
# File 'lib/context.rb', line 33

def to_ptr
  @pointer
end

#use_proj4_init_rulesBoolean

Gets if proj4 init rules are being used (i.e., support +init parameters)

Returns:

  • (Boolean)


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

Parameters:

  • value (Boolean)

Returns:

  • (nil)


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