Skip to content

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

Closed
@JacobJT

Description

@JacobJT

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions