Use ST_Azimuth
to get the angle from the origin point to the point of interest. I've used simple geometry
points here since you didn't have any sample data, but you're probably working with geography
. The principle is the same:
WITH points(star) AS (VALUES
(point(0.5, 1)),
(point(0.2,0.2)),
(point(0.2, 1)),
(point(0.8, 0.2))
)
SELECT star
FROM points
WHERE degrees(ST_Azimuth( point(0,0)::geometry, star::geometry ))
BETWEEN 0 AND 40;
star
---------
(0.5,1)
(0.2,1)
(2 rows)
You can also limit distance. Here's how to get distance and azimuth from table "points"
containing a point
-typed column "star"
using ST_Distance
too:
SELECT
star,
degrees(ST_Azimuth( point(0,0)::geometry, star::geometry )) AS azimuth_deg,
ST_Distance( point(0,0)::geometry, star::geometry ) AS distance
FROM points;
You can move those into the WHERE
clause and filter on them however you like.
If possible work directly in radians, rather than converting to degrees.
If you're working with points on the earth, consider using the geography
type instead of geometry
. Both functions mentioned here support geography
.
ST_Within
; the trick will be creating that projected wedge.ST_rotate
a line around an origin point, then create an arc to close the poly. Seems roundabout; I'd expect it to be possible to start with a circle and intersect it with a poly.