Class: OGR::Layer
- Inherits:
-
Object
- Object
- OGR::Layer
- Defined in:
- lib/ffi-ogr/layer.rb
Instance Attribute Summary collapse
-
#geometry_type ⇒ Object
Sets the attribute geometry_type.
-
#name ⇒ Object
Sets the attribute name.
-
#ptr ⇒ Object
Returns the value of attribute ptr.
Class Method Summary collapse
Instance Method Summary collapse
- #add_feature(feature) ⇒ Object
- #add_field(name, field_type, options = {}) ⇒ Object
- #create_feature ⇒ Object
- #free ⇒ Object
- #get_envelope ⇒ Object (also: #envelope)
- #get_features ⇒ Object (also: #features)
- #get_geometry_type ⇒ Object (also: #geometry_type)
- #get_name ⇒ Object (also: #name)
- #get_spatial_ref ⇒ Object (also: #spatial_ref)
-
#initialize(ptr) ⇒ Layer
constructor
A new instance of Layer.
- #sync ⇒ Object
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
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
3 4 5 |
# File 'lib/ffi-ogr/layer.rb', line 3 def name=(value) @name = value end |
#ptr ⇒ Object
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, ={}) type = field_type.to_sym precision = [:precision] || 1 width = [: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_feature ⇒ Object
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 |
#free ⇒ Object
13 14 15 |
# File 'lib/ffi-ogr/layer.rb', line 13 def free @ptr.free end |
#get_envelope ⇒ Object 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_features ⇒ Object 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_type ⇒ Object 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_name ⇒ Object 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_ref ⇒ Object 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 |
#sync ⇒ Object
17 18 19 |
# File 'lib/ffi-ogr/layer.rb', line 17 def sync FFIOGR.OGR_L_SyncToDisk(@ptr) end |