Class S2ShapeIndexRegion

java.lang.Object
com.google.common.geometry.S2ShapeIndexRegion
All Implemented Interfaces:
S2Region

@GwtCompatible(serializable=false) public class S2ShapeIndexRegion extends Object implements S2Region
This class wraps an S2ShapeIndex object with the additional methods needed to implement the S2Region API, in order to allow S2RegionCoverer to compute S2CellId coverings of arbitrary collections of geometry.

Example usage:

 S2CellUnion getCovering(S2ShapeIndex index) {
   S2RegionCoverer coverer = new S2RegionCoverer();
   coverer.setMaxCells(20);
   return coverer.getCovering(new S2ShapeIndexRegion(index));
 }
 

This class uses a number of temporary mutable objects to keep allocation down, and so is not thread-safe. To use it in parallel, each thread should construct its own instance (this is not expensive).

  • Field Details

  • Constructor Details

  • Method Details

    • getCapBound

      public S2Cap getCapBound()
      Description copied from interface: S2Region
      Return a bounding spherical cap.
      Specified by:
      getCapBound in interface S2Region
    • getRectBound

      public S2LatLngRect getRectBound()
      Description copied from interface: S2Region
      Return a bounding latitude-longitude rectangle.
      Specified by:
      getRectBound in interface S2Region
    • getCellUnionBound

      public void getCellUnionBound(List<S2CellId> cellIds)
      Clears the given list of cells and adds the cell union of this index. An index of shapes in one face adds up to 4 cells, otherwise up to 6 may be added.
    • coverRange

      private static void coverRange(S2CellId first, S2CellId last, List<S2CellId> cellIds)
      Computes the smallest S2Cell that covers the S2Cell range (first, last) and adds this cell to "cellIds".
      Throws:
      IllegalArgumentException - "first" and "last" don't have a common ancestor.
    • contains

      public boolean contains(S2Point p)
      Returns true if the given point is contained by any two-dimensional shape (i.e., polygon). Zero and one-dimensional shapes are ignored by this method.
      Specified by:
      contains in interface S2Region
    • contains

      public boolean contains(S2Cell target)
      Returns true if 'target' is contained by any single shape. If the cell is covered by a union of different shapes then it may return false.

      This implementation is conservative but not exact; if a shape just barely contains the given cell then it may return false. The maximum error is less than 10 * DBL_EPSILON radians (or about 15 nanometers).

      Specified by:
      contains in interface S2Region
    • mayIntersect

      public boolean mayIntersect(S2Cell target)
      Returns true if any shape intersects "target".

      This implementation is conservative but not exact; if a shape is just barely disjoint from the given cell then it may return true. The maximum error is less than 10 * DBL_EPSILON radians (or about 15 nanometers).

      Specified by:
      mayIntersect in interface S2Region
    • anyEdgeIntersects

      private boolean anyEdgeIntersects(S2ShapeIndex.S2ClippedShape clipped, S2Cell target)
      Returns true if any edge of the indexed shape "clipped" intersects the cell "target". It may also return true if an edge is very close to "target"; the maximum error is less than 10 * DBL_EPSILON radians (about 15 nanometers).