> ----------------------------- <snip> ----------------------------
>
> And Spatialite gives the cartesian answer (45 degrees) when the
> points
> are defined to be in some projected coordinate system, for example
> EPSG:3857.
>
Hi Jukka,
congratulations, you hit the mark.
I was just investigating the problem when your email arrived, and
until that moment I had come to understand two things based on my
very first checks on both Linux and Windows:
A) the result of SpatiaLite's ST_Azimuth() depends on the SRID;
sometimes they are identical to those reported for PostGIS,
but other times they are completely different.
B) even more surprisingly, the results change depending on the
connected DB.
After a more careful check on the source code, here is the
complete explanation.
1. There are two different ways to calculate the azimuth;
on the plane or on the ellipsoid.
2. Therefore the very first action of ST_Azimuth() is to
look for the geodesic parameters of the SRID defined
in the proj4text column of the spatial_ref_sys table.
3. At this point it evaluates the geodesic string to
understand whether it's a planar (projected) or
geographic type SRS, and in this second case it
also retrieves the lengths of the two axes of
the ellipsoid.
Note: if it cannot find the geodesic definition of the
SRID a planar system is assumed.
4. Finally everything is ready to calculate the azimuth
with the most appropriate method.
Drawing the final conclusions:
- In the absence of any explicit indication the default SRID=0
(Undefined - Geographic Long/Lat) will be assumed
- To get the same "planar" results as PostGIS you must be
careful to explicitly declare the SRID=-1
(Undefined - Cartesian)
- But if you use an unknown SRID, or if the DB metadata
are missing or only partial, then you still fall into
the "planar" case.
- Naturally by always using explicit SRID attributions
on a correctly initialized DB, then there will never
be any problems.
Blindly relying on the defaults, on the other hand,
can easily create great confusion. Be careful.
bye Sandro