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

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

Introduction

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

Prototype

public int level() 

Source Link

Document

Return the subdivision level of the cell (range 0..MAX_LEVEL).

Usage

From source file:com.norman0406.slimgress.API.Common.Utils.java

public static String[] getCellIdsFromRegion(S2Region region, int minLevel, int maxLevel) {
    S2RegionCoverer rCov = new S2RegionCoverer();

    rCov.setMinLevel(minLevel);/*from www .  ja v a2 s  .  c  om*/
    rCov.setMaxLevel(maxLevel);

    // get cells
    ArrayList<S2CellId> cells = new ArrayList<S2CellId>();
    rCov.getCovering(region, cells);

    ArrayList<Long> cellIds = new ArrayList<Long>();
    for (int i = 0; i < cells.size(); i++) {

        S2CellId cellId = cells.get(i);

        // can happen for some reason
        if (cellId.level() < minLevel || cellId.level() > maxLevel)
            continue;

        cellIds.add(cellId.id());
    }

    // convert to hex values
    String cellIdsHex[] = new String[cellIds.size()];
    for (int i = 0; i < cellIdsHex.length; i++) {
        cellIdsHex[i] = Long.toHexString(cellIds.get(i));
    }

    return cellIdsHex;
}

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

public static int asInt(S2CellId s2CellId) {
    if (s2CellId.level() > 13) {
        s2CellId = s2CellId.parent(13);/*from  w ww  . j a va 2s. com*/
    }
    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);
    }/*from   w w w .  jav a2 s  .  c  o  m*/
    return (int) (s2CellId.id() >>> (64 - 3 - (2 * level)));
}