Class: AIXM::Feature::Obstacle

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

Overview

Obstacles are individual objects described as cylindrical volume with circular base and height.

Cheat Sheet in Pseudo Code:

obstacle = AIXM.obstacle(
  source: String or nil
  name: String or nil
  type: TYPES
  xy: AIXM.xy
  z: AIXM.z
  radius: AIXM.d
)
obstacle.lighting = true or false (default for AIXM) or nil (means: unknown, default for OFMX)
obstacle.lighting_remarks = String or nil
obstacle.marking = true or false or nil (means: unknown, default)
obstacle.marking_remarks = String or nil
obstacle.height = AIXM.d or nil
obstacle.height_accurate = true or false or nil (means: unknown, default)
obstacle.xy_accuracy = AIXM.d or nil
obstacle.z_accuracy = AIXM.d or nil
obstacle.valid_from = Time or Date or String or nil
obstacle.valid_until = Time or Date or String or nil
obstacle.remarks = String or nil
obstacle.link_to   # => AIXM.obstacle or nil
obstacle.link_type   # => LINK_TYPE or nil

See ObstacleGroup for how to define physical links between two obstacles (e.g. cables between powerline towers).

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!

Constant Summary collapse

TYPES =
{
  ANTENNA: :antenna,
  BUILDING: :building,
  CHIMNEY: :chimney,
  CRANE: :crane,
  MAST: :mast,
  TOWER: :tower,
  WINDTURBINE: :wind_turbine,
  OTHER: :other   # specify in remarks
}.freeze
{
  CABLE: :cable,
  SOLID: :solid,
  OTHER: :other
}.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, name: nil, type:, xy:, z:, radius:) ⇒ Obstacle


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

def initialize(source: nil, name: nil, type:, xy:, z:, radius:)
  super(source: source)
  self.name, self.type, self.xy, self.z, self.radius = name, type, xy, z, radius
  @lighting = @marking = @height_accurate = false
end

Instance Attribute Details

#heightAIXM::D?


90
91
92
# File 'lib/aixm/feature/obstacle.rb', line 90

def height
  @height
end

#height_accurateBoolean?


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

def height_accurate
  @height_accurate
end

#lightingBoolean?


77
78
79
# File 'lib/aixm/feature/obstacle.rb', line 77

def lighting
  @lighting
end

#lighting_remarksString?


80
81
82
# File 'lib/aixm/feature/obstacle.rb', line 80

def lighting_remarks
  @lighting_remarks
end

118
119
120
# File 'lib/aixm/feature/obstacle.rb', line 118

def link_type
  @link_type
end

#linked_toSymbol?


115
116
117
# File 'lib/aixm/feature/obstacle.rb', line 115

def linked_to
  @linked_to
end

#markingBoolean?


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

def marking
  @marking
end

#marking_remarksString?


87
88
89
# File 'lib/aixm/feature/obstacle.rb', line 87

def marking_remarks
  @marking_remarks
end

#nameString


61
62
63
# File 'lib/aixm/feature/obstacle.rb', line 61

def name
  @name
end

#obstacle_groupAIXM::Feature::ObstacleGroup


112
113
114
# File 'lib/aixm/feature/obstacle.rb', line 112

def obstacle_group
  @obstacle_group
end

#radiusAIXM::D


70
71
72
# File 'lib/aixm/feature/obstacle.rb', line 70

def radius
  @radius
end

#remarksString?


109
110
111
# File 'lib/aixm/feature/obstacle.rb', line 109

def remarks
  @remarks
end

#typeSymbol


64
65
66
# File 'lib/aixm/feature/obstacle.rb', line 64

def type
  @type
end

#valid_fromTime, ...


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

def valid_from
  @valid_from
end

#valid_untilTime, ...


106
107
108
# File 'lib/aixm/feature/obstacle.rb', line 106

def valid_until
  @valid_until
end

#xyAIXM::XY


67
68
69
# File 'lib/aixm/feature/obstacle.rb', line 67

