int msIntersectPolygons(shapeObj *p1, shapeObj *p2) { int i; /* STEP 1: polygon 1 completely contains 2 (only need to check one point from each part) */ for(i=0; i<p2->numlines; i++) { if(msIntersectPointPolygon(&(p2->line[i].point[0]), p1) == MS_TRUE) /* this considers holes and multiple parts */ return(MS_TRUE); } /* STEP 2: polygon 2 completely contains 1 (only need to check one point from each part) */ for(i=0; i<p1->numlines; i++) { if(msIntersectPointPolygon(&(p1->line[i].point[0]), p2) == MS_TRUE) /* this considers holes and multiple parts */ return(MS_TRUE); } /* STEP 3: look for intersecting line segments */ if (msIntersectPolylines(p1, p2) == MS_TRUE) return(MS_TRUE); /* ** At this point we know there are are no intersections between edges. There may be other tests necessary ** but I haven't run into any cases that require them. */ return(MS_FALSE); }
int msIntersectPolylinePolygon(shapeObj *line, shapeObj *poly) { int i; /* STEP 1: polygon might competely contain the polyline or one of it's parts (only need to check one point from each part) */ for(i=0; i<line->numlines; i++) { if(msIntersectPointPolygon(&(line->line[i].point[0]), poly) == MS_TRUE) /* this considers holes and multiple parts */ return(MS_TRUE); } /* STEP 2: look for intersecting line segments */ if (msIntersectPolylines(line, poly) == MS_TRUE) return (MS_TRUE); return(MS_FALSE); }
/* ** Does shape1 intersect shape2, returns MS_TRUE/MS_FALSE or -1 for an error. */ int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2) { #ifdef USE_GEOS GEOSGeom g1, g2; int result; if(!shape1 || !shape2) return -1; if(!shape1->geometry) /* if no geometry for shape1 then build one */ shape1->geometry = (GEOSGeom) msGEOSShape2Geometry(shape1); g1 = (GEOSGeom) shape1->geometry; if(!g1) return -1; if(!shape2->geometry) /* if no geometry for shape2 then build one */ shape2->geometry = (GEOSGeom) msGEOSShape2Geometry(shape2); g2 = (GEOSGeom) shape2->geometry; if(!g2) return -1; result = GEOSIntersects(g1, g2); return ((result==2) ? -1 : result); #else if(!shape1 || !shape2) return -1; switch(shape1->type) { /* todo: deal with point shapes */ case(MS_SHAPE_LINE): switch(shape2->type) { case(MS_SHAPE_LINE): return msIntersectPolylines(shape1, shape2); case(MS_SHAPE_POLYGON): return msIntersectPolylinePolygon(shape1, shape2); } break; case(MS_SHAPE_POLYGON): switch(shape2->type) { case(MS_SHAPE_LINE): return msIntersectPolylinePolygon(shape2, shape1); case(MS_SHAPE_POLYGON): return msIntersectPolygons(shape1, shape2); } break; } return -1; #endif }