I want to intersect two polygons within an OpenLayers layer. I found the JSTS library, which should be able to intersect two polygons, and return the new created polygon of the intersection. The function to use: intersection


Using the OpenLayers Polygons directly, I get errors, resulting of the missing functions, added by JSTS. And if I use JSTS Polygons, there seems still something missing. this.getFactory().createGeometryCollection is not a function

How do I get an intersection of those two polygons?


The intersects method in OpenLayers will only return a boolean value, not the intersection of the features.

   //polygons intersect

Edit: I see you mean using the OpenLayers polygon type rather than the OpenLayers intersect method.

The JSTS library has only been out a few days, and the intersects function you referenced was updated 6 hours ago, so not sure how stable it is at the moment.

  • You are right. I just want to use the OpenLayers polygon type. I need the actual coordinates of the new intersection. Thanks pointing out that JSTS is still very fresh. – happly May 25 '11 at 9:02
  • @happly - I downloaded it a couple of days ago and couldn't get the unit tests to run, I'll try again in a week, but I wouldn't rely on it for a production system yet. Probably best to do it server-side for the moment – geographika May 25 '11 at 9:49
  • hmm, I could use it so much now. Thanks. You don't now any mature client-based solutions? – happly May 25 '11 at 15:43
  • @happly - not really.. see gis.stackexchange.com/questions/7159/… – geographika May 27 '11 at 13:17

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.