Example usage for com.google.common.geometry S2RegionCoverer getCovering

List of usage examples for com.google.common.geometry S2RegionCoverer getCovering

Introduction

In this page you can find the example usage for com.google.common.geometry S2RegionCoverer getCovering.

Prototype

public void getCovering(S2Region region, S2CellUnion covering) 

Source Link

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);//ww w .  j a v a  2 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;
}