# Postgis ST_Azimuth only returning a small range of angles

I have a puzzler with postgis and ST_Azimuth.

I have a table of points (taken from country borders, and run through the QChainage plugin). I want to find the azimuth from a fixed point (15.0,50.0) to each chainage point.

What I want to do is this;

• create a circle centred on NULL island (0,0)
• points form a circle of radius one degree
• angles corresponding to azimuth.

Running this query gives me what I expect; angles are between 0 and 2*PI (with some outliers above this). I translate points so the center is moved to (0,0)

``````select
st_azimuth(
st_setsrid(
st_makepoint(0,0),
4326
)
,
ST_translate(geom,ST_x(geom)-15.0,ST_y(geom)-50.0)
) as azimuth

from
qqq3lines
order by azimuth asc
``````

To do this, I created a unit vector - a line from (0,0) to (0,1), and rotate it by the azimuth, then take the end point.

``````select
st_asewkt(
st_endpoint(
st_rotate(
-- unit vector, facing north
st_makeline(
st_setsrid(st_makepoint(0,0),4326),
st_setsrid(st_makepoint(0,1),4326)
),
-- rotate by azimuth between central point and this point
st_azimuth(
st_setsrid(
st_makepoint(0,0),
4326
)
,
ST_translate(geom,ST_x(geom)-15.0,ST_y(geom)-50.0)
)
)
)
) as pt

from
qqq3lines
``````

But when I plot this in QGIS, I only seem to get a 'fan', a limited range of angles. I was expecting a more complete circle. The same things happen if I try to do this with custom QGIS python function in the field calculator, using the QGSPoint.azimuth(QGSPoint) method.

What am I doing wrong?

• Did you double check the first query's results? I suspect you want ST_Translate(geom, -15.0, -50.0) without ST_X() and ST_Y(). – Redoute Aug 18 '15 at 20:00