class OGR::FeatureDefinition

Attributes

c_pointer[R]

@return [FFI::Pointer] C pointer of the C FeatureDefn.

Public Class Methods

new(name_or_pointer) click to toggle source

@param name_or_pointer [String, FFI::Pointer] When given a String, it will

create a new FeatureDefinition with that name. When given an
FFI::Pointer, the new object will simply wrap the C FeatureDefinition
at that address.
# File lib/ogr/feature_definition.rb, line 22
def initialize(name_or_pointer)
  pointer = if name_or_pointer.is_a? String
              FFI::OGR::API.OGR_FD_Create(name_or_pointer)
            else
              name_or_pointer
            end

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

  @c_pointer = FFI::AutoPointer.new(pointer, FeatureDefinition.method(:release))
  @c_pointer.autorelease = false
end
release(pointer) click to toggle source

@param pointer [FFI::Pointer]

# File lib/ogr/feature_definition.rb, line 9
def self.release(pointer)
  return unless pointer && !pointer.null?

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

Public Instance Methods

add_field_definition(field_definition) click to toggle source

@param field_definition [OGR::FieldDefinition, FFI::Pointer]

# File lib/ogr/feature_definition.rb, line 68
def add_field_definition(field_definition)
  field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, field_definition)

  if field_definition_ptr.nil?
    raise OGR::InvalidFieldDefinition, "Unable to add OGR::FieldDefinition: '#{field_definition}'"
  end

  FFI::OGR::API.OGR_FD_AddFieldDefn(@c_pointer, field_definition_ptr)
end
add_geometry_field_definition(geometry_field_definition) click to toggle source

@param geometry_field_definition [OGR::GeometryFieldDefinition, FFI::Pointer]

# File lib/ogr/feature_definition.rb, line 151
def add_geometry_field_definition(geometry_field_definition)
  geometry_field_definition_ptr = GDAL._pointer(OGR::GeometryFieldDefinition, geometry_field_definition)
  FFI::OGR::API.OGR_FD_AddGeomFieldDefn(@c_pointer, geometry_field_definition_ptr)
end
delete_field_definition(index) click to toggle source

@param index [Integer] Index of the field definition to delete. @raise [OGR::Failure]

# File lib/ogr/feature_definition.rb, line 80
def delete_field_definition(index)
  OGR::ErrorHandling.handle_ogr_err("Unable to delete field definition at index #{index}") do
    FFI::OGR::API.OGR_FD_DeleteFieldDefn(
      @c_pointer,
      index
    )
  end
end
delete_geometry_field_definition(index) click to toggle source

@param index [Integer] @raise [OGR::Failure]

# File lib/ogr/feature_definition.rb, line 158
def delete_geometry_field_definition(index)
  OGR::ErrorHandling.handle_ogr_err("Unable to delete geometry field definition at index #{index}") do
    FFI::OGR::API.OGR_FD_DeleteGeomFieldDefn(@c_pointer, index)
  end
end
field_count() click to toggle source

@return [Integer]

# File lib/ogr/feature_definition.rb, line 52
def field_count
  FFI::OGR::API.OGR_FD_GetFieldCount(@c_pointer)
end
field_definition(index) click to toggle source

@param index [Integer] @return [OGR::FieldDefinition]

# File lib/ogr/feature_definition.rb, line 58
def field_definition(index)
  field_definition_ptr = FFI::OGR::API.OGR_FD_GetFieldDefn(@c_pointer, index)
  field_definition_ptr.autorelease = false

  return nil if field_definition_ptr.null?

  OGR::FieldDefinition.new(field_definition_ptr, nil)
end
field_index(name) click to toggle source

@param name [String] @return [Integer] nil if no match found

# File lib/ogr/feature_definition.rb, line 91
def field_index(name)
  result = FFI::OGR::API.OGR_FD_GetFieldIndex(@c_pointer, name)

  result.negative? ? nil : result
end
geometry_field_count() click to toggle source

@return [Integer]

# File lib/ogr/feature_definition.rb, line 128
def geometry_field_count
  FFI::OGR::API.OGR_FD_GetGeomFieldCount(@c_pointer)
end
geometry_field_definition(index) click to toggle source

@param index [Integer] @return [OGR::GeometryFieldDefinition]

# File lib/ogr/feature_definition.rb, line 134
def geometry_field_definition(index)
  geometry_field_definition_ptr = FFI::OGR::API.OGR_FD_GetGeomFieldDefn(@c_pointer, index)

  return nil if geometry_field_definition_ptr.null?

  OGR::GeometryFieldDefinition.new(geometry_field_definition_ptr)
end
geometry_field_index(name) click to toggle source

@param name [String] @return [Integer]

# File lib/ogr/feature_definition.rb, line 144
def geometry_field_index(name)
  result = FFI::OGR::API.OGR_FD_GetGeomFieldIndex(@c_pointer, name)

  result.negative? ? nil : result
end
geometry_ignored?() click to toggle source

@return [Boolean]

# File lib/ogr/feature_definition.rb, line 108
def geometry_ignored?
  FFI::OGR::API.OGR_FD_IsGeometryIgnored(@c_pointer)
end
geometry_type() click to toggle source

@return [FFI::OGR::API::WKBGeometryType]

# File lib/ogr/feature_definition.rb, line 98
def geometry_type
  FFI::OGR::API.OGR_FD_GetGeomType(@c_pointer)
end
geometry_type=(new_type) click to toggle source

@param new_type [FFI::OGR::API::WKBGeometryType]

# File lib/ogr/feature_definition.rb, line 103
def geometry_type=(new_type)
  FFI::OGR::API.OGR_FD_SetGeomType(@c_pointer, new_type)
end
ignore_geometry!(ignore: true) click to toggle source

@param ignore [Boolean]

# File lib/ogr/feature_definition.rb, line 113
def ignore_geometry!(ignore: true)
  FFI::OGR::API.OGR_FD_SetGeometryIgnored(@c_pointer, ignore)
end
ignore_style!(ignore: true) click to toggle source

@param ignore [Boolean]

# File lib/ogr/feature_definition.rb, line 123
def ignore_style!(ignore: true)
  FFI::OGR::API.OGR_FD_SetStyleIgnored(@c_pointer, ignore)
end
name() click to toggle source

@return [String]

# File lib/ogr/feature_definition.rb, line 44
def name
  name, ptr = FFI::OGR::API.OGR_FD_GetName(@c_pointer)
  ptr.autorelease = false

  name
end
release!() click to toggle source
# File lib/ogr/feature_definition.rb, line 37
def release!
  FeatureDefinition.release(@c_pointer)

  @c_pointer = nil
end
same?(other_feature_definition) click to toggle source

@param other_feature_definition [OGR::Feature, FFI::Pointer] @return [Boolean]

# File lib/ogr/feature_definition.rb, line 166
def same?(other_feature_definition)
  fd_ptr = GDAL._pointer(OGR::FeatureDefinition, other_feature_definition)

  FFI::OGR::API.OGR_FD_IsSame(@c_pointer, fd_ptr)
end
style_ignored?() click to toggle source

@return [Boolean]

# File lib/ogr/feature_definition.rb, line 118
def style_ignored?
  FFI::OGR::API.OGR_FD_IsStyleIgnored(@c_pointer)
end