-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Mongo: Fix reversing polygon coordinates #4609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4609 +/- ##
==========================================
+ Coverage 92.59% 92.65% +0.06%
==========================================
Files 119 119
Lines 8562 8566 +4
==========================================
+ Hits 7928 7937 +9
+ Misses 634 629 -5
Continue to review full report at Codecov.
|
I'm still not getting the expected results when querying using Example: This is the polygon object attached to an instance of my class:
This is the point I'm searching for: (42.624599,-83.770162) (this is a Parse GeoPoint) The point is definitely within the bounds of the polygon. I modified my code to create a new Parse GeoPoint with the latitude = original.latitude, and longitude = original.longitude, and I get the expected result. |
OK, did more testing and it looks like this change modified how Polygons are saved. That's where the coordinate reversal is taking place. So, the Polygon format should be [long, lat], but it was [lat, long]. I created a new instance of a Polygon instead of using the old one and saw that change. The method works as expected. So, the problem is that this is going to mean that all polygons currently stored are in reverse order, at least for people using mongo (I recall my Postgres tests were still passing when I modified the test case to highlight this error). |
@JacobJT What you see in the dashboard and input into your objects are in lat/lng. The databases are saved as lng/lat.(Postgres already stored at lng/lat) I didn't realize until today that I haven't updated my dashboard to support type Polygon which is why I missed this issue. @flovilmart How does this look? |
The polygon in my comment above was taken directly from the dashboard, and was created using the release version of parse-server. The query using a The polygon value below is created using the same Parse GeoPoints, but created using your parse-server branch. The query now works as expected and returns this object, but the fix is not compatible with old polygon data
|
spec/MongoTransform.spec.js
Outdated
const lat = -45; | ||
const lng = 45; | ||
// Mongo stores polygon in WGS84 lng/lat | ||
const input = {location: { type: 'Polygon', coordinates: [[[lng, lat],[lng, lat]]]}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is against the documentation for the GeoPoints,m where the list of corrdinates should be provided as lat,lng pairs, not lng,lat pairs.
http://parseplatform.org/Parse-SDK-JS/api/v1.11.1/Parse.GeoPoint.html
If the storage need to be reveresed, that's another issue but should not for something un natural for the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote it this way to highlight that the input and output are going to be reversed.
The current GeoPoint transform tests are slightly confusing at a glance.
Shouldn't this be testing mongoObjectToParseObject
input -> lng/lat output -> lat/lng?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I misread. Do you have a test that ensures the input / output orders are preserved? ie the mongo transformation is properly applied and reversed?
@JacobJT Thanks for helping with this one. |
* Fix reversing polygon coordinates * comments fix * real data test * improved tests
Closes: #4607
Has been tested on the latest parse-dashboard.
https://docs.mongodb.com/manual/reference/glossary/#term-wgs84