Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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