class AIXM::Document

The AIXM-Snapshot or OFMX-Snapshot document is the root container for aeronautical information such as airports or airspaces.

Cheat Sheet in Pseudo Code:

document = AIXM.document(
  namespace: String (UUID)
  created_at: Time or Date or String
  effective_at: Time or Date or String
)
document.add_feature(AIXM::Feature)

@see gitlab.com/openflightmaps/ofmx/wikis/Snapshot

Constants

NAMESPACE_RE

Attributes

created_at[R]

@return [Time] creation date and time (default: {#effective_at} or now)

effective_at[R]

@return [Time] effective after date and time (default: {#created_at} or now)

namespace[R]

@return [String] UUID to namespace the data contained in this document

Public Class Methods

new(namespace: nil, created_at: nil, effective_at: nil) click to toggle source
   # File lib/aixm/document.rb
39 def initialize(namespace: nil, created_at: nil, effective_at: nil)
40   self.namespace, self.created_at, self.effective_at = namespace, created_at, effective_at
41 end

Public Instance Methods

created_at=(value) click to toggle source
   # File lib/aixm/document.rb
53 def created_at=(value)
54   @created_at = value&.to_time || effective_at || Time.now
55 end
effective_at=(value) click to toggle source
   # File lib/aixm/document.rb
57 def effective_at=(value)
58   @effective_at = value&.to_time || created_at || Time.now
59 end
errors() click to toggle source

Validate the generated AIXM or OFMX atainst it's XSD and return the errors found.

@return [Array<String>] validation errors

    # File lib/aixm/document.rb
 95 def errors
 96   xsd = Nokogiri::XML::Schema(File.open(AIXM.schema(:xsd)))
 97   xsd.validate(Nokogiri::XML(to_xml)).reject do |error|
 98     AIXM.config.ignored_errors && error.message.match?(AIXM.config.ignored_errors)
 99   end
100 end
group_obstacles!(max_distance: AIXM.d(1, :nm)) click to toggle source

Compare all ungrouped obstacles and create new obstacle groups whose members are located within max_distance pairwise.

@param max_distance [AIXM::D] max distance between obstacle group member

pairs (default: 1 NM)

@return [Integer] number of obstacle groups added

   # File lib/aixm/document.rb
67 def group_obstacles!(max_distance: AIXM.d(1, :nm))
68   obstacles, list = features.find_by(:obstacle), {}
69   while subject = obstacles.send(:shift)
70     obstacles.each do |obstacle|
71       if subject.xy.distance(obstacle.xy) <= max_distance
72         [subject, obstacle].each { list[_1] = list[subject] || SecureRandom.uuid }
73       end
74     end
75   end
76   list.group_by(&:last).each do |_, grouped_list|
77     first_obstacle = grouped_list.first.first
78     obstacle_group = AIXM.obstacle_group(source: first_obstacle.source, region: first_obstacle.region)
79     grouped_list.each { |o, _| obstacle_group.add_obstacle features.send(:delete, o) }
80     add_feature obstacle_group
81   end.count
82 end
inspect() click to toggle source

@return [String]

   # File lib/aixm/document.rb
44 def inspect
45   %Q(#<#{self.class} created_at=#{created_at.inspect}>)
46 end
namespace=(value) click to toggle source
   # File lib/aixm/document.rb
48 def namespace=(value)
49   fail(ArgumentError, "invalid namespace") unless value.nil? || value.match?(NAMESPACE_RE)
50   @namespace = value || SecureRandom.uuid
51 end
to_xml() click to toggle source

@return [String] AIXM or OFMX markup

    # File lib/aixm/document.rb
103 def to_xml
104   meta = {
105     'xmlns:xsi': AIXM.schema(:namespace),
106     version: AIXM.schema(:version),
107     origin: "rubygem aixm-#{AIXM::VERSION}",
108     namespace: (namespace if AIXM.ofmx?),
109     created: @created_at.xmlschema,
110     effective: @effective_at.xmlschema
111   }.compact
112   builder = Builder::XmlMarkup.new(indent: 2)
113   builder.instruct!
114   builder.tag!(AIXM.schema(:root), meta) do |root|
115     AIXM::Memoize.method :to_uid do
116       root << features.map { _1.to_xml }.join.indent(2)
117     end
118   end
119   if AIXM.ofmx? && AIXM.config.mid
120     AIXM::PayloadHash::Mid.new(builder.target!).insert_mid.to_xml
121   else
122     builder.target!
123   end
124 end
valid?() click to toggle source

Validate the generated AIXM or OFMX atainst it's XSD.

@return [Boolean] whether valid or not

   # File lib/aixm/document.rb
87 def valid?
88   errors.none?
89 end