Reputation: 51
I am using turf.js to find a point inside a polygon and i found the problem persisting for several use cases one of such use case is as below below mentioned use case (i.e. for point (X=32.8,Y=40). I have also plotted the image for reference for which turf.booleanPointInPolygon is showing false. Image of Graph plot
var turf = require("@turf/turf");
var pt = turf.point([32.8,40]);
var poly = turf.polygon([[
[ 7.2 , 160.0],
[38.3, 30.0],
[65.1 , 30.0],
[62.3 , 96.0],
[18.4 , 325.0],
[7.6 , 380.0],
[7.5 , 307.0],
[7.4 , 234.0],
[7.2 , 160.0]
]]);
var bool = turf.booleanPointInPolygon(pt, poly, {ignoreBoundary: false});
//bool = false, even though the point is inside the polygon
failed to recognize a point within the polygon, this is a glitch from turf.js. How to report to turf.js. Anyone please help in fixing this.
Upvotes: 2
Views: 1170
Reputation: 51
I converted the cartesian x-axis array, y-axis array and the point to be found to log scale using Math.log(x)
in javascript before feeding to turf.js for creating polygon and the point to be found within it. It is rendering correctly now. The major flaw was that i plotted my coordinates in log scale and was seeking turfs solution by passing cartesian data (which i converted to log scale before sending to turf)
Upvotes: 2
Reputation: 7635
Your point is not inside the polygon. There is no bug in turf.js. You probably been tricked because your plotted graph is completely wrong.
Here it is how your polygon should look likes on a graph. You see that your point (J) is clearly outside:
Upvotes: 0