intersects method

bool intersects({
  1. MultiPolygon? multi,
  2. Polygon? poly,
})

Returns whether or not the MultiPolygon intersects another MultiPolygon or Polygon.

Example:

MultiPolygon([
  [LinearRing([Coordinate(1, 2), Coordinate(3, 4), Coordinate(5, 6), Coordinate(1, 2)])]
]).intersects(
  poly: Polygon([
    LinearRing([Coordinate(7, 8), Coordinate(9, 10), Coordinate(11, 12), Coordinate(7, 8)])
  ])
); // false

Implementation

bool intersects({MultiPolygon? multi, Polygon? poly}) {
  if (multi != null) {
    for (final ringSets in multi.coordinates) {
      if (intersects(poly: Polygon(ringSets))) {
        return true;
      }
    }
    return false;
  } else if (poly != null) {
    for (final ringSets in coordinates) {
      if (Polygon(ringSets).intersects(poly)) {
        return true;
      }
    }
    return false;
  } else {
    throw ArgumentError('multi or poly must be provided');
  }
}