2

difference degrees

I have two points p1 and p2.

 SELECT ST_GeomFromText('POINT(92.78488163381019 55.9757874622428)',  4326) as p1,
        ST_GeomFromText('POINT(92.78482645521103 55.97564239375992)', 4326) as p2

degree between points equal 200.824 and distance between points equal 16.492

SELECT degrees(ST_Azimuth(p1, p2)) as degree,
       ST_Distance_Sphere(p1, p2)  as distance</code></pre>

But i have different degree when i use st_Project with this arguments:

SELECT degrees(ST_Azimuth(p1, _p2)),
       ST_Distance_Sphere(p1, p2)
FROM (
  SELECT (ST_Project(p1, distance, radians(degree))::geometry as _p2 FROM ...
)

It returns:

  st_distance_sphere  ||       degrees
======================||====================
  16.4661410575154    ||  214.150581571718

Distance difference between (p1,p2) and (p1,_p2) changing only by 0.02 meter. But degree changing by 13 degrees.

Why degrees are not equal between other?

  • Tell us what p1 and p2 are, so we can actually duplicate your result. Also tell us postgis_full_version(). – Paul Ramsey Oct 22 '13 at 23:20
  • Sorry, add coordinates to question.

    Postgis_full_version: "POSTGIS="2.0.3 r11128" GEOS="3.3.8-CAPI-1.7.8" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.9.0" LIBJSON="UNKNOWN" RASTER"

    – Vsevolod Avramov Oct 23 '13 at 00:37
  • I apply this code for other points: (0,0) and (90,90) and get same wrong result. – Vsevolod Avramov Oct 23 '13 at 01:14
  • No answer yet, but I'm willing to guess this is mixing up of units/geography/geometry types. – Paul Ramsey Oct 23 '13 at 02:09
  • You right! I cast coordinates from geography to geometry type. And instead ST_Project use ST_Translate( p1, sin(radians(degree))distance1, cos(radians(degree))distance1) – Vsevolod Avramov Oct 23 '13 at 02:53
  • @PaulRamsey on the same note, I think there are problems with ST_DistanceSphere where PostGIS casts geometry->geography https://dba.stackexchange.com/q/191277/2639 Love for you to look at that one – Evan Carroll Nov 20 '17 at 03:59

1 Answers1

2

It's my fault. Like Paul Ramsey said - i use mixing types geography and geometry at the same time.

To resolve this i transform all points to geometry (with srid 3576) and instead ST_Project use ST_Translate( p1, sin(radians(degree))*distance1, cos(radians(degree))*distance1)

My final code is:

SELECT distance1,
       ST_Distance( p1, _p2) as distance2
       degree1,
       degrees(ST_Azimuth( p1, _p2)) as degree2
FROM 
(SELECT p1, p2, distance1, degree1, ST_Translate( p1, sin(radians(degree1))*distance1, cos(radians(degree1))*distance1) as _p2 FROM
  (SELECT p1, p2, ST_Distance(p1, p2) as distance1, degrees(ST_Azimuth(p1, p2)) as degree1 FROM
    (SELECT ST_Transform(ST_GeomFromText('POINT(92.78488163381019 55.9757874622428)', 4326), 3576) as p1, ST_Transform(ST_GeomFromText('POINT(92.78482645521103 55.97564239375992)', 4326),3576) as p2
    ) as points
  ) as foo
) as bar

Result: distance1 == distance2 and degree1 == degree2