1

What should I do to find the distance between two very far points?

p1 = "POINT(6.2 61.1)"
p2 = "POINT(6.1 61.0)"

select
ST_Distance(
  ST_Transform(ST_GeomFromWKT('$p1'), 'EPSG:4326', '$epsg'),
  ST_Transform(ST_GeomFromWKT('$p2'), 'EPSG:4326', '$epsg')
) as distance

with EPSG:3857 this is 25550.25 but with EPSG:32632 I'm got 12382.11 and leaning on Google that's right.

I'm using GeoSpark library in my calculations.

Update: My range of longitude approximately from 20 to 190

Update 2: I can't use PostGIS, I'm using Hadoop and GeoSpark

nmtoken
  • 13,355
  • 5
  • 38
  • 87
  • 1
    The main idea is to use Projected CS which can be local or worldwide. By the way, where your points should be located, i.e. country? Probably some reprojection is needed. – Taras Apr 01 '19 at 11:05
  • Points can be located from whole all Russia, I didn't find any projection which covers it.

    In global, my objective is find nieghbors polygons in 500 meters, where I use epsg:3856, and then precise distance with local EPSG which i find with that function: `val epsgCode: Geometry => String = { g => val lat: Double = g.getCentroid.getX;

     return s"EPSG:${32631 + (lat / 6).toInt}"
    

    }`

    – K. Kostikov Apr 01 '19 at 11:18
  • 0.1 difference in X and Y isn't generally considered "very far", even in geographic units. Try using the coordinates of London and Christchurch, at which point even a projected coordinate system can't help. Web Mercator (3857) should never be used for Cartesian distance calculations. Please [Edit] the question in response to requests for clarification. – Vince Apr 01 '19 at 11:21
  • I've wrote sample, that shows that I have problems even with so close points. My range of longitude approximately from 20 to -170 – K. Kostikov Apr 01 '19 at 11:25
  • Given the range of longitudes, you're probably better off using a geodetic library which will compute great elliptical values on the spheroid. – Vince Apr 01 '19 at 12:42
  • Take a look at ST_GeodesicLengthWGS84 for Hive & SparkSQL - https://github.com/Esri/spatial-framework-for-hadoop/wiki/UDF-Accessors#st_geodesiclengthwgs84 [disclosure: collaborator] – Randall Whitman Apr 13 '21 at 16:00

0 Answers0