LdDl / horizon

Map matching (snapping GPS points to road graph) and routing library in Go
Apache License 2.0
45 stars 6 forks source link

[FEATURE REQUEST / question] ellipsoidal model for distance #14

Open kkdd opened 2 years ago

kkdd commented 2 years ago

Hello, For mitigating the distortion error in distance, $r$, arisen from spherical model (= S2 geometry), I think that ellipsoidal model would be better, and it would traditionally consist of the following:

Do you have any ideas about it?

$$ \begin{align} dr &= \sqrt{dE^2+dN^2} \ dE &= \left(\frac{R}{\sqrt{1-e^2\sin^2 \phi }}\right) \cos \phi d \lambda \ dN &= \left(\frac{R\ (1- e^2)}{\left(1-e^2 \sin^2 \phi\right)^{3/2}}\right) d \phi \ \end{align} $$

$$ \begin{align} x &= R\lambda \ y &= 2 R \tan \frac{\phi}{2} \ \chi &= \tan \frac{\phi}{2} \ d \phi &= \frac{2}{1 + \chi^2} d \chi \ \cos \phi &= \frac{1 - \chi^2 }{1 + \chi^2}\ \sin \phi &= \frac{2 \chi}{1 + \chi^2} \end{align} $$

LdDl commented 2 years ago

Hi! Remark: unfortunately, I'm not that GIS guy, who knows a lot about projections (even knowing some PostGIS stuff).

  1. I do like an idea to replace B-tree search with R-tree (or even better Quad-tree), but how does this affect performance in terms of searches per second?
  2. Are there any "Mercator vs Gall (Braun)" discussions where I can find pros/cons of each projection?
kkdd commented 2 years ago

Hi, Thank you for your comment.

I'm sorry that I don't have a clear idea about the comparison of the search performance between the following:

(R-tree performance has been discussed in literature.)

And we can't see performance discussions about projection, unfortunately.

But the simple use of latitude $\phi$ has the disadvantage in performance when calculating differential, or short-range, distance if based on ellipsoidal model because of the existence of trigonometric functions:

$$ \begin{align} dr &= \sqrt{dE^2+dN^2} \ dE &= \left(\frac{R}{\sqrt{1-e^2\sin^2 \phi }}\right) \cos \phi d \lambda \ dN &= \left(\frac{R\ (1- e^2)}{\left(1-e^2 \sin^2 \phi\right)^{3/2}}\right) d \phi \ \end{align} $$

An idea against for above would be that all of $\cos \phi \textrm{\ and} \cos \phi$ in the coordinates in map data would be calculated in the preprocess stage.

LdDl commented 2 years ago

Well, I keep an eye on it. Is this correct definition of Braun proj?

+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +ellps=WGS84 +datum=WGS84 +units=m +no_defs

I want to play with it within the instruments like QGIS/ArcGIS/PostGIS

P.s. I've found little Quora disscusions about Gall-Peters(Braun) vs Mercator: https://www.quora.com/What-is-the-difference-between-Mercator-and-Gall-Peters-projection https://www.quora.com/Which-map-is-useful-and-good-between-Mercator-projection-and-Peters-projection

kkdd commented 2 years ago

Hi, An above-mentioned idea is for avoiding trigonometric calculation for distance in the differential, or short-range, sense.

I have no idea about the definition of Braun projection in proj. But in the following demonstration, I used the conversion of latitude, $\chi = 2 \tan \frac{\phi}{2}$, but didn't calculated any distance:

PS. Mercator projection (and Gudermannian function) can be represented by using $\tan \frac{\phi}{2}$, also.