Class: AIXM::Feature::ObstacleGroup
- Inherits:
-
AIXM::Feature
- Object
- AIXM::Feature
- AIXM::Feature::ObstacleGroup
- 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.
Cheat Sheet in Pseudo Code:
obstacle_group = AIXM.obstacle_group(
source: String or nil # see remarks below
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: As soon as an obstacle is added to an obstacle group, the xy_accuracy and z_accuracy of the obstacle group overwrite whatever is set on the individual obstacles!
Instance Attribute Summary collapse
-
#obstacles ⇒ Array<AIXM::Feature::Obstacle>
readonly
Obstacles in this obstacle group.
-
#remarks ⇒ String?
Free text remarks.
Instance Method Summary collapse
-
#add_obstacle(obstacle, linked_to: nil, link_type: :other) ⇒ self
Add an obstacle to the obstacle group and optionally link it to another obstacle from the obstacle group.
-
#initialize(source: nil, name: nil) ⇒ ObstacleGroup
constructor
A new instance of ObstacleGroup.
- #inspect ⇒ String
-
#name ⇒ String
Obstacle group name.
- #name=(value) ⇒ Object
-
#source ⇒ String
Reference to source of the feature data.
-
#to_uid ⇒ String
UID markup.
-
#to_xml ⇒ String
AIXM or OFMX markup.
-
#xy_accuracy ⇒ AIXM::D?
Margin of error for circular base center point.
- #xy_accuracy=(value) ⇒ Object
-
#z_accuracy ⇒ AIXM::D?
Margin of error for top point.
- #z_accuracy=(value) ⇒ Object
Methods inherited from AIXM::Feature
Constructor Details
#initialize(source: nil, name: nil) ⇒ ObstacleGroup
Returns a new instance of ObstacleGroup.
60 61 62 63 64 |
# File 'lib/aixm/feature/obstacle_group.rb', line 60 def initialize(source: nil, name: nil) super(source: source) self.name = name @obstacles = [] end |
Instance Attribute Details
#obstacles ⇒ Array<AIXM::Feature::Obstacle> (readonly)
Returns obstacles in this obstacle group.
58 59 60 |
# File 'lib/aixm/feature/obstacle_group.rb', line 58 def obstacles @obstacles end |
#remarks ⇒ String?
Returns free text remarks.
55 56 57 |
# File 'lib/aixm/feature/obstacle_group.rb', line 55 def remarks @remarks end |
Instance Method Details
#add_obstacle(obstacle, linked_to: nil, link_type: :other) ⇒ self
Add an obstacle to the obstacle group and optionally link it to another obstacle from the obstacle group.
100 101 102 103 104 105 106 107 108 |
# File 'lib/aixm/feature/obstacle_group.rb', line 100 def add_obstacle(obstacle, linked_to: nil, link_type: :other) obstacle.send(:obstacle_group=, self) if linked_to && link_type obstacle.send(:linked_to=, linked_to == :previous ? @obstacles.last : linked_to) obstacle.send(:link_type=, link_type) end @obstacles << obstacle self end |
#inspect ⇒ String
67 68 69 |
# File 'lib/aixm/feature/obstacle_group.rb', line 67 def inspect %Q(#<#{self.class} #{@obstacles.count} obstacle(s)>) end |
#name ⇒ String
Returns obstacle group name.
48 49 50 51 52 |
# File 'lib/aixm/feature/obstacle_group.rb', line 48 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
71 72 73 74 |
# File 'lib/aixm/feature/obstacle_group.rb', line 71 def name=(value) fail(ArgumentError, "invalid name") unless value.nil? || value.is_a?(String) @name = value&.uptrans end |
#source ⇒ String
Returns reference to source of the feature data.
48 49 50 51 52 |
# File 'lib/aixm/feature/obstacle_group.rb', line 48 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_uid ⇒ String
Returns UID markup.
111 112 113 114 115 116 117 118 |
# File 'lib/aixm/feature/obstacle_group.rb', line 111 def to_uid builder = Builder::XmlMarkup.new(indent: 2) builder.OgrUid do |ogr_uid| ogr_uid.txtName(name) ogr_uid.geoLat(obstacles.first.xy.lat(AIXM.schema)) ogr_uid.geoLong(obstacles.first.xy.long(AIXM.schema)) end end |
#to_xml ⇒ String
Returns AIXM or OFMX markup.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/aixm/feature/obstacle_group.rb', line 121 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.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 { |o| builder << o.to_xml(delegate: false) } builder.target! end |
#xy_accuracy ⇒ AIXM::D?
Returns margin of error for circular base center point.
48 49 50 51 52 |
# File 'lib/aixm/feature/obstacle_group.rb', line 48 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
76 77 78 79 |
# File 'lib/aixm/feature/obstacle_group.rb', line 76 def xy_accuracy=(value) fail(ArgumentError, "invalid xy accuracy") unless value.nil? || value.is_a?(AIXM::D) @xy_accuracy = value end |
#z_accuracy ⇒ AIXM::D?
Returns margin of error for top point.
48 49 50 51 52 |
# File 'lib/aixm/feature/obstacle_group.rb', line 48 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
81 82 83 84 |
# File 'lib/aixm/feature/obstacle_group.rb', line 81 def z_accuracy=(value) fail(ArgumentError, "invalid z accuracy") unless value.nil? || value.is_a?(AIXM::D) @z_accuracy = value end |