doc_id
doc_id

Reputation: 1443

Mongodb geospatial indexes, 2d vs 2dsphere

According to the docs it says about 2d indexes:

The 2d index supports calculations on a flat, Euclidean plane. The 2d index also supports distance-only calculations on a sphere, but for geometric calculations (e.g. $geoWithin) on a sphere, store data as GeoJSON objects and use the 2dsphere index type.

Few things I do not understand..

  1. I do not understand what is meant by distance-only, does it mean the Chord (that line which connects two surface points through a line "inside" the surface)?
  2. How does that calculation work against Earth Longitude and Latitude? If that was designed for Euclidean space, how does it express distance in radians?
  3. Instead, using the 2dsphere indexes, it calculates the surface distance correctly between two points, but it works without specifying the 360 longitude lines and the 180 latitude lines. Is it programmed to specially for Earth longitude and latinudes?
  4. If 3. above is correct. does it takes into account that Earth is oblate spheroid and not a perfect sphere?

Upvotes: 3

Views: 1128

Answers (1)

apb
apb

Reputation: 433

  1. No. It means the surface distance using the Haversine formula.
  2. I'm not sure what you are trying to ask in regards to "how does it express distance in radians" but if you mean how are lat/lon angle values and deltas converted into radians it is: PI * angle / 180.0. For the full Haversine formula, check out this link for implementations in 84 languages: http://rosettacode.org/wiki/Haversine_formula
  3. 2dsphere indexes use the WGS84 datum (which defines the bounds) See: http://spatialreference.org/ref/epsg/4326/.
  4. Without looking at their code it is impossible to say. But given that they use WGS84 and talk about an "earth-like sphere" it is highly doubtful. I'm guessing they use Haversine (so distance calculations are only an approximation).

Upvotes: 1

Related Questions