class Proj::Context

Proj 4.8 introduced the concept of a thread context object to support multi-threaded programs. The bindings automatically create one context per thread (its stored in local thread storage).

Attributes

database[R]

Public Class Methods

current() click to toggle source

The context for the current thread. If a context does not exist a new one is created

@return [Context] The context for the current thread

# File lib/proj/context.rb, line 22
def self.current
  Thread.current[:proj_context] ||= Context.new
end
default() click to toggle source

Returns the default Proj context. This context must only be used in the main thread In general it is better to create new contexts

@return [Context] The default context

# File lib/proj/context.rb, line 11
def self.default
  result = Context.allocate
  # The default Proj Context is represented by a null pointer
  result.instance_variable_set(:@pointer, FFI::Pointer::NULL)
  result
end
finalize(pointer) click to toggle source

@!visibility private

# File lib/proj/context.rb, line 27
def self.finalize(pointer)
  proc do
    Api.proj_context_destroy(pointer)
  end
end
new() click to toggle source
# File lib/proj/context.rb, line 33
def initialize
  @pointer = Api.proj_context_create
  ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))

  @database = Database.new(self)
end

Public Instance Methods

ca_bundle_path=(path) click to toggle source

Sets the CA Bundle path which will be used by PROJ when curl and PROJ_NETWORK are enabled.

@see proj.org/development/reference/functions.html#c.proj_context_set_ca_bundle_path

@param path [String] Path to CA bundle.

@return [nil]

# File lib/proj/context.rb, line 129
def ca_bundle_path=(path)
  Api.proj_context_set_ca_bundle_path(self, path.encode(:utf8))
end
cache() click to toggle source

Returns the cache used to store grid files locally

@return [GridCache]

# File lib/proj/context.rb, line 136
def cache
  GridCache.new(self)
end
database_path() click to toggle source

— Deprecated ——-

# File lib/proj/context.rb, line 237
def database_path
  self.database.path
end
database_path=(value) click to toggle source

Sets the path to the Proj database

# File lib/proj/context.rb, line 242
def database_path=(value)
  self.database.path = value
end
errno() click to toggle source

Returns the current error-state of the context. An non-zero error codes indicates an error.

See proj.org/development/reference/functions.html#c.proj_context_errno proj_context_errno

return [Integer]

# File lib/proj/context.rb, line 60
def errno
  Api.proj_context_errno(self)
end
initialize_copy(original) click to toggle source
Calls superclass method
# File lib/proj/context.rb, line 40
def initialize_copy(original)
  ObjectSpace.undefine_finalizer(self)

  super

  @pointer = Api.proj_context_clone(original)
  @database = Database.new(self)

  ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
end
log_level() click to toggle source

Gets the current log level

@return [PJ_LOG_LEVEL]

# File lib/proj/context.rb, line 82
def log_level
  Api.proj_log_level(self, :PJ_LOG_TELL)
end
log_level=(value) click to toggle source

Sets the current log level

@param value [PJ_LOG_LEVEL] @return [nil]

# File lib/proj/context.rb, line 90
def log_level=(value)
  Api.proj_log_level(self, value)
end
network_enabled=(value) click to toggle source

Enable or disable network access for downloading grid files

@see proj.org/development/reference/functions.html#c.proj_context_set_enable_network

@param value [Boolean] Specifies if network access should be enabled or disabled

# File lib/proj/context.rb, line 155
def network_enabled=(value)
  Api.proj_context_set_enable_network(self, value ? 1 : 0)
end
network_enabled?() click to toggle source

Returns if network access is enabled allowing {Grid} files to be downloaded

@see proj.org/development/reference/functions.html#c.proj_context_is_network_enabled

@return [Boolean] True if network access is enabled, otherwise false

# File lib/proj/context.rb, line 145
def network_enabled?
  result = Api.proj_context_is_network_enabled(self)
  result == 1 ? true : false
end
search_paths=(paths) click to toggle source

Sets the paths that Proj will search when opening one of its resource files such as the proj.db database, grids, etc.

If set on the default context, they will be inherited by contexts created later.

@see proj.org/development/reference/functions.html#c.proj_context_set_search_paths

