Module: OGR::LayerMixins::OGRFeatureMethods
- Included in:
- OGR::Layer
- Defined in:
- lib/ogr/layer_mixins/ogr_feature_methods.rb
Instance Method Summary collapse
-
#create_feature(feature) ⇒ Object
Adds the new OGR::Feature to the Layer.
-
#definition ⇒ OGR::FeatureDefinition?
(also: #feature_definition)
The schema information for this layer.
-
#delete_feature(feature_id) ⇒ Object
Deletes the feature from the layer.
- #feature(index) ⇒ OGR::Feature?
-
#feature=(new_feature) ⇒ Object
Rewrites an existing feature using the ID within the given Feature.
-
#feature_count(force: true) ⇒ Integer
The number of features in this layer.
- #features_read ⇒ Integer
-
#next_feature ⇒ OGR::Feature?
The next available feature in this layer.
-
#next_feature_index=(feature_index) ⇒ Object
(also: #set_next_by_index)
Sets the index for #next_feature.
-
#reset_reading ⇒ Object
Resets the sequential reading of features for this layer.
Instance Method Details
#create_feature(feature) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 29 def create_feature(feature) unless test_capability("SequentialWrite") raise OGR::UnsupportedOperation, "This layer does not support feature creation." end OGR::ErrorHandling.handle_ogr_err("Unable to create feature") do FFI::OGR::API.OGR_L_CreateFeature(@c_pointer, feature.c_pointer) end end |
#definition ⇒ OGR::FeatureDefinition? Also known as: feature_definition
The schema information for this layer.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 9 def definition feature_defn_pointer = FFI::OGR::API.OGR_L_GetLayerDefn(@c_pointer) feature_defn_pointer.autorelease = false return nil if feature_defn_pointer.null? # This object should not be modified. OGR::FeatureDefinition.new(feature_defn_pointer) end |
#delete_feature(feature_id) ⇒ Object
Deletes the feature from the layer.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 45 def delete_feature(feature_id) unless test_capability("DeleteFeature") raise OGR::UnsupportedOperation, "This layer does not support feature deletion." end OGR::ErrorHandling.handle_ogr_err("Unable to delete feature with ID '#{feature_id}'") do FFI::OGR::API.OGR_L_DeleteFeature(@c_pointer, feature_id) end end |
#feature(index) ⇒ OGR::Feature?
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 83 def feature(index) unless test_capability("RandomRead") raise OGR::UnsupportedOperation, "#feature(index) not supported by this Layer" end # This feature needs to be Destroyed. feature_pointer = FFI::OGR::API.OGR_L_GetFeature(@c_pointer, index) return nil if feature_pointer.null? OGR::Feature.new(feature_pointer) end |
#feature=(new_feature) ⇒ Object
Rewrites an existing feature using the ID within the given Feature.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 69 def feature=(new_feature) raise OGR::UnsupportedOperation, "#feature= not supported by this Layer" unless test_capability("RandomWrite") new_feature_ptr = GDAL._pointer(OGR::Feature, new_feature) raise OGR::InvalidFeature if new_feature_ptr.nil? || new_feature_ptr.null? OGR::ErrorHandling.handle_ogr_err("Unable to set feature") do FFI::OGR::API.OGR_L_SetFeature(@c_pointer, new_feature_ptr) end end |
#feature_count(force: true) ⇒ Integer
The number of features in this layer. If force
is false and it would be expensive to determine the feature count, -1 may be returned.
61 62 63 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 61 def feature_count(force: true) FFI::OGR::API.OGR_L_GetFeatureCount(@c_pointer, force) end |
#features_read ⇒ Integer
123 124 125 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 123 def features_read FFI::OGR::API.OGR_L_GetFeaturesRead(@c_pointer) end |
#next_feature ⇒ OGR::Feature?
The next available feature in this layer. Only features matching the current spatial filter will be returned. Use reset_reading
to start at the beginning again.
NOTE: You must call OGR::LayerMixins::OGRFeatureMethods.{OGR{OGR::Feature{OGR::Feature#destroy!} on the returned feature, otherwise expect segfaults.
104 105 106 107 108 109 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 104 def next_feature feature_pointer = FFI::OGR::API.OGR_L_GetNextFeature(@c_pointer) return if feature_pointer.null? OGR::Feature.new(feature_pointer) end |
#next_feature_index=(feature_index) ⇒ Object Also known as: set_next_by_index
Sets the index for #next_feature.
115 116 117 118 119 |
# File 'lib/ogr/layer_mixins/ogr_feature_methods.rb', line 115 def next_feature_index=(feature_index) OGR::ErrorHandling.handle_ogr_err("Unable to set next feature index to #{feature_index}") do FFI::OGR::API.OGR_L_SetNextByIndex(@c_pointer, feature_index) end end |