buildGeometries method

Geometry buildGeometries(
  1. List<LinearRing> shells,
  2. List<LinearRing> holes,
  3. List<List<LinearRing>> holesForShells
)

Implementation

Geometry buildGeometries(
    final List<LinearRing> shells,
    final List<LinearRing> holes,
    final List<List<LinearRing>> holesForShells) {
  List<Polygon> polygons;

  // if we have shells, lets use them
  if (shells.isNotEmpty) {
    polygons = []; // List(shells.length);
    // oh, this is a bad record with only holes
  } else {
    polygons = []; // List(holes.length);
  }

  // this will do nothing for the "only holes case"
  for (int i = 0; i < shells.length; i++) {
    LinearRing shell = shells[i];
    List<LinearRing> holesForShell = holesForShells[i];
    polygons.add(geometryFactory.createPolygon(shell, holesForShell));
    // polygons[i] = geometryFactory.createPolygon(shell, holesForShell);
  }

  // this will take care of the "only holes case"
  // we just reverse each hole
  if (shells.isEmpty) {
    for (int i = 0, ii = holes.length; i < ii; i++) {
      LinearRing hole = holes[i];
      polygons.add(geometryFactory.createPolygon(hole, null));
      // polygons[i] = geometryFactory.createPolygon(hole, null);
    }
  }

  Geometry g = geometryFactory.createMultiPolygon(polygons);

  return g;
}