Class: OGR::GeometryFieldDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/ogr/geometry_field_definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_or_pointer, type = :wkbUnknown) ⇒ GeometryFieldDefinition

Returns a new instance of GeometryFieldDefinition.

Parameters:

  • name_or_pointer (String, FFI::Pointer)
  • type (FFI::OGR::API::WKBGeometryType) (defaults to: :wkbUnknown)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ogr/geometry_field_definition.rb', line 20

def initialize(name_or_pointer, type = :wkbUnknown)
  pointer = if name_or_pointer.is_a? String
              FFI::OGR::API.OGR_GFld_Create(name_or_pointer, type)
            else
              name_or_pointer
            end

  if !pointer.is_a?(FFI::Pointer) || pointer.null?
    raise OGR::InvalidGeometryFieldDefinition, "Unable to create #{self.class.name} from #{name_or_pointer}"
  end

  @c_pointer = FFI::AutoPointer.new(pointer, GeometryFieldDefinition.method(:release))
  @c_pointer.autorelease = false

  @read_only = false
end

Instance Attribute Details

#c_pointerFFI::Pointer (readonly)

Returns:

  • (FFI::Pointer)


13
14
15
# File 'lib/ogr/geometry_field_definition.rb', line 13

def c_pointer
  @c_pointer
end

#read_only=(value) ⇒ Object (writeonly)

Parameters:

  • value (Boolean)


16
17
18
# File 'lib/ogr/geometry_field_definition.rb', line 16

def read_only=(value)
  @read_only = value
end

Class Method Details

.release(pointer) ⇒ Object

Parameters:

  • pointer (FFI::Pointer)


6
7
8
9
10
# File 'lib/ogr/geometry_field_definition.rb', line 6

def self.release(pointer)
  return unless pointer && !pointer.null?

  FFI::OGR::API.OGR_GFld_Destroy(pointer)
end

Instance Method Details

#destroy!Object



42
43
44
45
46
# File 'lib/ogr/geometry_field_definition.rb', line 42

def destroy!
  GeometryFieldDefinition.release(@c_pointer)

  @c_pointer = nil
end

#ignore=(value) ⇒ Object

Parameters:

  • value (Boolean)

Raises:



110
111
112
113
114
# File 'lib/ogr/geometry_field_definition.rb', line 110

def ignore=(value)
  raise OGR::ReadOnlyObject if @read_only

  FFI::OGR::API.OGR_GFld_SetIgnored(@c_pointer, value)
end

#ignored?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/ogr/geometry_field_definition.rb', line 105

def ignored?
  FFI::OGR::API.OGR_GFld_IsIgnored(@c_pointer)
end

#nameString

Returns:



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

def name
  name, ptr = FFI::OGR::API.OGR_GFld_GetNameRef(@c_pointer)
  ptr.autorelease = false

  name
end

#name=(new_name) ⇒ Object

Parameters:

Raises:



57
58
59
60
61
# File 'lib/ogr/geometry_field_definition.rb', line 57

def name=(new_name)
  raise OGR::ReadOnlyObject if @read_only

  FFI::OGR::API.OGR_GFld_SetName(@c_pointer, new_name)
end

#read_only?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ogr/geometry_field_definition.rb', line 38

def read_only?
  @read_only || false
end

#spatial_referenceOGR::SpatialReference



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ogr/geometry_field_definition.rb', line 76

def spatial_reference
  spatial_ref_ptr = FFI::OGR::API.OGR_GFld_GetSpatialRef(@c_pointer)

  if spatial_ref_ptr.nil? || spatial_ref_ptr.null?
    nil
  else
    auto_ptr = FFI::AutoPointer.new(spatial_ref_ptr, OGR::SpatialReference.method(:release))

    OGR::SpatialReference.new(auto_ptr)
  end
end

#spatial_reference=(new_spatial_reference) ⇒ Object

This function drops the reference of the previously set SRS object and acquires a new reference on the passed object (if non-NULL).

Parameters:

Raises:



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ogr/geometry_field_definition.rb', line 92

def spatial_reference=(new_spatial_reference)
  raise OGR::ReadOnlyObject if @read_only

  spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, new_spatial_reference, autorelease: false)
  raise if spatial_ref_ptr.null?

  FFI::OGR::API.OGR_GFld_SetSpatialRef(
    @c_pointer,
    spatial_ref_ptr
  )
end

#typeFFI::OGR::API::WKBGeometryType

Returns:

  • (FFI::OGR::API::WKBGeometryType)


64
65
66
# File 'lib/ogr/geometry_field_definition.rb', line 64

def type
  FFI::OGR::API.OGR_GFld_GetType(@c_pointer)
end

#type=(new_type) ⇒ Object

Parameters:

  • new_type (FFI::OGR::API::WKBGeometryType)

Raises:



69
70
71
72
73
# File 'lib/ogr/geometry_field_definition.rb', line 69

def type=(new_type)
  raise OGR::ReadOnlyObject if @read_only

  FFI::OGR::API.OGR_GFld_SetType(@c_pointer, new_type)
end