Class: Proj::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/proj/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = nil) ⇒ Session

Returns a new instance of Session.



12
13
14
15
16
# File 'lib/proj/session.rb', line 12

def initialize(context = nil)
  @context = context || Context.current
  @pointer = Api.proj_insert_object_session_create(@context)
  ObjectSpace.define_finalizer(self, self.class.finalize(@context, @pointer))
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/proj/session.rb', line 3

def context
  @context
end

Instance Method Details

#get_insert_statements(object, authority, code, numeric_codes = false, allowed_authorities = nil) ⇒ Strings

Returns SQL statements needed to insert the passed object into the database.

Parameters:

  • object (PjObject)
    • The object to insert into the database. Currently only PrimeMeridian, Ellipsoid, Datum, GeodeticCRS, ProjectedCRS, VerticalCRS, CompoundCRS or BoundCRS are supported.

  • authority (String)
    • Authority name into which the object will be inserted. Must not be nil

  • code (Integer)
    • Code with which the object will be inserted.Must not be nil

  • numeric_codes (Boolean) (defaults to: false)
    • Whether intermediate objects that can be created should use numeric codes (true), or may be alphanumeric (false)

  • allowed_authorities (Array<String>) (defaults to: nil)
    • Authorities to which intermediate objects are allowed to refer to. “authority” will be implicitly added to it.

Returns:

  • (Strings)
    • List of insert statements



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/proj/session.rb', line 31

def get_insert_statements(object, authority, code, numeric_codes = false, allowed_authorities = nil)
  allowed_authorities_ptr = if allowed_authorities
                              # Add extra item at end for null pointer
                              pointer = FFI::MemoryPointer.new(:pointer, allowed_authorities.size + 1)

                              # Convert strings to C chars
                              allowed_authorities.each_with_index do |authority, i|
                                pointer.put_pointer(i, FFI::MemoryPointer.from_string(authority))
                              end
                              pointer
                            end

  strings_ptr = Api.proj_get_insert_statements(self.context, self, object, authority, code, numeric_codes ? 1 : 0, allowed_authorities_ptr, nil)
  Strings.new(strings_ptr)
end

#to_ptrObject



18
19
20
# File 'lib/proj/session.rb', line 18

def to_ptr
  @pointer
end