Sha256: 4cc6592cd16a80e9b00628a40cb2666e47af3aadd98b9bfb228eea15179d073f

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'json'

module OGR
  module FeatureDefinitionExtensions
    # @return [Array<OGR::FieldDefinition>]
    def field_definitions
      return [] if field_count.zero?

      field_count.times.map do |i|
        field_definition(i)
      end
    end

    # @return [Array<OGR::GeometryFieldDefinition>]
    def geometry_field_definitions
      return [] if geometry_field_count.zero?

      geometry_field_count.times.map do |i|
        geometry_field_definition(i)
      end
    end

    # @param name [String]
    # @return [OGR::FieldDefinition]
    def field_definition_by_name(name)
      i = field_index(name)
      return unless i

      field_definition(i)
    end

    # @param name [String]
    # @return [OGR::GeometryFieldDefinition]
    def geometry_field_definition_by_name(name)
      g = geometry_field_index(name)
      return unless g

      geometry_field_definition(g)
    end

    # @return [Hash]
    def as_json(_options = nil)
      {
        field_count: field_count,
        field_definitions: field_definitions.map(&:as_json),
        geometry_field_count: geometry_field_count,
        geometry_type: geometry_type,
        is_geometry_ignored: geometry_ignored?,
        is_style_ignored: style_ignored?,
        name: name
      }
    end

    # @return [String]
    def to_json(options = nil)
      as_json(options).to_json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta5 lib/ogr/feature_definition_extensions.rb
ffi-gdal-1.0.0.beta4 lib/ogr/feature_definition_extensions.rb