Class: AIPP::LS::SHOOT::ShootingGrounds

Inherits:
SHOOT::Parser show all
Includes:
Helpers::Base
Defined in:
lib/aipp/regions/LS/shoot/shooting_grounds.rb

Constant Summary collapse

DEFAULT_Z =

fallback if no max height is defined

AIXM.z(2000, :qfe)
SAFETY =

safety margin in meters added to max height

100

Instance Attribute Summary

Attributes inherited from Parser

#aixm

Instance Method Summary collapse

Methods included from Helpers::Base

#organisation_ls, #origin_for, #timetable_from

Methods inherited from Parser

#add, dependencies, depends_on, #find, #find_by, #given, #initialize, #inspect, #link_to, #origin_for, #read, #section

Methods included from Patcher

#attach_patches, #detach_patches, included

Methods included from Debugger

#info, #original_warn, #verbose_info, #warn, #with_debugger

Constructor Details

This class inherits a constructor from AIPP::Parser

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aipp/regions/LS/shoot/shooting_grounds.rb', line 11

def parse
  effective_date = AIPP.options.local_effective_at.strftime('%Y%m%d')
  airac_date = AIRAC::Cycle.new(aixm.effective_at).to_s('%Y-%m-%d')
  shooting_grounds = {}
  read.each_with_index do |row, line|
    type, id, date, no_shooting = row[0], row[1], row[2], (row[17] == "1")
    next unless type == 'BSZ'
    next if no_shooting || date != effective_date
    next if AIPP.options.id && AIPP.options.id != id
    # TODO: Several BSZ lines may exist for the same shooting area with
    #   different location codes (aka: partial activations). The geometries
    #   of those location codes are not currently available, we therefore
    #   have to merge the data into one record. The geometries should become
    #   available by the end of 2023 which will make it possible to map
    #   each line to one geometry and remove the merging logic.
    upper_z = row[15] ? AIXM.z(AIXM.d(row[15].to_i + SAFETY, :m).to_ft.dim.round, :qfe) : DEFAULT_Z
    (shooting_grounds[id] ||= { schedules: [], upper_z: AIXM::GROUND }).then do |s|
      s[:feature] ||= read("shooting_grounds-#{id}").fetch(:feature)
      s[:csv_line] ||= line
      s[:url] ||= row[10].blank_to_nil
      s[:details] = [s[:details], row[6].blank_to_nil].compact.join("\n")
      s[:dabs] ||= (row[16] == '1')
      s[:upper_z] = upper_z if upper_z.alt > s[:upper_z].alt
      s[:schedules] += schedules_for(row)
    end
  end
  shooting_grounds.each do |id, data|
    data in csv_line:, details:, url:, upper_z:, schedules:, dabs:, feature: { geometry: polygons, properties: { bezeichnung: name, infobezeichnung: contact, infotelefonnr: phone, infoemail: email } }
    schedules = consolidate(schedules)
    if schedules.any?
      geometries = geometries_for polygons
      indexed = geometries.count > 1
      geometries.each_with_index do |geometry, index|
        remarks = {
          details: details,
          contact: contact,
          phone: phone,
          email: email,
          bulletin: url
        }.to_remarks
        add(
          AIXM.airspace(
            source: "LS|OTHER|schiessgebiete.csv|#{airac_date}|#{csv_line}",
            region: 'LS',
            type: :dangerous_activities_area,
            name: "LS-S#{id} #{name} #{index if indexed}".strip
          ).tap do |airspace|
            airspace.add_layer layer_for(upper_z, schedules, remarks)
            airspace.geometry = geometry
            airspace.comment = "DABS: marked for publication" if dabs
          end
        )
      end
    end
  end
end