I have a dataset with cell tower information, as you can see below. The lat and lon fields are the location of the tower.
The objective is to get the area (geometry) of the sector the cell tower covers, from start_angle to end_angle. As you can see in the next image, using the first row of the dataset as example, I can obtain the lines from start_angle 275 and end_angle 35, but I want the rest of the buffer to disappear.
Query used:
This first query is used to create and rotate the lines from start_angle and end_angle and also a line with 0 degrees.
WITH vertices AS
(SELECT
id,
start_angle,
end_angle,
(ST_DumpPoints(geom)).path[1] AS v_id,
(ST_DumpPoints(geom)).geom AS vertex
FROM celulas
), teste as
(SELECT
id,
v_id,
ST_SetSRID(ST_Translate(ST_Rotate(ST_MakeLine(ST_MakePoint( 1.0,0.0),
ST_MakePoint(-1.0,0.0)),
radians(start_angle * -1)), ST_X(vertex), ST_Y(Vertex)),
ST_SRID(vertex)) AS startline,
ST_SetSRID(ST_Translate(ST_Rotate(ST_MakeLine(ST_MakePoint( 1.0,0.0),
ST_MakePoint(-1.0,0.0)),
radians(end_angle * -1)), ST_X(vertex), ST_Y(Vertex)),
ST_SRID(vertex)) AS endline,
ST_SetSRID(ST_Translate(ST_Rotate(ST_MakeLine(ST_MakePoint( 1.0,0.0),
ST_MakePoint(-1.0,0.0)),
radians(0)), ST_X(vertex), ST_Y(Vertex)),
ST_SRID(vertex)) AS midline
FROM vertices
)
I also used the next query to union all geometries: the radius buffer and the lines
select St_intersection(st_split(buffer, midline), st_split(buffer, angulo))
from angulo