Class: OGR::Layer

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-ogr/layer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Layer

Returns a new instance of Layer.


5
6
7
8
9
# File 'lib/ffi-ogr/layer.rb', line 5

def initialize(ptr)
  @ptr = FFI::AutoPointer.new(ptr, self.class.method(:release))
  #@ptr = FFI::AutoPointer.new(ptr)
  @ptr.autorelease = false
end

Instance Attribute Details

#geometry_type=(value) ⇒ Object

Sets the attribute geometry_type

Parameters:

  • value

    the value to set the attribute geometry_type to.


3
4
5
# File 'lib/ffi-ogr/layer.rb', line 3

def geometry_type=(value)
  @geometry_type = value
end

#name=(value) ⇒ Object

Sets the attribute name

Parameters:

  • value

    the value to set the attribute name to.


3
4
5
# File 'lib/ffi-ogr/layer.rb', line 3

def name=(value)
  @name = value
end

#ptrObject

Returns the value of attribute ptr


3
4
5
# File 'lib/ffi-ogr/layer.rb', line 3

def ptr
  @ptr
end

Class Method Details

.release(ptr) ⇒ Object


11
# File 'lib/ffi-ogr/layer.rb', line 11

def self.release(ptr);end

Instance Method Details

#add_feature(feature) ⇒ Object


65
66
67
# File 'lib/ffi-ogr/layer.rb', line 65

def add_feature(feature)
  FFIOGR.OGR_L_CreateFeature(@ptr, feature.ptr)
end

#add_field(name, field_type, options = {}) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ffi-ogr/layer.rb', line 43

def add_field(name, field_type, options={})
  type = field_type.to_sym
  precision = options[:precision] || 1
  width = options[:width] || 32

  field = FFIOGR.OGR_Fld_Create(name, field_type.to_sym)

  if type == :real
    FFIOGR.OGR_Fld_SetPrecision(field, precision)
  else
    FFIOGR.OGR_Fld_SetWidth(field, width)
  end

  FFIOGR.OGR_L_CreateField(@ptr, field, 1)
  FFIOGR.OGR_Fld_Destroy(field)
end

#create_featureObject


60
61
62
63
# File 'lib/ffi-ogr/layer.rb', line 60

def create_feature
  feature = FFIOGR.OGR_F_Create(FFIOGR.OGR_L_GetLayerDefn(@ptr))
  OGR::Tools.cast_feature(feature)
end

#freeObject


13
14
15
# File 'lib/ffi-ogr/layer.rb', line 13

def free
  @ptr.free
end

#get_envelopeObject Also known as: envelope


21
22
23
24
25
# File 'lib/ffi-ogr/layer.rb', line 21

def get_envelope
  envelope = FFI::MemoryPointer.new :pointer, 4
  FFIOGR.OGR_L_GetExtent(@ptr, envelope, 0)
  OGR::Envelope.new(envelope.read_array_of_double(4))
end

#get_featuresObject Also known as: features


69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ffi-ogr/layer.rb', line 69

def get_features
  features = []

  FFIOGR.OGR_L_ResetReading(@ptr)
  num_features = FFIOGR.OGR_L_GetFeatureCount(@ptr, 0)

  for i in (0...num_features) do
    features << OGR::Tools.cast_feature(FFIOGR.OGR_L_GetNextFeature(@ptr))
  end

  features
end

#get_geometry_typeObject Also known as: geometry_type


33
34
35
# File 'lib/ffi-ogr/layer.rb', line 33

def get_geometry_type
  FFIOGR.OGR_L_GetGeomType(@ptr)
end

#get_nameObject Also known as: name


28
29
30
# File 'lib/ffi-ogr/layer.rb', line 28

def get_name
  FFIOGR.OGR_L_GetName(@ptr)
end

#get_spatial_refObject Also known as: spatial_ref


38
39
40
# File 'lib/ffi-ogr/layer.rb', line 38

def get_spatial_ref
  OGR::Tools.cast_spatial_reference(FFIOGR.OGR_L_GetSpatialRef(@ptr))
end

#syncObject


17
18
19
# File 'lib/ffi-ogr/layer.rb', line 17

def sync
  FFIOGR.OGR_L_SyncToDisk(@ptr)
end