Class: AIXM::L

Inherits:
Object show all
Defined in:
lib/aixm/l.rb

Overview

Geographical line with optional profile

Each line point is an OStruct which can be queried for its coordinates with ‘.xy` or its optional elevation with `.z`

Examples:

All of the below are equivalent

line = AIXM.l   # or:
line = AIXM.l(xy: AIXM.xy(...), z: AIXM.z(...))
line.add_line_point(xy: AIXM.xy(...), z: AIXM.z(...))
line.line_points.first.xy   # => AIXM::XY
line.line_points.first.z    # => AIXM::Z

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xy: nil, z: nil) ⇒ L

See the overview for examples.



22
23
24
25
# File 'lib/aixm/l.rb', line 22

def initialize(xy: nil, z: nil)
  @line_points = []
  add_line_point(xy: xy, z: z) if xy
end

Instance Attribute Details

#line_pointsArray<OStruct> (readonly)

Array of line points

Returns:

  • (Array<OStruct>)


19
20
21
# File 'lib/aixm/l.rb', line 19

def line_points
  @line_points
end

Instance Method Details

#==(other) ⇒ Object

See Also:

  • Object#==


57
58
59
# File 'lib/aixm/l.rb', line 57

def ==(other)
  self.class === other && to_s == other.to_s
end

#add_line_point(xy:, z: nil) ⇒ self

Add a line point to the line

Parameters:

  • xy (AIXM::XY)

    coordinates

  • z (AIXM::Z, nil) (defaults to: nil)

    elevation

Returns:

  • (self)


42
43
44
45
46
47
# File 'lib/aixm/l.rb', line 42

def add_line_point(xy:, z: nil)
  fail(ArgumentError, "invalid xy") unless xy.instance_of?(AIXM::XY)
  fail(ArgumentError, "invalid z") unless !z || z.instance_of?(AIXM::Z)
  line_points << OpenStruct.new(xy: xy, z: z)
  self
end

#inspectString

Returns:

  • (String)


28
29
30
# File 'lib/aixm/l.rb', line 28

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

#line?Boolean

Whether there are enough line points to define a line

Returns:

  • (Boolean)


52
53
54
# File 'lib/aixm/l.rb', line 52

def line?
  line_points.count >= 2
end

#to_sString

Returns human readable representation.

Returns:

  • (String)

    human readable representation



33
34
35
# File 'lib/aixm/l.rb', line 33

def to_s
  line_points.map { _1.to_h.values.map(&:to_s).join(' ') }.join(', ')
end