| 1 | CREATE OR REPLACE FUNCTION public.set_coverage_zone_geometry()
|
|---|
| 2 | RETURNS trigger
|
|---|
| 3 | LANGUAGE plpgsql
|
|---|
| 4 | AS $$
|
|---|
| 5 | DECLARE
|
|---|
| 6 | site_location geometry(Point, 4326);
|
|---|
| 7 | sector_azimuth integer;
|
|---|
| 8 | sector_beamwidth integer;
|
|---|
| 9 | BEGIN
|
|---|
| 10 | SELECT ns.location, ts.azimuth, ts.beamwidth
|
|---|
| 11 | INTO site_location, sector_azimuth, sector_beamwidth
|
|---|
| 12 | FROM public.tower_sectors ts
|
|---|
| 13 | JOIN public.cell_towers ct ON ct.tower_id = ts.tower_id
|
|---|
| 14 | JOIN public.network_sites ns ON ns.site_id = ct.site_id
|
|---|
| 15 | WHERE ts.sector_id = NEW.sector_id;
|
|---|
| 16 |
|
|---|
| 17 | IF site_location IS NULL
|
|---|
| 18 | OR sector_azimuth IS NULL
|
|---|
| 19 | OR sector_beamwidth IS NULL THEN
|
|---|
| 20 | NEW.coverage_area := NULL;
|
|---|
| 21 | ELSE
|
|---|
| 22 | NEW.coverage_area := public.build_sector_coverage(
|
|---|
| 23 | site_location,
|
|---|
| 24 | sector_azimuth,
|
|---|
| 25 | sector_beamwidth,
|
|---|
| 26 | NEW.coverage_radius_m
|
|---|
| 27 | );
|
|---|
| 28 | END IF;
|
|---|
| 29 |
|
|---|
| 30 | RETURN NEW;
|
|---|
| 31 | END;
|
|---|
| 32 | $$;
|
|---|