public List<T> getContainingOrNearest(Point point) {
    build();
    List<?> items = index.query(point.getEnvelopeInternal());
    // optimization: if there's only one then skip checking contains/distance
    if (items.size() == 1) {
      if (items.getFirst() instanceof GeomWithData<?> value) {
        @SuppressWarnings("unchecked") T t = (T) value.data;
        return List.of(t);
      }
    }
    List<T> result = postFilterContaining(point, items);

    // if none contain, then look for the nearest polygon from potential overlaps
    if (result.isEmpty()) {
      double nearest = Double.MAX_VALUE;
      T nearestValue = null;
      for (Object item : items) {
        if (item instanceof GeomWithData<?> value) {
          double distance = value.poly.distance(point);
          if (distance < nearest) {
            @SuppressWarnings("unchecked") T t = (T) value.data;
            nearestValue = t;
            nearest = distance;
          }
        }
      }
      if (nearestValue != null) {
        result.add(nearestValue);
      }
    }
    return result;
  }
Returns the data associated with either the polygons that contain {@code point} or if none are found than the
nearest polygon to {@code point} with an envelope that contains point.
planetiler-core/src/main/java/com/onthegomap/planetiler/geo/PolygonIndex.java