def xy
  @xy
end

#xy_accuracyAIXM::D?


97
98
99
# File 'lib/aixm/feature/obstacle.rb', line 97

def xy_accuracy
  @xy_accuracy
end

#zAIXM::Z


73
74
75
# File 'lib/aixm/feature/obstacle.rb', line 73

def z
  @z
end

#z_accuracyAIXM::D?


100
101
102
# File 'lib/aixm/feature/obstacle.rb', line 100

def z_accuracy
  @z_accuracy
end

Instance Method Details

#grouped?Boolean


223
224
225
# File 'lib/aixm/feature/obstacle.rb', line 223

def grouped?
  obstacle_group && obstacle_group.obstacles.count > 1
end

#inspectString


127
128
129
# File 'lib/aixm/feature/obstacle.rb', line 127

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

#linked?Boolean


228
229
230
# File 'lib/aixm/feature/obstacle.rb', line 228

def linked?
  !!linked_to
end

#to_uid(as: :ObsUid) ⇒ String


233
234
235
236
237
238
239
240
241
# File 'lib/aixm/feature/obstacle.rb', line 233

def to_uid(as: :ObsUid)
  self.obstacle_group ||= singleton_obstacle_group
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.tag!(as) do |tag|
    tag << obstacle_group.to_uid.indent(2) if AIXM.ofmx?
    tag.geoLat((xy.lat(AIXM.schema)))
    tag.geoLong((xy.long(AIXM.schema)))
  end.insert_payload_hash(region: AIXM.config.mid_region)
end

#to_xml(delegate: true) ⇒ String


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/aixm/feature/obstacle.rb', line 244

def to_xml(delegate: true)
  self.obstacle_group ||= singleton_obstacle_group
  return obstacle_group.to_xml if delegate && AIXM.ofmx?
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.comment! "Obstacle: [#{type}] #{xy.to_s} #{name}".strip
  builder.Obs do |obs|
    obs << to_uid.indent(2)
    obs.txtName(name) if name
    if AIXM.ofmx?
      obs.codeType(TYPES.key(type).to_s)
    else
      obs.txtDescrType(TYPES.key(type).to_s)
    end
    obs.codeGroup(grouped? ? 'Y' : 'N')
    if AIXM.ofmx?
      obs.codeLgt(lighting ? 'Y' : 'N') unless lighting.nil?
      obs.codeMarking(marking ? 'Y' : 'N') unless marking.nil?
    else
      obs.codeLgt(lighting ? 'Y' : 'N')
    end
    obs.txtDescrLgt(lighting_remarks) if lighting_remarks
    obs.txtDescrMarking(marking_remarks) if marking_remarks
    obs.codeDatum('WGE')
    if AIXM.aixm? && obstacle_group.xy_accuracy
      obs.valGeoAccuracy(obstacle_group.xy_accuracy.dist.trim)
      obs.uomGeoAccuracy(obstacle_group.xy_accuracy.unit.upcase.to_s)
    end
    obs.valElev(z.alt)
    if AIXM.aixm? && obstacle_group.z_accuracy
      obs.valElevAccuracy(obstacle_group.z_accuracy.to_ft.dist.round)
    end
    obs.valHgt(height.to_ft.dist.round) if height
    obs.uomDistVer('FT')
    if AIXM.ofmx? && !height_accurate.nil?
      obs.codeHgtAccuracy(height_accurate ? 'Y' : 'N')
    end
    if AIXM.ofmx?
      if radius
        obs.valRadius(radius.dist.trim)
        obs.uomRadius(radius.unit.upcase.to_s)
      end
      if grouped? && linked?
        obs << linked_to.to_uid(as: :ObsUidLink).indent(2)
        obs.codeLinkType(LINK_TYPES.key(link_type).to_s)
      end
      obs.datetimeValidWef(valid_from.xmlschema) if valid_from
      obs.datetimeValidTil(valid_until.xmlschema) if valid_until
    end
    obs.txtRmk(remarks) if remarks
  end
end