Serious Bug in MongoDB Geospatial distance calculation
blog.icod.de
blog.icod.de
I'm using PostgresSQL+PostGIS with QGIS as the front-end for a personal project and it's been fantastic.
> Final Edit: False Alarm
>
> It’s not MongoDB, It’s not the MongoDB Go driver, it’s something I did.
> I was especially careful to double and triple check Long and Lat and still something went wrong.
MongoDB uses libbson which should clearly preserve the type in the queries. If the client library wrapper goofs the syntax it is not related to the server core.
Try looking at the raw record in the db shell... ;-)
We. You weren't kidding. Every few lines was an ad. It was absolutely impossible to read.
I want to give the author the benefit of the doubt here. If he had actually seen what it looks like, I cannot believe he would keep it that way. He surely has ads turned off for himself to avoid being flagged as clicking on his own ads.
If you're storing data in a standardized format, odds are it's longitude, latitude. If your starting guess is the opposite, you will almost always be wrong.
Now you could make the case that Longitude and Latitude are NOT cartesian coordinates and thus not beholden to the x,y convention. Fair point, but we still encode it as a pair of coordinates as if it were a 2D reference system (technically the Platte Carre projection) like any other. Switching the coordinate order feels like a strange hill to die on - again, why a special case?
In any case, it's wildly inaccurate to place the blame on GeoJSON which was just following the widely held, and mathematically consistent, convention.
It behooves the new user to learn the industry standards and conventions instead of inventing their own.
But that's all about casual use. If someone's job is to write geospatial code for a database driver, it's a bare minimum to expect they'd pay attention to making this work right. Also to have a test suite to verify it's working right.
(When I write code I always put in a little check on inputs to display a very clear error message if it sees a "latitude" outside the range [-90, 90]. Won't catch all bad data but sure can help.)
To someone that works with geospatial data, this is like asserting that RGB is the wrong order for specifying color, ignoring that approximately everyone in industry has been using this ordering convention for a very long time.
Historically, cartography was Lat,Long (1). Then software developers took over, and their natural mode of thinking inherits from thinking in x,y coordinates in 2d-graphics on the computer screen, so Long,Lat started to dominate in software. And now software dominates everything.
Here's a take on the history: http://docs.geotools.org/latest/userguide/library/referencin...
(1) This is from 1983, but the Lat,Long practice is much older https://en.wikipedia.org/wiki/ISO_6709