# File lib/proj/context.rb, line 194
def search_paths=(paths)
  # Convert paths to C chars
  paths_ptr = paths.map do |path|
    FFI::MemoryPointer.from_string(path)
  end

  pointer = FFI::MemoryPointer.new(:pointer, paths.size)
  pointer.write_array_of_pointer(paths_ptr)

  if Api.method_defined?(:proj_context_set_search_paths)
    Api.proj_context_set_search_paths(self, paths.size, pointer)
  elsif Api.method_defined?(:pj_set_searchpath)
    Api.pj_set_searchpath(paths.size, pointer)
  end
end
set_file_api(file_api_klass) click to toggle source

Installs a new {FileApiImpl FileApi}

@see proj.org/development/reference/functions.html#c.proj_context_set_fileapi

# File lib/proj/context.rb, line 213
def set_file_api(file_api_klass)
  unless file_api_klass.kind_of?(Class)
    raise("#{file_api_klass} must be a class whose initializer has single argument which is a context")
  end

  # There is no API to "uninstall" a FileApi. Thus it needs to stay alive
  # until the context is GCed
  @file_api = file_api_klass.new(self)
end
set_log_function(pointer = nil, &proc) click to toggle source

Sets a custom log function

@example

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

@param pointer [FFI::MemoryPointer] Optional pointer to custom data @param proc [Proc] Custom logging procedure

@return [nil]

# File lib/proj/context.rb, line 75
def set_log_function(pointer = nil, &proc)
  Api.proj_log_func(self, pointer, proc)
end
set_network_api(network_api_klass) click to toggle source

Installs a new {NetworkApiImpl NetworkApi}

@see proj.org/development/reference/functions.html#c.proj_context_set_network_callbacks

# File lib/proj/context.rb, line 226
def set_network_api(network_api_klass)
  unless network_api_klass.kind_of?(Class)
    raise("#{network_api_klass} must be a class whose initializer has single argument which is a context")
  end

  # There is no API to "uninstall" a FileApi. Thus it needs to stay alive
  # until the context is GCed
  @network_api = network_api_klass.new(self)
end
to_ptr() click to toggle source
# File lib/proj/context.rb, line 51
def to_ptr
  @pointer
end
url() click to toggle source

Returns the URL endpoint to query for remote grids

@see proj.org/development/reference/functions.html#c.proj_context_get_url_endpoint

@return [String] Endpoint URL

# File lib/proj/context.rb, line 164
def url
  Api.proj_context_get_url_endpoint(self)
end
url=(value) click to toggle source

Sets the URL endpoint to query for remote grids. This overrides the default endpoint in the PROJ configuration file or with the PROJ_NETWORK_ENDPOINT environment variable.

@see proj.org/development/reference/functions.html#c.proj_context_set_url_endpoint

@param value [String] Endpoint URL

# File lib/proj/context.rb, line 173
def url=(value)
  Api.proj_context_set_url_endpoint(self, value)
end
use_proj4_init_rules() click to toggle source

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

@return [Boolean]

# File lib/proj/context.rb, line 97
def use_proj4_init_rules
  result = Api.proj_context_get_use_proj4_init_rules(self, 0)
  result == 1 ? true : false
end
use_proj4_init_rules=(value) click to toggle source

Sets if proj4 init rules should be used

@param value [Boolean]

@return [nil]

# File lib/proj/context.rb, line 107
def use_proj4_init_rules=(value)
  Api.proj_context_use_proj4_init_rules(self, value ? 1 : 0)
end
user_directory(create = false) click to toggle source

Returns the user directory used to save grid files.

@see proj.org/development/reference/functions.html#c.proj_context_get_user_writable_directory

@param create [Boolean] If true create the directory if it does not exist already. Defaults to false.

@return [String] Directory

# File lib/proj/context.rb, line 184
def user_directory(create = false)
  Api.proj_context_get_user_writable_directory(self, create ? 1 : 0)
end
wkt_dialect(wkt) click to toggle source

Guess the “dialect” of the specified WKT string

@see proj.org/development/reference/functions.html#c.proj_context_guess_wkt_dialect

@param wkt [String] A WKT string

@return [PJ_GUESSED_WKT_DIALECT]

# File lib/proj/context.rb, line 118
def wkt_dialect(wkt)
  Api.proj_context_guess_wkt_dialect(self, wkt)
end