You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
isPointInside does not appear to work correctly when the polygon straddles the anti-meridian.
I maintain a system with lots of polygons that do straddle the antimeridian (I'm in Australia :-) so it's important to me.
see the test code below that illustrates the problem when it's run:
var geolib = require('geolib');
// -------------
// Test 1 This succeeds
// -------------
var polygon = [
{latitude: -46, longitude: 1},
{latitude: -46, longitude: 2},
{latitude: -47, longitude: 2},
{latitude: -47, longitude: 1}
];
console.log('Test 1: Polygon:',polygon);
console.log('should be true', geolib.isPointInside({ latitude:-46.5, longitude:1.5}, polygon))
console.log('should be false', geolib.isPointInside({ latitude:-47.9, longitude:1.2}, polygon))
console.log('should be true', geolib.isPointInside({ latitude:-46.8, longitude:1.1}, polygon))
console.log('------------');
// -------------
// Test 2 This succeeds
// -------------
var polygon = [
{latitude: 10, longitude: -10},
{latitude: 10, longitude: 10},
{latitude: 20, longitude: 10},
{latitude: 20, longitude: -10}
];
console.log('Test 2: Polygon:',polygon);
console.log('should be true', geolib.isPointInside({ latitude:15, longitude:-5}, polygon))
console.log('should be false', geolib.isPointInside({ latitude:15, longitude:-15}, polygon))
console.log('should be true', geolib.isPointInside({ latitude:15, longitude:-5}, polygon))
// ----------
// Test 3 : AntiMeridian 1: This fails
// ----------
var polygon = [
{latitude: 10, longitude: 175},
{latitude: 10, longitude: -175},
{latitude: 20, longitude: -175},
{latitude: 20, longitude: 175}
];
console.log('Test 3: Antimeridian 1: Polygon:',polygon);
console.log('should be true', geolib.isPointInside({ latitude:15, longitude:177}, polygon))
console.log('should be false', geolib.isPointInside({ latitude:15, longitude:-170}, polygon))
console.log('should be true', geolib.isPointInside({ latitude:15, longitude:-176}, polygon))
console.log('------------');
// ----------
// Test 4: Antimeridian 2: This fails
// ----------
var polygon = [
{latitude: 10, longitude: -175},
{latitude: 10, longitude: 175},
{latitude: 20, longitude: 175},
{latitude: 20, longitude: -175}
];
console.log('Test 4: Antimeridian 2: Polygon:',polygon);
console.log('should be true', geolib.isPointInside({ latitude:15, longitude:177}, polygon))
console.log('should be false', geolib.isPointInside({ latitude:15, longitude:-170}, polygon))
console.log('should be true', geolib.isPointInside({ latitude:15, longitude:-176}, polygon))
console.log('------------');
The text was updated successfully, but these errors were encountered:
Can confirm this is a problem, I just had a painful experience on this too.
My crappy solution was an interface warning !
Possible (ugly) solution : if the box straddles the anti-meridian, pretend the whole situation is on the other side of the globe? i.e. shuffle all the longitudes +180 degrees? (and then for any degrees over 180, map that to appropriate negative value e.g. 350 - 360 = -10 )
isPointInside does not appear to work correctly when the polygon straddles the anti-meridian.
I maintain a system with lots of polygons that do straddle the antimeridian (I'm in Australia :-) so it's important to me.
see the test code below that illustrates the problem when it's run:
The text was updated successfully, but these errors were encountered: