Class: AIXM::Feature::Airspace

Inherits:
AIXM::Feature show all
Defined in:
lib/aixm/feature/airspace.rb

Overview

Three-dimensional volume most notably defining flight zones.

Cheat Sheet in Pseudo Code:

airspace = AIXM.airspace(
  source: String or nil
  id: String
  type: String or Symbol
  local_type: String or nil
  name: String or nil
)
airspace.geometry << AIXM.point or AIXM.arc or AIXM.border or AIXM.circle
airspace.layers << AIXM.layer

Constant Summary collapse

TYPES =
{
  NAS: :national_airspace_system,
  FIR: :flight_information_region,
  'FIR-P': :part_of_flight_information_region,
  UIR: :upper_flight_information_region,
  'UIR-P': :part_of_upper_flight_information_region,
  CTA: :control_area,
  'CTA-P': :part_of_control_area,
  OCA: :oceanic_control_area,
  'OCA-P': :part_of_oceanic_control_area,
  UTA: :upper_control_area,
  'UTA-P': :part_of_upper_control_area,
  TMA: :terminal_control_area,
  'TMA-P': :part_of_terminal_control_area,
  CTR: :control_zone,
  'CTR-P': :part_of_control_zone,
  CLASS: :airspace_with_class,
  OTA: :oceanic_transition_area,
  SECTOR: :control_sector,
  'SECTOR-C': :temporarily_consolidated_sector,
  TSA: :temporary_segregated_area,
  TRA: :temporary_reserved_area,
  CBA: :cross_border_area,
  RCA: :reduced_coordination_airspace_procedure,
  RAS: :regulated_airspace,
  AWY: :airway,
  P: :prohibited_area,
  R: :restricted_area,
  'R-AMC': :amc_manageable_restricted_area,
  D: :danger_area,
  'D-AMC': :amc_manageable_danger_area,
  'D-OTHER': :dangerous_activities_area,
  ADIZ: :air_defense_identification_zone,
  A: :alert_area,
  W: :warning_area,
  PROTECT: :protected_from_specific_air_traffic,
  AMA: :minimum_altitude_area,
  ASR: :altimeter_setting_region,
  'NO-FIR': :airspace_outside_any_flight_information_region,
  POLITICAL: :political_area,
  PART: :part_of_airspace
}.freeze

Instance Attribute Summary collapse

Attributes inherited from AIXM::Feature

#source

Instance Method Summary collapse

Methods inherited from AIXM::Feature

#==

Constructor Details

#initialize(source: nil, id: nil, type:, local_type: nil, name: nil) ⇒ Airspace

Returns a new instance of Airspace


86
87
88
89
90
91
92
# File 'lib/aixm/feature/airspace.rb', line 86

def initialize(source: nil, id: nil, type:, local_type: nil, name: nil)
  super(source: source)
  self.type, self.local_type, self.name = type, local_type, name
  self.id = id
  @geometry = AIXM.geometry
  @layers = []
end

Instance Attribute Details

#geometryAIXM::Component::Geometry

Returns horizontal geometrical shape

Returns:


81
82
83
# File 'lib/aixm/feature/airspace.rb', line 81

def geometry
  @geometry
end

#idString

Note:

When assigning nil, a 4 byte hex derived from #type, #name and #local_type is written instead.

Returns published identifier (e.g. “LFP81”)

Returns:

  • (String)

    published identifier (e.g. “LFP81”)


69
70
71
# File 'lib/aixm/feature/airspace.rb', line 69

def id
  @id
end

#layersArray<AIXM::Compoment::Layer>

Returns vertical layers

Returns:

  • (Array<AIXM::Compoment::Layer>)

    vertical layers


84
85
86
# File 'lib/aixm/feature/airspace.rb', line 84

def layers
  @layers
end

#local_typeString?

Returns short name (e.g. “LF P 81”)

Returns:

  • (String, nil)

    short name (e.g. “LF P 81”)


75
76
77
# File 'lib/aixm/feature/airspace.rb', line 75

def local_type
  @local_type
end

#nameString?

Returns full name (e.g. “LF P 81 CHERBOURG”)

Returns:

  • (String, nil)

    full name (e.g. “LF P 81 CHERBOURG”)


78
79
80
# File 'lib/aixm/feature/airspace.rb', line 78

def name
  @name
end

#typeSymbol

Returns type of airspace (see TYPES)

Returns:

  • (Symbol)

    type of airspace (see TYPES)


72
73
74
# File 'lib/aixm/feature/airspace.rb', line 72

def type
  @type
end

Instance Method Details

#inspectString

Returns:

  • (String)

95
96
97
# File 'lib/aixm/feature/airspace.rb', line 95

def inspect
  %Q(#<#{self.class} type=#{type.inspect} name=#{name.inspect}>)
end

#to_uid(as: :AseUid) ⇒ String

Returns UID markup

Returns:

  • (String)

    UID markup


119
120
121
122
123
124
125
# File 'lib/aixm/feature/airspace.rb', line 119

def to_uid(as: :AseUid)
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.tag!(as) do |tag|
    tag.codeType(TYPES.key(type).to_s)
    tag.codeId(id)
  end
end

#to_xmlString

Returns AIXM or OFMX markup

Returns:

  • (String)

    AIXM or OFMX markup

Raises:


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/aixm/feature/airspace.rb', line 130

def to_xml
  fail(LayerError.new("no layers defined", self)) unless layers.any?
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.comment! "Airspace: [#{TYPES.key(type)}] #{name || :UNNAMED}"
  builder.Ase({
    source: (source if AIXM.ofmx?)
  }.compact) do |ase|
    ase << to_uid.indent(2)
    ase.txtLocalType(local_type) if local_type && local_type != name
    ase.txtName(name) if name
    unless layered?
      ase << layers.first.to_xml.indent(2)
    end
  end
  builder.Abd do |abd|
    abd.AbdUid do |abd_uid|
      abd_uid << to_uid.indent(4)
    end
    abd << geometry.to_xml.indent(2)
  end
  if layered?
    layers.each.with_index do |layer, index|
      layer_airspace = AIXM.airspace(type: 'CLASS', name: "#{name} LAYER #{index + 1}")
      builder.Ase do |ase|
        ase << layer_airspace.to_uid.indent(2)
        ase.txtName(layer_airspace.name)
        ase << layers[index].to_xml.indent(2)
      end
      builder.Adg do |adg|
        adg.AdgUid do |adg_uid|
          adg_uid << layer_airspace.to_uid.indent(4)
        end
        adg << to_uid(as: :AseUidSameExtent).indent(2)
      end
    end
  end
  builder.target!
end