kb0 / maps_toolkit

Dart library for area, distance, heading measurements
Apache License 2.0
46 stars 17 forks source link

Issues checking if location is within set polygon #4

Closed ChristianAdrian closed 4 years ago

ChristianAdrian commented 4 years ago

some areas within the set polygon returns false.

kb0 commented 4 years ago

Can you provide an example?

ChristianAdrian commented 4 years ago
I’m using your package with another package and I used wikimapia API for getting the coordinates of the polygon. So in this capture you can see that the red pin is the current location. But containslocation returns false. When I move it in a different area within the polygon it returns true but sometimes it doesn’t. Anyway how to debug this issue? Sent from Mail for Windows 10 From: kb0Sent: Thursday, July 9, 2020 3:22 PMSubject: Re: [kb0/maps_toolkit] Issues checking if location is within set polygon (#4) Can you provide an example?—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.  Virus-free. www.avast.com
ChristianAdrian commented 4 years ago

Sent from Mail https://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

[image: Capture.PNG]

In the emulator the red pin is the current coordinates that is being compared I used wikimapia API for plotting the polygon and that the red highlight in the map as you can see the red pin is within the polygon but contains.location returns false in this coordinates. If I move it within the same polygon it returns true. How fix on this issue?

kb0 commented 4 years ago
  1. No image, only text [image: Capture.PNG]
  2. Can you provide dart code with coordinates of polygon, and coordinates of point? Something, like:
    PolygonUtil.containsLocation(
    LatLng(20.0, 33.5),
    [LatLng(28, -82), LatLng(29, -83), LatLng(30, -85), LatLng(28, -82)],
    true)
ChristianAdrian commented 4 years ago

[{"x":55.4695522,"y":25.3937088},{"x":55.4680877,"y":25.3945885},{"x":55.4669666,"y":25.3952887},{"x":55.4651588,"y":25.3955238},{"x":55.4634045,"y":25.3957539},{"x":55.461688,"y":25.395926},{"x":55.4603147,"y":25.396064},{"x":55.4590219,"y":25.3962459},{"x":55.4580186,"y":25.396384},{"x":55.4564952,"y":25.3967619},{"x":55.4557013,"y":25.397467},{"x":55.4548966,"y":25.3981769},{"x":55.4546231,"y":25.3986979},{"x":55.4543602,"y":25.3991751},{"x":55.4540169,"y":25.3991849},{"x":55.4538935,"y":25.3997689},{"x":55.4537487,"y":25.4004544},{"x":55.4535448,"y":25.4012299},{"x":55.4526758,"y":25.4010844},{"x":55.4519248,"y":25.4040403},{"x":55.4517852,"y":25.4040112},{"x":55.4487705,"y":25.4027515},{"x":55.4485558,"y":25.4026156},{"x":55.4480168,"y":25.4021663},{"x":55.4498431,"y":25.4003286},{"x":55.4510986,"y":25.3985452},{"x":55.4533194,"y":25.3953276},{"x":55.454607,"y":25.393263},{"x":55.4548966,"y":25.3928947},{"x":55.4551541,"y":25.3923422},{"x":55.4552613,"y":25.3913827},{"x":55.4551005,"y":25.3903843},{"x":55.4553687,"y":25.3899676},{"x":55.4563611,"y":25.389815},{"x":55.4573321,"y":25.3897108},{"x":55.4584693,"y":25.3895291},{"x":55.4590433,"y":25.3894467},{"x":55.4602503,"y":25.3892553},{"x":55.4609638,"y":25.3891559},{"x":55.4621171,"y":25.3889694},{"x":55.4635441,"y":25.3890759},{"x":55.4651105,"y":25.3893376},{"x":55.4662719,"y":25.3897823},{"x":55.4674708,"y":25.3902487},{"x":55.4683774,"y":25.3906583},{"x":55.4692679,"y":25.3910217},{"x":55.4708289,"y":25.3916445},{"x":55.4719017,"y":25.3917995}]

this are the polygon coordinates

25.392898, 55.455251 this is a sample coordinate that does not work.

25.394104, 55.454473 this is a coordinate that returns true

On Thu, Jul 9, 2020 at 5:09 PM kb0 notifications@github.com wrote:

  1. No image, only text [image: Capture.PNG]
  2. Can you provide dart code with coordinates of polygon, and coordinates of point? Something, like:

PolygonUtil.containsLocation( LatLng(20.0, 33.5), [LatLng(28, -82), LatLng(29, -83), LatLng(30, -85), LatLng(28, -82)], true)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kb0/maps_toolkit/issues/4#issuecomment-656117328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOW6FULILUT5HAV2DOWYXHLR2W6SBANCNFSM4OVKEQOQ .

ChristianAdrian commented 4 years ago

any update regarding this issue?

Sacchid commented 4 years ago

Sorry although I am not author of this package, am writing this to ask you that are you sure are those co-ordinates for points correctly ordered? By using similar Geo-fencing package, both points (Point(25.392898, 55.455251) Point(25.394104, 55.454473)) are not inside Polygon, but Point(55.455251, 25.392898) and Point(55.454473, 25.394104) are both inside the given polygon. For my ref, can you send link with which you have checked, I will also check these points with Gmap later.

ChristianAdrian commented 4 years ago

Sorry although I am not author of this package, am writing this to ask you that are you sure are those co-ordinates for points correctly ordered? By using similar Geo-fencing package, both points (Point(25.392898, 55.455251) Point(25.394104, 55.454473)) are not inside Polygon, but Point(55.455251, 25.392898) and Point(55.454473, 25.394104) are both inside the given polygon. For my ref, can you send link with which you have checked, I will also check these points with Gmap later.

Hi, I used wikimapia's api for getting the coordinate points and then saved it to our database. http://wikimapia.org/#lang=en&lat=25.390714&lon=55.457182&z=15&m=w&show=/22012924/Al-Rashideya-1 this is the link for the plotted coordinates.

kb0 commented 4 years ago

@ChristianAdrian you should check order of your testing points. I add test for your case at https://github.com/kb0/maps_toolkit/blob/master/test/polygon_util_test.dart. It's work as expected:

// correct order of latitude and longitude
expect(
    PolygonUtil.containsLocation(
        LatLng(55.455251, 25.392898), polygon, true),
    equals(true));

expect(
    PolygonUtil.containsLocation(
        LatLng(55.454473, 25.394104), polygon, true),
    equals(true));

// reverse order of latitude and longitude
expect(
    PolygonUtil.containsLocation(
        LatLng(25.394104, 55.454473), polygon, true),
    equals(false));

expect(
    PolygonUtil.containsLocation(
        LatLng(25.394104, 55.454473), polygon, true),
    equals(false));
ChristianAdrian commented 4 years ago

@kb0

should check order of your testing points. I add test for your

@ChristianAdrian you should check order of your testing points. I add test for your case at https://github.com/kb0/maps_toolkit/blob/master/test/polygon_util_test.dart. It's work as expected:

// correct order of latitude and longitude
expect(
  PolygonUtil.containsLocation(
      LatLng(55.455251, 25.392898), polygon, true),
  equals(true));

expect(
  PolygonUtil.containsLocation(
      LatLng(55.454473, 25.394104), polygon, true),
  equals(true));

// reverse order of latitude and longitude
expect(
  PolygonUtil.containsLocation(
      LatLng(25.394104, 55.454473), polygon, true),
  equals(false));

expect(
  PolygonUtil.containsLocation(
      LatLng(25.394104, 55.454473), polygon, true),
  equals(false));

Hi, sorry my example was not clear but the value of x is the lng and the value of y is the lat because im getting this data in an api thats why its like that but in my code I used it as the opposite so in my code it is like this.

final polygon = makeList([

  25.3937088,
  55.4695522,
  25.3945885,
  55.4680877,
  25.3952887,
  55.4669666,
  25.3955238,
  55.4651588,
  25.3957539,
  55.4634045,
  25.395926,
  55.461688,
  25.396064,
  55.4603147,
  25.3962459,
  55.4590219,
  25.396384,
  55.4580186,
  25.3967619,
  55.4564952,
  25.397467,
  55.4557013,
  25.3981769,
  55.4548966,
  25.3986979,
  55.4546231,
  25.3991751,
  55.4543602,
  25.3991849,
  55.4540169,
  25.3997689,
  55.4538935,
  25.4004544,
  55.4537487,
  25.4012299,
  55.4535448,
  25.4010844,
  55.4526758,
  25.4040403,
  55.4519248,
  25.4040112,
  55.4517852,
  25.4027515,
  55.4487705,
  25.4026156,
  55.4485558,
  25.4021663,
  55.4480168,
  25.4003286,
  55.4498431,
  25.3985452,
  55.4510986,
  25.3953276,
  55.4533194,
  25.393263,
  55.454607,
  25.3928947,
  55.4548966,
  25.3923422,
  55.4551541,
  25.3913827,
  55.4552613,
  25.3903843,
  55.4551005,
  25.3899676,
  55.4553687,
  25.389815,
  55.4563611,
  25.3897108,
  55.4573321,
  25.3895291,
  55.4584693,
  25.3894467,
  55.4590433,
  25.3892553,
  55.4602503,
  25.3891559,
  55.4609638,
  25.3889694,
  55.4621171,
  25.3890759,
  55.4635441,
  25.3893376,
  55.4651105,
  25.3897823,
  55.4662719,
  25.3902487,
  55.4674708,
  25.3906583,
  55.4683774,
  25.3910217,
  55.4692679,
  25.3916445,
  55.4708289,
  25.3917995
  55.4719017,
]);

PolygonUtil.containsLocation(

  LatLng(25.394104, 55.454473), polygon, true),

equals(false)); expect( PolygonUtil.containsLocation( LatLng(25.394104, 55.454473), polygon, true), equals(false));

