5

I am using turf.js for geometrical operation on openlayers3 features but i think it lacks support for "contains" operation.

There are these within and inside operations, but they return "false" when i check it with the polygon. Is there any other way to do this "contains" operation with turf.js or do i have to use the JSTS?

  • JSTS is a better solution in my personal opinion. But in your case if a point is within a polygon then this polygon contains your point. – pavlos Nov 1 '15 at 15:29
  • Thanks @pavlos for reply, but my requirement is not to check the point within polygon, but polygon contains "polygon". And yeah may be looping through the coordinates of 2nd polygon and then checking the "within" to first polygon solves the problem, but that becomes an unnecessary task. – Suraj Nov 1 '15 at 17:51
  • Turf within and inside checks for a set of points against a polygon. turfjs.org/static/docs/module-turf_within.html. So obviously wont work for polygons to polygons. Though looping through polygon points (as you describe) shall give you the solution. Why do you think this is an unnecessary task? In your case seems to be neccessary ..... unless you want to use JSTS, which in my personal opinion is more elegant and complete library – pavlos Nov 2 '15 at 11:56
  • 1
    Much of Turf has relied on JSTS it turns out: github.com/Turfjs/turf/issues/88 – thadk Jul 5 '16 at 18:27
  • 1
    Not really knowing anything about either of these prior to a few hours ago, I'd say turf is far better documented than JSTS. With JSTS all I could find was a link the the Java API and a site with about 4 examples. Am I missing something? – redbmk Aug 2 '16 at 16:49
1

You should be able to use the turf/boolean-contains module, noting that this only returns a true or false answer. Hope that helps

  • Given that this question was asked in '15. And currently i am not working on the same, yet the description on at the URL shared seems like finally this support is added to turf.js. Hence accepting this as answer. – Suraj Jan 12 '18 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.