static Geometry bufferUnionUnbuffer(double buffer, List<Geometry> polygonGroup, Stats stats) {
    /*
     * A simpler alternative that might initially appear faster would be:
     *
     * Geometry merged = GeoUtils.createGeometryCollection(polygonGroup);
     * merged = buffer(buffer, merged);
     * merged = unbuffer(buffer, merged);
     *
     * But since buffer() is faster than union() only when the amount of overlap is small,
     * this technique becomes very slow for merging many small nearby polygons.
     *
     * The following approach is slower most of the time, but faster on average because it does
     * not choke on dense nearby polygons:
     */
    List<Geometry> buffered = new ArrayList<>(polygonGroup.size());
    for (Geometry geometry : polygonGroup) {
      buffered.add(buffer(buffer, geometry));
    }
    Geometry merged = GeoUtils.createGeometryCollection(buffered);
    try {
      merged = union(merged);
    } catch (TopologyException e) {
      // buffer result is sometimes invalid, which makes union throw so fix
      // it and try again (see #700)
      stats.dataError("buffer_union_unbuffer_union_failed");
      merged = GeometryFixer.fix(merged);
      merged = union(merged);
    }
    merged = unbuffer(buffer, merged);
    return merged;
  }
Merges nearby polygons by expanding each individual polygon by {@code buffer}, unioning them, and contracting the
result.
planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java