its supposed to be like this. But I'm still getting some parts within the polygon return false.

kb0 commented 4 years ago

@ChristianAdrian I add test with reverse order of coordinates (latitude <-> longitude) - 'contains issue-4-2' (https://github.com/kb0/maps_toolkit/commit/923579b85c3a20922beb2b84d1cfdd203e29b1c8) - it's work on your data

ChristianAdrian commented 4 years ago

@kb0

@ChristianAdrian I add test with reverse order of coordinates (latitude <-> longitude) - 'contains issue-4-2' (923579b) - it's work on your data

yes that returns true but this one returns false even if its within the polygon 25.392898, 55.455251

reference from my first https://github.com/kb0/maps_toolkit/issues/4#issuecomment-657180101

this is why I cant figure out the problem because some of the plots within the polygon works but some does not

kb0 commented 4 years ago

Fix point in tests, point (25.392898, 55.455251) return true:

    expect(
        PolygonUtil.containsLocation(
            LatLng(25.392898, 55.455251), polygon, true),
        equals(true));
ChristianAdrian commented 4 years ago

Fix point in tests, point (25.392898, 55.455251) return true:

    expect(
        PolygonUtil.containsLocation(
            LatLng(25.392898, 55.455251), polygon, true),
        equals(true));

Thanks, I have found the problem it's with the other package I'm using to get the location