6

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

polygon1.intersection(polygon2)

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?

1 Answer 1

8

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

if(polygon1.intersects(polygon2)){
   //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.

4
  • 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, 2011 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 May 25, 2011 at 9:49
  • hmm, I could use it so much now. Thanks. You don't now any mature client-based solutions?
    – happly
    May 25, 2011 at 15:43
  • @happly - not really.. see gis.stackexchange.com/questions/7159/… May 27, 2011 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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