Class: AIXM::Feature::Airspace

Inherits:
AIXM::Feature show all
Includes:
Association, Memoize
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
  region: String or nil
  id: String or nil   # nil is converted to an 8 character digest
  type: String or Symbol
  local_type: String or nil
  name: String or nil
)
airspace.add_layer(AIXM.layer)
airspace.geometry.add_segment(AIXM.point or AIXM.arc or AIXM.border or AIXM.circle)

The id is mandatory, however, you may omit it when initializing a new airspace or assign nil to an existing airspace which will generate a 8 character digest from type, local_type and name.

Some regions define additional airspace types. In LF (France) for intance, the types RMZ (radio mandatory zone) and TMZ (transponder mandatory zone) exist. Such airspaces are usually specified together with a generic type such as :regulated_airspace:

airspace= AIXM.airspace(type: :regulated_airspace, local_type: "RMZ")

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

Constants inherited from AIXM::Feature

REGION_RE

Instance Attribute Summary collapse

Attributes inherited from AIXM::Feature

#region, #source

Instance Method Summary collapse

Methods included from Memoize

cache, included, method

Methods included from Association

included

Methods inherited from AIXM::Feature

#==

Constructor Details

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

Returns a new instance of Airspace.


109
110
111
112
113
114
# File 'lib/aixm/feature/airspace.rb', line 109

def initialize(source: nil, region: nil, id: nil, type:, local_type: nil, name: nil)
  super(source: source, region: region)
  self.type, self.local_type, self.name = type, local_type, name
  self.id = id
  self.geometry = AIXM.geometry
end

Instance Attribute Details

#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”)


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

def id
  @id
end

#local_typeString?

Some regions define additional types. They are usually specified with

Returns:

  • (String, nil)

    local type (e.g. “RMZ” or “TMZ”)


104
105
106
# File 'lib/aixm/feature/airspace.rb', line 104

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”)


107
108
109
# File 'lib/aixm/feature/airspace.rb', line 107

def name
  @name
end

#typeSymbol

Returns type of airspace (see TYPES).

Returns:

  • (Symbol)

    type of airspace (see TYPES)


99
100
101
# File 'lib/aixm/feature/airspace.rb', line 99

def type
  @type
end

Instance Method Details

#add_layer(layer) ⇒ Object

Parameters:

  • layer (AIXM::Compoment::Layer)

91
# File 'lib/aixm/feature/airspace.rb', line 91

has_many :layers

#geometryAIXM::Component::Geometry

Returns horizontal geometry shape.

Returns:


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

has_one :geometry

#geometry=(geometry) ⇒ Object

Parameters:


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

has_one :geometry

#inspectString

Returns:

  • (String)

117
118
119
# File 'lib/aixm/feature/airspace.rb', line 117

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

#layersArray<AIXM::Compoment::Layer>

Returns vertical layers.

Returns:

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

    vertical layers


91
# File 'lib/aixm/feature/airspace.rb', line 91

has_many :layers

#to_uid(as: :AseUid) ⇒ String

Returns UID markup.

Returns:

  • (String)

    UID markup


143
144
145
146
147
148
149
# File 'lib/aixm/feature/airspace.rb', line 143

def to_uid(as: :AseUid)
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.tag!(as, ({ region: (region if AIXM.ofmx?) }.compact)) do |tag|
    tag.codeType(TYPES.key(type).to_s)
    tag.codeId(id)
  end
end

#to_wrapped_uid(as: :AseUid, with:) ⇒ String

Returns UID markup.

Returns:

  • (String)

    UID markup


153
154
155
156
157
158
# File 'lib/aixm/feature/airspace.rb', line 153

def to_wrapped_uid(as: :AseUid, with:)
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.tag!(with) do |tag|
    tag << to_uid(as: as).indent(2)
  end
end

#to_xmlString

Returns AIXM or OFMX markup.

Returns:

  • (String)

    AIXM or OFMX markup

Raises:


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/aixm/feature/airspace.rb', line 163

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 << to_wrapped_uid(with: :AbdUid).indent(2)
    abd << geometry.to_xml.indent(2)
  end
  if layered?
    layers.each.with_index do |layer, index|
      layer_airspace = AIXM.airspace(region: region, 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 << layer_airspace.to_wrapped_uid(with: :AdgUid).indent(2)
        adg << to_uid(as: :AseUidSameExtent).indent(2)
      end
      layer.services.each do |service|
        builder.Sae do |sae|
          sae.SaeUid do |sae_uid|
            sae_uid << service.to_uid.indent(4)
            sae_uid << layer_airspace.to_uid.indent(4)
          end
        end
      end
    end
  else
    layers.first.services.each do |service|
      builder.Sae do |sae|
        sae.SaeUid do |sae_uid|
          sae_uid << service.to_uid.indent(4)
          sae_uid << to_uid.indent(4)
        end
      end
    end
  end
  builder.target!
end