Skip to content
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

Issue with Polygons and / or Parse.Query.polygonContains #4607

Closed
JacobJT opened this issue Mar 6, 2018 · 2 comments
Closed

Issue with Polygons and / or Parse.Query.polygonContains #4607

JacobJT opened this issue Mar 6, 2018 · 2 comments

Comments

@JacobJT
Copy link

JacobJT commented Mar 6, 2018

Issue Description

I've just updated parse-server, parse, and parse-dashboard to the latest versions to utilize the Parse.Polygon object, specifically to use the Parse.Query.polygonContains() method. Something is either switching coordinate pairs when it shouldn't be, or not switching coordinate pairs when it should be, somewhere in the flow of creating a Polygon from Parse.GeoPoints, attaching it to an object, then querying that class using polygonContains. I get the expected result when I flop the order of the values within a Polygon object, but that Polygon object was set up with an array of Parse.GeoPoints.

Steps to reproduce

  1. Create a Parse.Polygon from an array of Parse.GeoPoints
  2. Attach Polygon to an object & Save
  3. Create a query on the class you've attached the Polygon to, and use query.polygonContains("polygonKey", geoPoint); where geoPoint is a known coordinate within the polygon
  4. Check results - they will be nil
  5. Use the Parse-Dashboard to go through the Polygon's values and swap the lat / longs. Notice that when creating the Polygon from an array of Parse.GeoPoints that they were put in the [lat,long] order. Change them to be [long,lat].
  6. Run the query again, and you should find the expected object

Expected Results

Querying for a location using polygonContains on a Polygon field created with an array of Parse.GeoPoints should yield the expected object when using a GeoPoint known to be within said polygon

Actual Outcome

The query only returns the expected result if you swap the order of [lat,long] values on the Polygon object.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : ~2.7.2
    • Operating System: OSX 10.12.6
    • Hardware: 2015 MBP
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): local / AWS
  • Database ~~~~Not sure where to find this info, don't see any of the relevant info on mLab~~~~

    • MongoDB version: [FILL THIS OUT]
    • Storage engine: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab

Additional Info

I notice that in your unit tests, you use [ [0,0], [0,1], [1,1], [1,0] ], which is likely why this error was missed. Other test polygons include:

    const points1 = [[0,0],[0,1],[1,1],[1,0]];
    const points2 = [[0,0],[0,2],[2,2],[2,0]];
    const points3 = [[10,10],[10,15],[15,15],[15,10],[10,10]];

These all run into the same issue of being mirrored over a lat = long line.

I could "hack around" this issue by reversing the order of the coordinates I pass into the query, but then again, I don't know if the issue lies within the query method or the storage of Polygon itself. I'm assuming the former, but don't know. I then also don't know if there are other repurcussions to this.

@dplewis
Copy link
Member

dplewis commented Mar 6, 2018

Can you email me the polygon you are using and geopoint? findlewis (at) gmail (dot) com

Or post your logs VERBOSE=1

@JacobJT
Copy link
Author

JacobJT commented Mar 6, 2018

@dplewis incoming in a few, thanks. I was also putting together a PR to update the test cases so that it'll highlight this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants