Class: Proj::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/config.rb

Instance Method Summary collapse

Instance Method Details

#data_pathObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/config.rb', line 33

def data_path
  if ENV['PROJ_LIB'] && File.directory?(ENV['PROJ_LIB'])
    ENV['PROJ_LIB']
  else
    result = self.search_paths.detect do |path|
      File.directory?(path)
    end

    unless result
      raise(Error, "Could not find Proj data directory. Please set the PROJ_LIB environmental variable to correct directory")
    end

    result
  end
end

#db_pathObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/config.rb', line 56

def db_path
  result = self.search_paths.map do |path|
    File.join(path, 'proj.db')
  end.detect do |path|
    File.exists?(path)
  end

  unless result
    raise(Error, "Could not find Proj database (proj.db). Please set the PROJ_LIB environmental variable to directory that contains it")
  end

  result
end

#search_pathsObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/config.rb', line 21

def search_paths
  ['/usr/share/proj',
   '/usr/local/share/proj',
   '/opt/share/proj',
   '/opt/local/share/proj',
   'c:/msys64/mingw64/share/proj',
   'c:/mingw64/share/proj',
   '/opt/local/lib/proj6/share/proj',
   '/opt/local/lib/proj5/share/proj',
   '/opt/local/lib/proj49/share/proj']
end

#search_paths_pointerObject



49
50
51
52
53
54
# File 'lib/config.rb', line 49

def search_paths_pointer
  p_path = FFI::MemoryPointer.from_string(self.data_path)
  p_paths = FFI::MemoryPointer.new(:pointer, 1)
  p_paths[0].write_pointer(p_path)
  p_paths
end

#set_search_pathsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/config.rb', line 7

def set_search_paths
  p_paths = self.search_paths_pointer
  items = p_paths.type_size/p_paths.size

  # Set search paths on default context - any new contexts will inherit from this
  if Api.method_defined?(:proj_context_set_search_paths)
    Api.proj_context_set_search_paths(nil, items, p_paths)
  end

  if Api.method_defined?(:pj_set_searchpath)
    Api.pj_set_searchpath(items, p_paths)
  end
end