Distance between two 3D points in geodjango (postgis)

I have the following problem:
I created two points, for example:

SRID=3857;POINT Z (62780.8532226825 5415035.177460473 100)
SRID=3857;POINT Z (62785.8532226825 5415035.177460473 70)

As you can see, the difference in the X coordinates is 5 m, and 30 m in the Z coordinates. When I run a.distance(b)django in the shell, it returns 5 , which is wrong.

However, when I run in the psql shell:

SELECT ST_3DDistance(a.coordinates, b.coordinates)
FROM restapi_entityxyz a, restapi_entityxyz b
WHERE a.external_id='6841zef1561' AND b.external_id='1G23Fzd';

It returns:

st_3ddistance
------------------
 30.4138126514911

What is the correct answer.

Is this a lack of functionality in geodjangoor a bug?
Should I use a custom library to perform this calculation?

My surroundings are as follows:

  • Python 3.5,
  • Django
  • postgresql 9.4 + postgis
  • gdal and many python libraries.
+1
1

django ( ), 2D.

, 3d-, , : ()

  • :
    polar_point_1 = (long_1, lat_1, alt_1)
     
     polar_point_2 = (long_2, lat_2, alt_2)

  • , :

    x = alt * cos(lat) * sin(long)
    y = alt * sin(lat)
    z = alt * cos(lat) * cos(long)
    

    p_1 = (x_1, y_1, z_1) p_2 = (x_2, y_2, z_2) .

  • , :

    dist = sqrt((x_2-x_1)**2 + (y_2-y_1)**2 + (z_2-z_1)**2)
    


: GeoDjango
+1

Source: https://habr.com/ru/post/1683451/


All Articles