Module: OGR::LayerMixins::OGRFieldMethods
- Included in:
- OGR::Layer
- Defined in:
- lib/ogr/layer_mixins/ogr_field_methods.rb
Instance Method Summary collapse
- #alter_field_definition(field_index, new_field_definition, flags) ⇒ Object
-
#create_field(field_definition, approx_ok: false) ⇒ Object
Creates and writes a new field to the layer.
-
#create_geometry_field(geometry_field_def, approx_ok: false) ⇒ Object
Creates and writes a new geometry to the layer.
-
#delete_field(field_id) ⇒ Object
Deletes the field definition from the layer.
-
#find_field_index(field_name, exact_match: true) ⇒ Integer
Finds the index of a field in this Layer.
-
#reorder_field(old_position, new_position) ⇒ Object
Puts the field whose index is
old_position
into index atnew_position
and shuffles the other indexes accordingly. - #reorder_fields(*new_order) ⇒ Object
-
#set_ignored_fields(*field_names) ⇒ Object
If the driver supports this functionality, it will not fetch the specified fields in subsequent calls to #feature / #next_feature and thus save some processing time and/or bandwidth.
Instance Method Details
#alter_field_definition(field_index, new_field_definition, flags) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 82 def alter_field_definition(field_index, new_field_definition, flags) unless test_capability("AlterFieldDefn") raise OGR::UnsupportedOperation, "This layer does not support field definition altering." end new_field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, new_field_definition) OGR::ErrorHandling.handle_ogr_err("Unable to alter field definition at field index #{field_index}") do FFI::OGR::API.OGR_L_AlterFieldDefn( @c_pointer, field_index, new_field_definition_ptr, flags ) end end |
#create_field(field_definition, approx_ok: false) ⇒ Object
Creates and writes a new field to the layer. This adds the field to the internal FeatureDefinition; C API says not to update the FeatureDefinition directly.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 14 def create_field(field_definition, approx_ok: false) unless test_capability("CreateField") raise OGR::UnsupportedOperation, "This layer does not support field creation." end field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, field_definition) OGR::ErrorHandling.handle_ogr_err("Unable to create field") do FFI::OGR::API.OGR_L_CreateField(@c_pointer, field_definition_ptr, approx_ok) end end |
#create_geometry_field(geometry_field_def, approx_ok: false) ⇒ Object
Creates and writes a new geometry to the layer. Note: not all drivers support this.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 118 def create_geometry_field(geometry_field_def, approx_ok: false) unless test_capability("CreateGeomField") raise OGR::UnsupportedOperation, "This layer does not support geometry field creation" end geometry_field_definition_ptr = GDAL._pointer(OGR::GeometryFieldDefinition, geometry_field_def) OGR::ErrorHandling.handle_ogr_err("Unable to create geometry field") do FFI::OGR::API.OGR_L_CreateGeomField( @c_pointer, geometry_field_definition_ptr, approx_ok ) end end |
#delete_field(field_id) ⇒ Object
Deletes the field definition from the layer.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 30 def delete_field(field_id) unless test_capability("DeleteField") raise OGR::UnsupportedOperation, "This driver does not support field deletion." end OGR::ErrorHandling.handle_ogr_err("Unable to delete field") do FFI::OGR::API.OGR_L_DeleteField(@c_pointer, field_id) end end |
#find_field_index(field_name, exact_match: true) ⇒ Integer
Finds the index of a field in this Layer.
105 106 107 108 109 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 105 def find_field_index(field_name, exact_match: true) result = FFI::OGR::API.OGR_L_FindFieldIndex(@c_pointer, field_name, exact_match) result.negative? ? nil : result end |
#reorder_field(old_position, new_position) ⇒ Object
Puts the field whose index is old_position
into index at new_position
and shuffles the other indexes accordingly.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 65 def reorder_field(old_position, new_position) unless test_capability("ReorderFields") raise OGR::UnsupportedOperation, "This driver does not support field reordering." end OGR::ErrorHandling.handle_ogr_err("Unable to reorder field: #{old_position} to #{new_position}") do FFI::OGR::API.OGR_L_ReorderField(@c_pointer, old_position, new_position) end end |
#reorder_fields(*new_order) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 44 def reorder_fields(*new_order) unless test_capability("ReorderFields") raise OGR::UnsupportedOperation, "This driver does not support field reordering." end return false if new_order.empty? || new_order.any? { |i| i > feature_definition.field_count } map_array_ptr = FFI::MemoryPointer.new(:int, new_order.size).write_array_of_int(new_order) OGR::ErrorHandling.handle_ogr_err("Unable to reorder fields using order: #{new_order}") do FFI::OGR::API.OGR_L_ReorderFields(@c_pointer, map_array_ptr) end end |
#set_ignored_fields(*field_names) ⇒ Object
If the driver supports this functionality, it will not fetch the specified fields in subsequent calls to #feature / #next_feature and thus save some processing time and/or bandwidth.
140 141 142 143 144 145 146 147 148 |
# File 'lib/ogr/layer_mixins/ogr_field_methods.rb', line 140 def set_ignored_fields(*field_names) return false if field_names.empty? fields_ptr = GDAL._string_array_to_pointer(field_names) OGR::ErrorHandling.handle_ogr_err("Unable to ignore fields with names: #{field_names}") do FFI::OGR::API.OGR_L_SetIgnoredFields(@c_pointer, fields_ptr) end end |