Example usage for com.google.common.geometry S2CellId parent

List of usage examples for com.google.common.geometry S2CellId parent

Introduction

In this page you can find the example usage for com.google.common.geometry S2CellId parent.

Prototype

public S2CellId parent(int level) 

Source Link

Document

Return the cell at the previous level or at the given level (which must be less than or equal to the current level).

Usage

From source file:com.bc.inventory.utils.S2Integer.java

public static void main(String[] args) {
    S2LatLng s2LatLng = S2LatLng.fromDegrees(42, 10);
    System.out.println("s2LatLng = " + s2LatLng);
    S2CellId s2CellId = S2CellId.fromLatLng(s2LatLng);
    System.out.println("s2CellId = " + s2CellId);
    S2CellId s2CellId13 = s2CellId.parent(13);
    System.out.println("s2CellId13 = " + s2CellId13);

    System.out.println("s2cellId = " + Long.toBinaryString(s2CellId.id()));
    System.out.println("s2cellId13 = " + Long.toBinaryString(s2CellId13.id()));
    System.out.println("s2cellIdInt = " + Long.toBinaryString(asInt(s2CellId)));
}

From source file:com.bc.inventory.utils.S2Integer.java

public static int asInt(S2CellId s2CellId) {
    if (s2CellId.level() > 13) {
        s2CellId = s2CellId.parent(13);
    }//from   ww w  . j a va 2 s  . co  m
    return (int) (s2CellId.id() >>> 34);
}

From source file:com.bc.inventory.utils.S2Integer.java

public static int asIntAtLevel(S2CellId s2CellId, int level) {
    if (s2CellId.level() > level) {
        s2CellId = s2CellId.parent(level);
    }//w  w w  . j av  a 2 s  .co  m
    return (int) (s2CellId.id() >>> (64 - 3 - (2 * level)));
}

From source file:org.esa.beam.occci.ReverseMatcher.java

public Set<Integer> matchInsitu(List<SimpleRecord> insituRecords, long maxTimeDifference) {
    Map<Integer, List<S2Point>> candidatesMap = new HashMap<>();

    try (StopWatch sw = new StopWatch("  >>test for time and cell")) {
        for (SimpleRecord insituRecord : insituRecords) {
            final long referenceTime = insituRecord.getTime();
            final long windowStartTime;
            final long windowEndTime;
            if (referenceTime == -1) {
                windowStartTime = globalStartTime;
                windowEndTime = globalEndTime;
            } else {
                windowStartTime = referenceTime - maxTimeDifference;
                windowEndTime = referenceTime + maxTimeDifference;
            }//from w  w  w .  j ava2  s .c  o m

            Point2D.Float location = insituRecord.getLocation();
            final double lon = location.getX();
            final double lat = location.getY();
            S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lon);
            S2Point s2Point = s2LatLng.toPoint();
            S2CellId s2CellId = S2CellId.fromPoint(s2Point);
            final int cellInt = S2CellIdInteger.asInt(s2CellId.parent(3));

            List<Integer> productIndices = reverseProductDB.findInsitu(cellInt, windowStartTime, windowEndTime);
            for (Integer productIndex : productIndices) {
                List<S2Point> candidateProducts = candidatesMap.get(productIndex);
                if (candidateProducts == null) {
                    candidateProducts = new ArrayList<>();
                    candidatesMap.put(productIndex, candidateProducts);
                }
                candidateProducts.add(s2Point);
            }
        }
        System.out.println("candidatesMap = " + candidatesMap.size());
    }

    List<Integer> uniqueProductList = new ArrayList<>(candidatesMap.size());
    uniqueProductList.addAll(candidatesMap.keySet());

    Set<Integer> matches = new HashSet<>();
    try (StopWatch sw = new StopWatch("  >>load and test polygons")) {
        Collections.sort(uniqueProductList);
        try (DataInputStream dis = new DataInputStream(
                new BufferedInputStream(new FileInputStream(polygonFile)))) {
            int streamPID = 0;
            for (Integer productID : uniqueProductList) {
                while (streamPID < productID) {
                    int numLoopPoints = dis.readInt();
                    dis.skipBytes(numLoopPoints * 3 * 8);
                    streamPID++;
                }
                final int numLoopPoints = dis.readInt();
                final double[] pointData = new double[numLoopPoints * 3];
                for (int i = 0; i < pointData.length; i++) {
                    pointData[i] = dis.readDouble();
                }
                streamPID++;

                S2Polygon s2Polygon = S2IEoProduct.createS2Polygon(pointData);
                List<S2Point> s2Points = candidatesMap.get(productID);
                for (S2Point s2Point : s2Points) {
                    if (s2Polygon.contains(s2Point)) {
                        matches.add(productID);
                        break;
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    return matches;
}

From source file:org.apache.lucene.spatial.prefix.tree.S2PrefixTree.java

@Override
public CellIterator getTreeCellIterator(Shape shape, int detailLevel) {
    if (!(shape instanceof Point)) {
        return super.getTreeCellIterator(shape, detailLevel);
    }/*from   w  ww  .j  a v a 2s . c  o  m*/
    Point p = (Point) shape;
    S2CellId id = S2CellId.fromLatLng(S2LatLng.fromDegrees(p.getY(), p.getX()))
            .parent(arity * (detailLevel - 1));
    List<Cell> cells = new ArrayList<>(detailLevel);
    for (int i = 0; i < detailLevel - 1; i++) {
        cells.add(new S2PrefixTreeCell(this, id.parent(i * arity)));
    }
    cells.add(new S2PrefixTreeCell(this, id));
    return new FilterCellIterator(cells.iterator(), null);
}