module OGR::Feature::Extensions
Public Instance Methods
Retrieves the value for each field and yields it.
@return [Enumerator] @yieldparam [Number, String
, Array]
# File lib/ogr/extensions/feature/extensions.rb, line 12 def each_field return enum_for(:each_field) unless block_given? field_count.times do |i| yield field(i) end end
@return [Enumerator] @yieldparam [OGR::Geometry]
# File lib/ogr/extensions/feature/extensions.rb, line 71 def each_geometry_field return enum_for(:each_geometry_field) unless block_given? geometry_field_count.times do |i| yield geometry_field(i) end end
@return [Enumerator] @yieldparam [OGR::GeometryFieldDefinition]
# File lib/ogr/extensions/feature/extensions.rb, line 56 def each_geometry_field_definition return enum_for(:each_geometry_field_definition) unless block_given? geometry_field_count.times do |i| yield geometry_field_definition(i) end end
Retrieves a field using index
, but uses its type from the associated {OGR::FieldDefinition} to determine it’s core type to return as. This saves from having to find out the type then call the associated field_as_[type]
method if you just want the data in it’s originally intended form.
@param index [Integer] Index of the field to retrieve the data for. @return [Number, String
, Array] @raise [OGR::UnsupportedFieldType] if the associated FieldDefinition’s
type has not yet been mapped here (to know how to return the value).
# File lib/ogr/extensions/feature/extensions.rb, line 36 def field(index) field_type = field_definition(index).type case field_type when :OFTInteger, :OFTInteger64 then field_as_integer(index) when :OFTIntegerList, :OFTInteger64List then field_as_integer_list(index) when :OFTReal then field_as_double(index) when :OFTRealList then field_as_double_list(index) when :OFTString, :OFTWideString then field_as_string(index) when :OFTStringList, :OFTWideStringList then field_as_string_list(index) when :OFTBinary then field_as_binary(index) when :OFTDate, :OFTTime, :OFTDateTime, :OFTMaxType then field_as_date_time(index) else raise OGR::UnsupportedFieldType, "Don't know how to fetch field for field type: #{field_type}" end end
@return [Array] Uses each FieldDefinition
to determine the field type at
each index and returns maps the field as that value type.
# File lib/ogr/extensions/feature/extensions.rb, line 22 def fields each_field.to_a end
@return [Array<OGR::GeometryFieldDefinition>]
# File lib/ogr/extensions/feature/extensions.rb, line 65 def geometry_field_definitions each_geometry_field_definition.to_a end
@return [Array<OGR::Geometry>]
# File lib/ogr/extensions/feature/extensions.rb, line 80 def geometry_fields each_geometry_field.to_a end