Sha256: 436e0013504477515dd4443c6a612f4d3528bcf08227356cfd32222db65676aa

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require_relative '../ffi/gdal'


module GDAL
  module MajorObject
    # @return [Array<String>]
    def metadata_domain_list
      unless defined? FFI::GDAL.GDALGetMetadataDomainList
        warn "GDALGetMetadataDomainList is't defined. GDAL::MajorObject#metadata_domain_list disabled."
        return []
      end

      list_pointer = FFI::GDAL.GDALGetMetadataDomainList(c_pointer)
      return [] if list_pointer.null?

      strings = list_pointer.get_array_of_string(0)

      strings.compact.delete_if(&:empty?)
    end

    # @param domain [String] Name of the domain to get metadata for.
    # @return [Hash]
    def metadata(domain='')
      m = FFI::GDAL.GDALGetMetadata(c_pointer, domain)
      return {} if m.null?

      data_array = m.get_array_of_string(0)

      data_array.each_with_object({}) do |key_value_pair, obj|
        key, value = key_value_pair.split('=', 2)

        begin
          obj[key] = MultiXml.parse(value)
        rescue MultiXml::ParseError
          obj[key] = value
        end
      end
    end

    # @param name [String]
    # @param domain [String]
    # @return [String]
    def metadata_item(name, domain='')
      FFI::GDAL.GDALGetMetadataItem(c_pointer, name, domain)
    end

    def set_metadata_item(name, value, domain='')
      cpl_err = FFI::GDAL.GDALSetMetadataItem(c_pointer, name, value.to_s, domain)

      cpl_err.to_bool
    end

    # @return [Hash{domain => Array<String>}]
    def all_metadata
      sub_metadata = metadata_domain_list.each_with_object({}) do |subdomain, obj|
        metadata_array = metadata(subdomain)
        obj[subdomain] = metadata_array
      end

      { DEFAULT: metadata }.merge(sub_metadata)
    end

    # @return [String]
    def description
      FFI::GDAL.GDALGetDescription(c_pointer)
    end

    # @param new_description [String]
    def description=(new_description)
      FFI::GDAL.GDALSetDescription(c_pointer, new_description.to_s)
    end

    def null?
      c_pointer.null?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta3 lib/gdal/major_object.rb
ffi-gdal-1.0.0.beta1 lib/gdal/major_object.rb