PostGIS – How to Calculate the Azimuth of a Line of a MultiLineString in PostGIS

distancelinestringmap-matchingpostgis

I have two spatially enabled tables in PostgreSQL with a geometry in each:
First table is with POINT type, second is with MULTILINESTRING.

I need to calculate the azimuth of the LINESTRING part of a MULTILINESTRING, which is closest to the POINT.

So the question is: how do I extract the LINESTRING in question, and compute the azimuth?

Best Answer

Am I misunderstanding? Isn't this just:

SELECT
   ST_Asimuth(p.geom, ST_ClosestPoint(l.geom,p.geom)) AS azimuth
FROM line l, point p

If you have more than one item in the line and point tables, the question of what condition you join them on becomes important, but as you described it, it's just one item in each.