List of usage examples for com.google.common.geometry S2CellId id
long id
To view the source code for com.google.common.geometry S2CellId id.
Click Source Link
From source file:org.esa.beam.occci.S2IndexCreatorMain.java
public static void main(String[] args) throws IOException, ParseException { if (args.length != 2) { printUsage();/*from w w w . j av a2s . c o m*/ } File productListFile = new File(args[0]); if (!productListFile.exists()) { System.err.printf("productList file '%s' does not exits%n", args[0]); printUsage(); } int counter = 0; List<EoProduct> eoProductList = ProductDB.readProducts("s2", productListFile); Collections.sort(eoProductList, ProductDB.EO_PRODUCT_COMPARATOR); File indexFile = new File(args[1]); File urlFile = new File(indexFile + ".url"); File poylFile = new File(indexFile + ".polygon"); File coverFile = new File(indexFile + ".coverages"); List<S2IntCoverage> allCoverages = new ArrayList<>(); try (DataOutputStream dosIndex = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(indexFile))); DataOutputStream dosUrl = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(urlFile))); DataOutputStream dosPoly = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(poylFile)))) { for (EoProduct eoProduct : eoProductList) { eoProduct.createGeo(); S2EoProduct s2EoProduct = (S2EoProduct) eoProduct; dosUrl.writeUTF(eoProduct.getName()); dosIndex.writeLong(eoProduct.getStartTime()); dosIndex.writeLong(eoProduct.getEndTime()); S2CellUnion cellUnion = s2EoProduct.cellUnion; S2IntCoverage s2IntCoverage = new S2IntCoverage(cellUnion); int index = allCoverages.indexOf(s2IntCoverage); if (index <= 0) { allCoverages.add(s2IntCoverage); index = allCoverages.size() - 1; } dosIndex.writeInt(index); int level1Mask = 0; for (int i = 0; i < cellUnion.cellIds().size(); i++) { S2CellId s2CellId = cellUnion.cellIds().get(i); level1Mask |= (1 << (int) (s2CellId.id() >>> MASK_SHIFT)); } dosIndex.writeInt(level1Mask); s2EoProduct.writePolygone(dosPoly); s2EoProduct.reset(); counter++; if (counter % 10000 == 0) { System.out.println("counter = " + counter); } } } System.out.println("allCoverages.size() = " + allCoverages.size()); try (DataOutputStream dosCover = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(coverFile)))) { dosCover.writeInt(allCoverages.size()); for (S2IntCoverage s2Cover : allCoverages) { int[] intIds = s2Cover.intIds; dosCover.writeInt(intIds.length); for (int intId : intIds) { dosCover.writeInt(intId); } } } }
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.amazonaws.geo.s2.internal.S2Manager.java
public static long generateGeohash(GeoPoint geoPoint) { S2LatLng latLng = S2LatLng.fromDegrees(geoPoint.getLatitude(), geoPoint.getLongitude()); S2Cell cell = new S2Cell(latLng); S2CellId cellId = cell.id(); return cellId.id(); }
From source file:org.esa.beam.occci.S2EoProduct.java
private static String cellUnionToString(S2CellUnion cellUnion) { ArrayList<S2CellId> s2CellIds = cellUnion.cellIds(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s2CellIds.size(); i++) { S2CellId s2CellId = s2CellIds.get(i); sb.append(s2CellId.id()); if (i < s2CellIds.size() - 1) { sb.append(";"); }//from ww w . java 2 s . c o m } return sb.toString(); }
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);// w w w. j av a 2 s. com 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);//ww w . j a v a2 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.S2EoProduct.java
public void writeCellUnion(DataOutputStream dos) throws IOException { ArrayList<S2CellId> s2CellIds = cellUnion.cellIds(); dos.writeInt(s2CellIds.size());/*from ww w . j av a 2 s . com*/ for (S2CellId s2CellId : s2CellIds) { dos.writeLong(s2CellId.id()); } }
From source file:org.apache.lucene.spatial.prefix.tree.S2PrefixTreeCell.java
/** * Get the {@link S2CellId} from the {@link BytesRef} representation. * * @param ref The bytes./*from w w w .j av a 2s . c o m*/ * @return the corresponding S2 cell. */ private S2CellId getS2CellIdFromBytesRef(BytesRef ref) { int length = ref.length; if (isLeaf(ref)) { length--; } if (length == 0) { return null; //world cell } int face = PIXELS.get(ref.bytes[ref.offset]); S2CellId cellId = FACES[face]; long id = cellId.id(); for (int i = ref.offset + 1; i < ref.offset + length; i++) { int thisLevel = i - ref.offset; int pos = PIXELS.get(ref.bytes[i]); // first child at level id = id - (id & -id) + (1L << (2 * (S2CellId.MAX_LEVEL - thisLevel * tree.arity))); // next until pos id = id + pos * ((id & -id) << 1); } return new S2CellId(id); }
From source file:org.esa.beam.occci.MultiPassMatcher.java
@Override public Set<EoProduct> matchInsitu(List<SimpleRecord> insituRecords, long maxTimeDifference) { Map<S2IEoProduct, List<S2Point>> candidatesMap = new HashMap<>(); long globalStartTime; long globalEndTime; try {//from w w w . j a va 2 s.c o m globalStartTime = AbstractEoProduct.DATE_FORMAT .parse(DateUtils.getNoFractionString("2014-01-01T00:00:00")).getTime(); globalEndTime = AbstractEoProduct.DATE_FORMAT .parse(DateUtils.getNoFractionString("2015-01-01T00:00:00")).getTime(); } catch (ParseException e) { throw new RuntimeException(e); } try (StopWatch sw = new StopWatch(" >>test for time and cell")) { for (SimpleRecord insituRecord : insituRecords) { S2CellId s2CellId = null; S2Point s2Point = null; int level1Mask = 0; 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; } int productIndex = productDB.getIndexForTime(windowStartTime); if (productIndex == -1) { continue; } boolean finishedWithInsitu = false; while (!finishedWithInsitu) { S2IEoProduct eoProduct = (S2IEoProduct) productDB.getRecord(productIndex); productIndex++; if (eoProduct == null) { finishedWithInsitu = true; } else if (eoProduct.getStartTime() > windowEndTime) { finishedWithInsitu = true; } else if (eoProduct.getEndTime() < windowStartTime) { //test next product; } else { // time match if (s2CellId == null) { Point2D.Float location = insituRecord.getLocation(); double lon = location.getX(); double lat = location.getY(); S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lon); s2Point = s2LatLng.toPoint(); s2CellId = S2CellId.fromPoint(s2Point); level1Mask = (1 << (int) (s2CellId.id() >>> S2IndexCreatorMain.MASK_SHIFT)); } if ((eoProduct.level1Mask & level1Mask) != 0) { if (S2CellIdInteger.containsPoint(eoProduct.cellIds, s2CellId)) { List<S2Point> candidateProducts = candidatesMap.get(eoProduct); if (candidateProducts == null) { candidateProducts = new ArrayList<>(); candidatesMap.put(eoProduct, candidateProducts); } candidateProducts.add(s2Point); } } } } } System.out.println("candidatesMap = " + candidatesMap.size()); } List<S2IEoProduct> uniqueProductList = new ArrayList<>(candidatesMap.size()); uniqueProductList.addAll(candidatesMap.keySet()); Set<EoProduct> matches = new HashSet<>(); try (StopWatch sw = new StopWatch(" >>load and test polygons")) { Collections.sort(uniqueProductList, (o1, o2) -> Integer.compare(o1.productID, o2.productID)); try (DataInputStream dis = new DataInputStream( new BufferedInputStream(new FileInputStream(polygonFile)))) { int streamPID = 0; for (S2IEoProduct eoProduct : uniqueProductList) { final int productID = eoProduct.productID; 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(eoProduct); for (S2Point s2Point : s2Points) { if (s2Polygon.contains(s2Point)) { matches.add(eoProduct); break; } } } } catch (IOException e) { e.printStackTrace(); return null; } } return matches; }