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

Issues checking if location is within set polygon #4

Closed
ChristianAdrian opened this issue Jul 9, 2020 · 14 comments
Closed

Issues checking if location is within set polygon #4

ChristianAdrian opened this issue Jul 9, 2020 · 14 comments

Comments

@ChristianAdrian
Copy link

some areas within the set polygon returns false.

@kb0
Copy link
Owner

kb0 commented Jul 9, 2020

Can you provide an example?

@ChristianAdrian
Copy link
Author

ChristianAdrian commented Jul 9, 2020 via email

@ChristianAdrian
Copy link
Author

ChristianAdrian commented Jul 9, 2020 via email

@kb0
Copy link
Owner

kb0 commented Jul 9, 2020

  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
Copy link
Author

ChristianAdrian commented Jul 12, 2020 via email

@ChristianAdrian
Copy link
Author

any update regarding this issue?

@Sacchid
Copy link

Sacchid commented Jul 22, 2020

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
Copy link
Author

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
Copy link
Owner

kb0 commented Jul 26, 2020

@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));

@kb0 kb0 closed this as completed Jul 26, 2020
@ChristianAdrian
Copy link
Author

ChristianAdrian commented Jul 27, 2020

@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
Copy link
Owner

kb0 commented Jul 27, 2020

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

@ChristianAdrian
Copy link
Author

ChristianAdrian commented Jul 27, 2020

@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
#4 (comment)

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

@kb0
Copy link
Owner

kb0 commented Jul 27, 2020

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

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

@ChristianAdrian
Copy link
Author

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

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

3 participants