Class: AIXM::Feature::ObstacleGroup

Inherits:
AIXM::Feature show all
Includes:
Association, Memoize
Defined in:
lib/aixm/feature/obstacle_group.rb

Overview

Groups of obstacles which consist of either linked (e.g. power line towers) or unlinked (e.g. wind turbines) members.

Obstacle group should contain at least two obstacles. However, if the details of each obstacle of the group are unknown, you may add only one virtual obstacle to the group and mention the number of real obstacles in it's remarks.

Cheat Sheet in Pseudo Code:

obstacle_group = AIXM.obstacle_group(
  source: String or nil        # see remarks below
  region: String or nil
  name: String or nil
).tap do |obstacle_group|
  obstacle_group.xy_accuracy = AIXM.d or nil
  obstacle_group.z_accuracy = AIXM.d or nil
  obstacle_group.remarks = String or nil
end
obstacle_group.add_obstacle(   # add an obstacle to the group
  AIXM.obstacle
)
obstacle_group.add_obstacle(   # add an obstacle to the group and link
  AIXM.obstacle,               # it to the obstacle last added to the group
  linked_to: :previous,
  link_type: LINK_TYPES
)
obstacle_group.add_obstacle(   # add an obstacle to the group and link
  AIXM.obstacle,               # it to any obstacle already in the group
  linked_to: AIXM.obstacle,
  link_type: LINK_TYPES
)

Please note: Accuracies (xy_accuracy and z_accuracy) set on an obstacle group are implicitly applied to all obstacles of the group unless they have their own, different accuracies set.

Constant Summary

Constants inherited from AIXM::Feature

REGION_RE

Instance Attribute Summary collapse

Attributes inherited from AIXM::Feature

#region

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, name: nil) ⇒ ObstacleGroup

Returns a new instance of ObstacleGroup.


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

def initialize(source: nil, region: nil, name: nil)
  super(source: source, region: region)
  self.name = name
end

Instance Attribute Details

#remarksString?

Returns free text remarks.

Returns:

  • (String, nil)

    free text remarks


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

def remarks
  @remarks
end

Instance Method Details

#add_obstacle(obstacle, linked_to: nil, link_type: nil) ⇒ self

Parameters:

Returns:

  • (self)

59
60
61
62
63
64
# File 'lib/aixm/feature/obstacle_group.rb', line 59

has_many :obstacles do |obstacle, linked_to: nil, link_type: nil|
  if linked_to
    obstacle.send(:linked_to=, linked_to == :previous ? @obstacles.last : linked_to)
    obstacle.send(:link_type=, (link_type || :other))
  end
end

#inspectString

Returns:

  • (String)

89
90
91
# File 'lib/aixm/feature/obstacle_group.rb', line 89

def inspect
  %Q(#<#{self.class} #{@obstacles.count} obstacle(s)>)
end

#nameString

Returns obstacle group name.

Returns:

  • (String)

    obstacle group name


74
75
76
77
78
# File 'lib/aixm/feature/obstacle_group.rb', line 74

%i(source name xy_accuracy z_accuracy).each do |method|
  define_method method do
    instance_variable_get(:"@#{method}") || obstacles.first&.send(method)
  end
end

#name=(value) ⇒ Object


93
94
95
96
# File 'lib/aixm/feature/obstacle_group.rb', line 93

def name=(value)
  fail(ArgumentError, "invalid name") unless value.nil? || value.is_a?(String)
  @name = value&.uptrans
end

#obstaclesArray<AIXM::Feature::Obstacle>

Returns obstacles in this obstacle group.

Returns:


59
60
61
62
63
64
# File 'lib/aixm/feature/obstacle_group.rb', line 59

has_many :obstacles do |obstacle, linked_to: nil, link_type: nil|
  if linked_to
    obstacle.send(:linked_to=, linked_to == :previous ? @obstacles.last : linked_to)
    obstacle.send(:link_type=, (link_type || :other))
  end
end

#sourceString

Returns reference to source of the feature data.

Returns:

  • (String)

    reference to source of the feature data


74
75
76
77
78
# File 'lib/aixm/feature/obstacle_group.rb', line 74

%i(source name xy_accuracy z_accuracy).each do |method|
  define_method method do
    instance_variable_get(:"@#{method}") || obstacles.first&.send(method)
  end
end

#to_uidString

Returns UID markup.

Returns:

  • (String)

    UID markup


113
114
115
116
117
118
119
# File 'lib/aixm/feature/obstacle_group.rb', line 113

def to_uid
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.OgrUid({ region: (region if AIXM.ofmx?) }.compact) do |ogr_uid|
    ogr_uid.geoLat(obstacles.first.xy.lat(AIXM.schema))
    ogr_uid.geoLong(obstacles.first.xy.long(AIXM.schema))
  end
end

#to_xmlString

Returns AIXM or OFMX markup.

Returns:

  • (String)

    AIXM or OFMX markup


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/aixm/feature/obstacle_group.rb', line 123

def to_xml
  builder = Builder::XmlMarkup.new(indent: 2)
  if AIXM.ofmx?
    builder.comment! "Obstacle group: #{name}".strip
    builder.Ogr({ source: (source if AIXM.ofmx?) }.compact) do |ogr|
      ogr << to_uid.indent(2)
      ogr.txtName(name)
      ogr.codeDatum('WGE')
      if xy_accuracy
        ogr.valGeoAccuracy(xy_accuracy.dist.trim)
        ogr.uomGeoAccuracy(xy_accuracy.unit.upcase.to_s)
      end
      if z_accuracy
        ogr.valElevAccuracy(z_accuracy.to_ft.dist.round)
        ogr.uomElevAccuracy('FT')
      end
      ogr.txtRmk(remarks) if remarks
    end
  end
  obstacles.each { builder << _1.to_xml(delegate: false) }
  builder.target!
end

#xy_accuracyAIXM::D?

Returns margin of error for circular base center point.

Returns:

  • (AIXM::D, nil)

    margin of error for circular base center point


74
75
76
77
78
# File 'lib/aixm/feature/obstacle_group.rb', line 74

%i(source name xy_accuracy z_accuracy).each do |method|
  define_method method do
    instance_variable_get(:"@#{method}") || obstacles.first&.send(method)
  end
end

#xy_accuracy=(value) ⇒ Object


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

def xy_accuracy=(value)
  fail(ArgumentError, "invalid xy accuracy") unless value.nil? || value.is_a?(AIXM::D)
  @xy_accuracy = value
end

#z_accuracyAIXM::D?

Returns margin of error for top point.

Returns:

  • (AIXM::D, nil)

    margin of error for top point


74
75
76
77
78
# File 'lib/aixm/feature/obstacle_group.rb', line 74

%i(source name xy_accuracy z_accuracy).each do |method|
  define_method method do
    instance_variable_get(:"@#{method}") || obstacles.first&.send(method)
  end
end

#z_accuracy=(value) ⇒ Object


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

def z_accuracy=(value)
  fail(ArgumentError, "invalid z accuracy") unless value.nil? || value.is_a?(AIXM::D)
  @z_accuracy = value
end