Class: Proj::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/proj/unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_name, code, name, category, conv_factor, proj_short_name, deprecated) ⇒ Unit

Create a new Unit

Parameters:

  • auth_name (String)

    Authority name

  • code (String)

    Object code

  • name (String)

    Object name. For example “metre”, “US survey foot”, etc

  • category (String)

    Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”

  • conv_factor (String)

    Conversion factor to apply to transform from that unit to the corresponding SI unit (metre for “linear”, radian for “angular”, etc.). It might be 0 in some cases to indicate no known conversion factor

  • proj_short_name (String)

    PROJ short name, like “m”, “ft”, “us-ft”, etc… Might be nil

  • deprecated (Boolean)

    Whether the object is deprecated



63
64
65
66
67
68
69
70
71
# File 'lib/proj/unit.rb', line 63

def initialize(auth_name, code, name, category, conv_factor, proj_short_name, deprecated)
  @auth_name = auth_name
  @code = code
  @name = name
  @category = category
  @conv_factor = conv_factor
  @proj_short_name = proj_short_name
  @deprecated = deprecated
end

Instance Attribute Details

#auth_nameString (readonly)

Returns Authority name.

Returns:

  • (String)

    Authority name



17
18
19
# File 'lib/proj/unit.rb', line 17

def auth_name
  @auth_name
end

#categoryString (readonly)

Returns Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”.

Returns:

  • (String)

    Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

#codeString (readonly)

Returns Object code.

Returns:

  • (String)

    Object code



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

#conv_factorString (readonly)

Returns Conversion factor to apply to transform from that unit to the corresponding SI unit (metre for “linear”, radian for “angular”, etc.). It might be 0 in some cases to indicate no known conversion factor.

Returns:

  • (String)

    Conversion factor to apply to transform from that unit to the corresponding SI unit (metre for “linear”, radian for “angular”, etc.). It might be 0 in some cases to indicate no known conversion factor



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

#deprecatedObject (readonly)

Returns the value of attribute deprecated.



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

#nameString (readonly)

Returns Object name. For example “metre”, “US survey foot”, etc.

Returns:

  • (String)

    Object name. For example “metre”, “US survey foot”, etc



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

#proj_short_nameString (readonly)

Returns PROJ short name, like “m”, “ft”, “us-ft”, etc… Might be nil.

Returns:

  • (String)

    PROJ short name, like “m”, “ft”, “us-ft”, etc… Might be nil



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

Class Method Details

.built_in(auth_name: nil, category: nil, allow_deprecated: false) ⇒ Object

Returns a list of built in Units. This is deprecated. Use Database#units instead



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/proj/unit.rb', line 20

def self.built_in(auth_name: nil, category: nil, allow_deprecated: false)
  # First get linear units
  pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_units)
  result = Array.new
  0.step do |i|
    unit_info = Api::PJ_UNITS.new(pointer_to_array[i])
    break if unit_info[:id].nil?
    result << self.new('PROJ', unit_info[:id], unit_info[:name],
                       'length', unit_info[:factor], unit_info[:id], false)
  end

  # Now get angular linear units
  if Api.method_defined?(:proj_list_angular_units)
    pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_angular_units)
    0.step do |i|
      unit_info = Api::PJ_UNITS.new(pointer_to_array[i])
      break result if unit_info[:id].nil?
      result << self.new('PROJ', unit_info[:id], unit_info[:name],
                         'angular', unit_info[:factor], unit_info[:id], false)
    end
  end

  if auth_name
    result = result.find_all {|unit_info| unit_info.auth_name == auth_name}
  end

  if category
    result = result.find_all {|unit_info| unit_info.category == category}
  end
  result
end

Instance Method Details

#<=>(other) ⇒ Object



73
74
75
# File 'lib/proj/unit.rb', line 73

def <=>(other)
  self.name <=> other.name
end

#==(other) ⇒ Object



77
78
79
80
# File 'lib/proj/unit.rb', line 77

def ==(other)
  self.auth_name == other.auth_name &&
  self.code == other.code
end

#inspectObject



105
106
107
# File 'lib/proj/unit.rb', line 105

def inspect
  "#<#{self.class} authority=\"#{auth_name}\", code=\"#{code}\", name=\"#{name}\">"
end

#to_sObject



101
102
103
# File 'lib/proj/unit.rb', line 101

def to_s
  self.name
end

#unit_typeObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/proj/unit.rb', line 82

def unit_type
  case self.category
  when "linear"
    :PJ_UT_LINEAR
  when "linear_per_time"
    :PJ_UT_LINEAR
  when "angular"
    :PJ_UT_ANGULAR
  when "angular_per_time"
    :PJ_UT_ANGULAR
  when "scale"
    :PJ_UT_SCALE
  when "scale_per_time"
    :PJ_UT_SCALE
  when "time"
    :PJ_UT_TIME
  end
end