Advanced: 02 Set coverage zone geometry.sql

File 02 Set coverage zone geometry.sql, 897 bytes (added by 231139, 10 days ago)
Line 
1CREATE OR REPLACE FUNCTION public.set_coverage_zone_geometry()
2RETURNS trigger
3LANGUAGE plpgsql
4AS $$
5DECLARE
6 site_location geometry(Point, 4326);
7 sector_azimuth integer;
8 sector_beamwidth integer;
9BEGIN
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;
31END;
32$$;